added travis + tests

This commit is contained in:
Phil Kunz 2015-10-05 23:33:57 +02:00
parent 2dec60ce56
commit e28670de17
9 changed files with 209 additions and 29 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
node_modules/ node_modules/
.settings/ .settings/
.idea/ .idea/
ts/*.js
ts/*.js.map

View File

@ -10,10 +10,10 @@ deploy:
provider: npm provider: npm
email: npm@smart-coordination.com email: npm@smart-coordination.com
api_key: api_key:
secure: y7l1JyBDihAYxbqfuPAUXJfY+PC7RSSCkAtXtBIjPA6wytSBnz55te/Vdy8RFgVty6O/k4hHzrhgUJMSoWKmPuGQ5bMBgkyV9OI5PPp4uEUyy5UdcJZv3cZYpGGDRjLjCHP4pF7AHdRcDUMEiE5ZrDtmUH1SBLoRswieO0TKsiMr3u45yR6rHFoPnnw1YlatoAPpiuP3SLnCrIjQeSOS7y9SL6PpakiquJNtpseVOr60sp39L6vLAeqJ7xTjjNJk23LF/60lfiKtM7QFg9qqE7cxFUWJs7Zmgfg4/hGcU9XRfDfZQgSNntcdFczPejO5juv2KOb1tzH7EhXrWlcF1yd70RBdJbcOn7O6ctHjMCGrCSn6IQPzcNWNErFELfMLsjVQUxbfHSc0iA1JxcYWeXUivrStwVOa9ufuG2KZCQZyEjra3zPdCu9yrE30c/mTace7eJXPYTsNn2tmxvTnFoTWmeQ0xL9Iyz9zceADpxjYJoJ8r4XMDWxWga5G9OPaqCINHxjKhOX0C36YEjYTaeNMNHv6F6BPLdKwQ9SmklMtcyC312nJsXwKy+KYJSoY6WqMef9Zk3ez0o09W0UkSr0qiQkyYCoNm8b1L7VrYuccPH24GE0fn8QMWmeE5TBThYbEIdt6NBoYCDeocflUm5KBrImFGo1peeYS1aQnpoQ= secure: XAtA2XHAr96ILKpm1VnB/Nff9hiQv3FUa/NDfGZgvJKimuF/TwU2+kXyAag/LlEQGckZ9/IDx0PTIe8x4wOvg2VyKceYktGt6G5/MHeAXwzkkM253k2CKweVtBgnpZ2doTZXeeV/h7hHuEWZbWRXIVCgM6/inaaNe4cMRGCWqwb1xmw6D8VkLpNo6PiB37gR4GfMokasgVHZEVMg2evWKk0moREGW9XKqoE6PS9TPHPHerdqFqfbmeOq3nNgHrJZkNsAJ3PPESWCe/NGEBwtYDKrPI3QlouvXmxScI9/p2VCQmdFoUxKMDsVzBdRMrCx+XxoS8x81HxubZSpnvzUlzGtznZi7e6OyAlI7xXELIO551AH4V/pNWWUPATX+7vXVDGh7aAZYme/fejisjO5Tk9aqRvohh2jCDml3ED6alHHfI0oX5UvBpOE+XwGTIJ8qpf9RrLP5DC27JWE3fqY/WoqIZX7phoKeKYLl+R7Iln/dfvepbMBgcesnBf4PuMh3Qm2l2G1bElJ/hniV1dgggwjcg50nA0Ee9sCnORPxxjdDIMwJw//NJSe+Aq5Fm1ure9oNiBYOeF0bLVQyfGIC8J8coy1xdqv2klKnGHjMMN44bjNlmDp00SaRpbdDuavyocosQVpzfA+hY2QtGV5TXFv6TLgcMYwf8gNyVNkSGE=
on: on:
tags: true tags: true
repo: pushrocks/gulp-bootstrap repo: pushrocks/smartcli
notifications: notifications:
slack: slack:
secure: f5Uss0z9RPl/QcA/DroB8loyE93aOYI6bqCkrsiUscmZtlv/TVQtT4dxqGA6uvcG6iTQDBi3Ul88dQxWkRm4IqbhY35/iMaV2dHW4FVYMAh8GQMbsfL2sALCcufxD9blw47awv3iFcwhV1EeyesscjgL0JIjduk96v/7G/6QIO2838M1lzlgtj+kRUkim8qkaEs1je3gRrhMUIjLuAdscMXyUKYFMjWo9ACSjVUl30R/ZNemb18itIja6i92GotreBgcfEMczvy58ovDC7xdJUsY8LjMI01DwY+WPRnI0tAhsuI8moBwwcdM4e3bAjKjucQRjO33O5bMWRZ6QCiYd0DnCEFyCPQLJ4GSy/tkD00n8ijLHAOSV3AH1zNbdK1EAdSPQXDvlI36KJn/2hyQLoitGHVUPr76ujJWP82ypO2tgIp3XQU0dJVCxDuHnwJO2+hjdI+gCPqxNTpjeujHx3UdkTGNRjuuf9dlZ/D08fApjYxy2fxItTqo3QjP/nrqvBXUOPP8yPHpjIT4H2t5Pr4SJjBGI6X4qhKyFj6s9rA/Xu1rL+45zu1C3uC3z+u3T9UwrbzJ/cZM6r6UQvQmUvIfBNaMlg4I/diQCDIPL+Rhop2nylY3IcHmJnk2itn7kOqj1tohCpFEml5pRuSZy4udWywkdtyBAsHWFLF7oiQ= secure: f5Uss0z9RPl/QcA/DroB8loyE93aOYI6bqCkrsiUscmZtlv/TVQtT4dxqGA6uvcG6iTQDBi3Ul88dQxWkRm4IqbhY35/iMaV2dHW4FVYMAh8GQMbsfL2sALCcufxD9blw47awv3iFcwhV1EeyesscjgL0JIjduk96v/7G/6QIO2838M1lzlgtj+kRUkim8qkaEs1je3gRrhMUIjLuAdscMXyUKYFMjWo9ACSjVUl30R/ZNemb18itIja6i92GotreBgcfEMczvy58ovDC7xdJUsY8LjMI01DwY+WPRnI0tAhsuI8moBwwcdM4e3bAjKjucQRjO33O5bMWRZ6QCiYd0DnCEFyCPQLJ4GSy/tkD00n8ijLHAOSV3AH1zNbdK1EAdSPQXDvlI36KJn/2hyQLoitGHVUPr76ujJWP82ypO2tgIp3XQU0dJVCxDuHnwJO2+hjdI+gCPqxNTpjeujHx3UdkTGNRjuuf9dlZ/D08fApjYxy2fxItTqo3QjP/nrqvBXUOPP8yPHpjIT4H2t5Pr4SJjBGI6X4qhKyFj6s9rA/Xu1rL+45zu1C3uC3z+u3T9UwrbzJ/cZM6r6UQvQmUvIfBNaMlg4I/diQCDIPL+Rhop2nylY3IcHmJnk2itn7kOqj1tohCpFEml5pRuSZy4udWywkdtyBAsHWFLF7oiQ=

View File

@ -1,11 +1,69 @@
/// <reference path="typings/tsd.d.ts" /> /// <reference path="typings/tsd.d.ts" />
var path, through; var path = require("path");
through = require("through2"); var beautylog = require("beautylog");
path = require("path"); var cliff = require("cliff");
module.exports = function (jadeTemplate, mojo) { var inquirer = require("inquirer");
if (mojo === void 0) { mojo = undefined; } var argv = require('yargs').argv;
return through.obj(function (file, enc, cb) { //define the smartcli object
//run callback function to signal end of plugin process. var smartcli = {};
return cb(null, file); //add plugins from above for direct use
smartcli.inquirer = inquirer;
smartcli.cliff = cliff;
smartcli.argv = argv;
/**
* returns the current working directory
* @returns {string}
*/
smartcli.getCwd = function () {
return process.cwd();
};
/**
* executes callback with answer to question as argument
* @param questionString the question you want to ask the user
* @param cb the function to execute with answer as param
* @returns {null}
*/
smartcli.getAnswer = function (questionString, cb) {
if (typeof questionString != 'string') {
beautylog.error('no question specified');
return null;
}
//make inquirer compatible question object
var question = {
type: "input",
name: "userFeedback",
message: questionString,
validate: function (value) {
return true;
}
};
inquirer.prompt([question], function (answers) {
var answer = answers.userFeedback;
cb(answer);
}); });
}; };
/**
*
* @param questionString
* @param choiceOptions
* @param cb
* @returns {null}
*/
smartcli.getChoice = function (questionString, choiceOptions, cb) {
if (!Array.isArray(choiceOptions)) {
return null;
}
//make inquirer compatible question object
var question = {
type: "list",
name: "userFeedback",
message: questionString,
choices: choiceOptions,
filter: function (val) { return val.toLowerCase(); }
};
inquirer.prompt(question, function (answers) {
var answer = answers.userFeedback;
cb(answer);
});
};
module.exports = smartcli;

