@busy-web/cli
Advanced tools
Comparing version 0.5.0 to 0.5.1
{ | ||
"name": "@busy-web/cli", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "Command line tools to enhance web dev tasks", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -19,3 +19,4 @@ # cli | ||
#### OPTIONS: | ||
##### -b, --boring Hide title and version information and remove empty new lines | ||
##### --boring Hide title and version information and remove empty new lines | ||
##### --debug Turn debug mode on | ||
@@ -72,2 +73,3 @@ #### Example: | ||
-r, --require throw error if config or ENV settings do not exist. ( default: false ) | ||
-an, --allow-null allow null values to be set from ENV to APP config | ||
@@ -74,0 +76,0 @@ ##### release ‹type› |
@@ -18,2 +18,3 @@ /** | ||
{ cmd: '--require', short: '-r', desc: 'throw error if config or ENV settings do not exist. ( default: false )' }, | ||
{ cmd: '--allow-null', short: '-an', desc: 'allow null values to be set from ENV to APP config' } | ||
], | ||
@@ -20,0 +21,0 @@ run: config |
@@ -7,4 +7,4 @@ | ||
if (!process.__busyweb.boring) { | ||
logger.write(colors.white.dim.italic(" version: " + process.__busyweb.package.version), "\n"); | ||
logger.write(colors.yellow.italic(" version: " + process.__busyweb.package.version), "\n"); | ||
} | ||
} |
@@ -17,6 +17,12 @@ /** | ||
// load header | ||
loader('helpers/header')(); | ||
// load version | ||
loader('helpers/version')(); | ||
// load commands | ||
loader('lib/load-commands')(); | ||
// validata args | ||
let hasArgs = false; | ||
@@ -31,15 +37,8 @@ const args = process.argv.slice(2); | ||
// show help if non valid args found | ||
if (!hasArgs) { | ||
//const { isEmberCli } = loader('utils/ember'); | ||
// TODO: | ||
// add logic here to add a throughput channel for ember-cli commands to be ran. | ||
// | ||
//if (isEmberCli()) { | ||
// global.console.log('ember cli project'); | ||
//} else { | ||
// global.console.log('not an ember cli project'); | ||
//} | ||
loader('helpers/help')(); | ||
} | ||
// fix arg1 bin argument for loaded scripts | ||
const argv = process.argv; | ||
@@ -51,12 +50,17 @@ argv[1] = path.join(__dirname, 'scripts', 'bw'); | ||
/** | ||
* helper method for shutting down program | ||
* | ||
*/ | ||
function exit(code) { | ||
let msg = colors.green('OK'); | ||
let msg = colors.green('[ OK ]'); | ||
if (code !== 0) { | ||
msg = colors.red('FAIL'); | ||
msg = colors.red('[ FAIL ]'); | ||
} | ||
logger.write(process.__busyweb.boring ? "" : "\n", colors.yellow("< EXIT:"), msg, colors.yellow(">")); | ||
logger.write(process.__busyweb.boring ? "" : "\n", msg, colors.yellow("busy-web finished"), "\n"); | ||
process.exit(code); | ||
} | ||
// Log command results and exit program | ||
const logger = loader('utils/logger'); | ||
@@ -63,0 +67,0 @@ if (process.__busyweb.runPromise) { |
@@ -42,8 +42,12 @@ /** | ||
program.usage(busyweb.usage); | ||
program.option('-b, --boring', 'Hide title and version information and remove empty new lines'); | ||
program.option('--boring', 'Hide title and version information and remove empty new lines'); | ||
program.option('--debug', 'Turn debug mode on'); | ||
let boring = process.argv.find(val => val === '-b' || val === '--boring'); | ||
busyweb.boring = (boring !== undefined && boring !== null); | ||
let debug = process.argv.find(val => val === '-b' || val === '--debug'); | ||
busyweb.debug = (debug !== undefined && debug !== null); | ||
return busyweb; | ||
} |
@@ -7,3 +7,2 @@ /** | ||
const RSVP = require('rsvp'); | ||
const colors = require('colors'); | ||
const ora = require('ora'); | ||
@@ -14,3 +13,3 @@ const logger = loader('utils/logger'); | ||
if (!opts.hidecmd) { | ||
logger.write(colors.green('=> ') + colors.blue(arg)); | ||
logger.info(arg); | ||
} | ||
@@ -25,19 +24,20 @@ | ||
return new RSVP.Promise((resolve, reject) => { | ||
if (opts.allowInput) { | ||
let args = arg.split(' '); | ||
let primary = args.shift(); | ||
// create child process to run the cmd. | ||
if (opts.allowInput) { | ||
let [ primary, ...args ] = arg.split(' '); | ||
// create child process to run the cmd and allow ui input | ||
const child = spawn(primary, args, { stdio: 'inherit' }); | ||
child.on('close', () => { | ||
resolve(); | ||
}); | ||
// regieter on close event to resolve promise | ||
child.on('close', () => resolve()); | ||
// register error event to reject promise | ||
child.on('error', err => { | ||
logger.error('child error', err); | ||
if (process.__busyweb.debug) { | ||
logger.debug('[ CMDERR ]', err); | ||
} | ||
reject(err); | ||
}); | ||
} else { | ||
// create child process to run the cmd. | ||
// create child process to run the cmd with callback for promises | ||
const child = exec(arg, { }, (err, stdout, stderr) => { | ||
@@ -49,4 +49,5 @@ if (spinner) { spinner.stop(); } | ||
} else if (err) { | ||
// TODO: add check for `process.debug` before logger | ||
logger.error(stderr); | ||
if (process.__busyweb.debug) { | ||
logger.debug('[ CMDERR ]', stderr); | ||
} | ||
reject(err); | ||
@@ -58,5 +59,5 @@ } else { | ||
if (opts.verbose) { | ||
if (opts.verbose || process.__busyweb.debug) { | ||
child.stdout.on('data', data => { | ||
logger.print(data); | ||
logger.subinfo(data); | ||
}); | ||
@@ -63,0 +64,0 @@ } |
@@ -26,22 +26,25 @@ | ||
print(...args) { | ||
this.write(colors.green(' =>'), colors.cyan(stringify(args))); | ||
}, | ||
log(...args) { | ||
this.write(colors.green(' =>'), colors.white.dim(stringify(args))); | ||
this.write(colors.magenta(' => Log:'), stringify(args)); | ||
}, | ||
debug(...args) { | ||
this.write(colors.cyan(' => Debug:'), stringify(args)); | ||
}, | ||
subinfo(...args) { | ||
this.write(colors.green(' =>'), colors.cyan(stringify(args))); | ||
}, | ||
info(...args) { | ||
this.write(process.__busyweb.boring ? "" : "\n", colors.green(' =>'), colors.blue(stringify(args))); | ||
this.write(colors.green(' =>'), colors.blue(stringify(args))); | ||
}, | ||
warn(...args) { | ||
this.write(process.__busyweb.boring ? "" : "\n", colors.yellow(' =>'), colors.yellow(stringify(args))); | ||
this.write(colors.yellow(' => Warning:'), stringify(args)); | ||
}, | ||
error(...args) { | ||
args.unshift("ERROR:"); | ||
this.write(process.__busyweb.boring ? "" : "\n", colors.red(' =>'), colors.red(stringify(args))); | ||
this.write(colors.red(' => Error:'), stringify(args)); | ||
} | ||
}; |
@@ -0,1 +1,5 @@ | ||
/** | ||
* @module Utils | ||
* | ||
*/ | ||
@@ -12,2 +16,6 @@ function assert(msg, test) { | ||
function isEmpty(value) { | ||
return !(isDefined(value) && value.length > 0); | ||
} | ||
function isArray(value) { | ||
@@ -20,3 +28,4 @@ return isDefined(value) && Array.isArray(value); | ||
isDefined, | ||
isEmpty, | ||
isArray | ||
}; |
Sorry, the diff of this file is not supported yet
41391
38
996
96
11