View File

@ -24,7 +24,12 @@
"url": "https://github.com/pushrocks/smartcli/issues" "url": "https://github.com/pushrocks/smartcli/issues"
}, },
"homepage": "https://github.com/pushrocks/smartcli", "homepage": "https://github.com/pushrocks/smartcli",
"dependencies": {}, "dependencies": {
"beautylog": "0.0.12",
"cliff": "^0.1.10",
"inquirer": "^0.10.1",
"yargs": "^3.26.0"
},
"devDependencies": { "devDependencies": {
"gulp": "3.9.0", "gulp": "3.9.0",
"gulp-typescript": "2.9.2" "gulp-typescript": "2.9.2"

18
test.js Normal file
View File

@ -0,0 +1,18 @@
/// <reference path="typings/tsd.d.ts" />
var smartcli = require("./index.js");
var getAnswerTest = function () {
smartcli.getAnswer('How do you feel?', function (answer) {
console.log('The answer is: ' + answer);
getChoiceTest();
});
};
var getChoiceTest = function () {
smartcli.getChoice('What to you like best?', ['Cars', 'Planes', 'Boats'], function (answer) {
console.log('The answer is: ' + answer);
getCwdTest();
});
};
var getCwdTest = function () {
console.log('The current directory is: ' + smartcli.getCwd());
};
getAnswerTest();

View File

@ -1,2 +0,0 @@
nvm use v0.12.7
gulp

View File

@ -11,6 +11,15 @@ gulp.task('compileTS', function() {
return stream; return stream;
}); });
gulp.task('default',['compileTS'], function() { gulp.task('compileTestTS', function() {
var stream = gulp.src('../test.ts')
.pipe(gulpTypescript({
out: "test.js"
}))
.pipe(gulp.dest("../../"));
return stream;
});
gulp.task('default',['compileTS','compileTestTS'], function() {
console.log('Typescript compiled'); console.log('Typescript compiled');
}); });

View File

@ -1,14 +1,81 @@
/// <reference path="typings/tsd.d.ts" /> /// <reference path="typings/tsd.d.ts" />
var path, through;
through = require("through2"); var path = require("path");
path = require("path"); var beautylog = require("beautylog");
var cliff = require("cliff");
var inquirer = require("inquirer");
var argv = require('yargs').argv;
module.exports = (jadeTemplate,mojo = undefined) => { //define the smartcli object
var smartcli:any = {};
return through.obj((file, enc, cb) => { //add plugins from above for direct use
smartcli.inquirer = inquirer;
smartcli.cliff = cliff;
smartcli.argv = argv;
//run callback function to signal end of plugin process. /**
return cb(null, file); * returns the current working directory
* @returns {string}
*/
smartcli.getCwd = function () {
return process.cwd();
};
/**
* executes callback with answer to question as argument
* @param questionString the question you want to ask the user
* @param cb the function to execute with answer as param
* @returns {null}
*/
smartcli.getAnswer = function(questionString:string, cb) {
if (typeof questionString != 'string') {
beautylog.error('no question specified');
return null;
}
//make inquirer compatible question object
var question = {
type: "input",
name: "userFeedback",
message: questionString,
validate: function( value ) {
return true;
}
};
inquirer.prompt([question],function(answers){
var answer = answers.userFeedback;
cb(answer);
}); });
}; };
/**
*
* @param questionString
* @param choiceOptions
* @param cb
* @returns {null}
*/
smartcli.getChoice = function(questionString:string, choiceOptions:string[], cb) {
if(!Array.isArray(choiceOptions)) {
return null;
}
//make inquirer compatible question object
var question = {
type: "list",
name: "userFeedback",
message: questionString,
choices: choiceOptions,
filter: function( val ) { return val.toLowerCase(); }
};
inquirer.prompt(question,function(answers){
var answer = answers.userFeedback;
cb(answer);
});
};
module.exports = smartcli;

22
ts/test.ts Normal file
View File

@ -0,0 +1,22 @@
/// <reference path="typings/tsd.d.ts" />
var smartcli = require("./index.js");
var getAnswerTest = function() {
smartcli.getAnswer('How do you feel?',function(answer){
console.log('The answer is: ' + answer);
getChoiceTest();
});
};
var getChoiceTest = function() {
smartcli.getChoice('What to you like best?',['Cars','Planes','Boats'],function(answer){
console.log('The answer is: ' + answer);
getCwdTest();
});
};
var getCwdTest = function(){
console.log('The current directory is: ' + smartcli.getCwd());
};
getAnswerTest();