Comparing version 0.0.22 to 0.0.23
165
index.js
@@ -7,126 +7,57 @@ 'use strict'; | ||
var path = require('path'); | ||
var spawnSync = require('child_process').spawnSync; | ||
var spawn = require('child_process').spawn; | ||
var moment = require('moment'); | ||
var config = require(path.join(process.env.HOME, process.env.CML_CONFIG)); | ||
require('autocmdr/lib/help')(program); | ||
/** | ||
* Spawns a gulp task process | ||
* @param {[String]} task_name Task name | ||
* @param {[String]} cwd Working directory | ||
* @return {[Object]} Process data | ||
*/ | ||
function run_task(task_name, cwd) { | ||
console.log(chalk.grey('Starting task: ') + chalk.bold.white(task_name)); | ||
console.log(chalk.grey('Working directory: ') + chalk.bold.white(cwd)); | ||
return spawnSync('gulp', [task_name], { | ||
cwd: cwd | ||
}); | ||
} | ||
var empty_project = require('./lib/empty_project'); | ||
var spawn_task = require('./lib/spawn_task'); | ||
var handle_task = require('./lib/handle_task'); | ||
var remove_compiled_assets = require('./lib/remove_compiled_assets'); | ||
function spawn_task(task_name, cwd) { | ||
program | ||
.version(pkg.version) | ||
.option('-b, --build', 'create production build') | ||
.option('-d, --development', 'start development') | ||
.option('-D, --docs', 'generate project docs') | ||
.option('-l, --lint', 'lint markup, styles and script sources') | ||
.option('-t, --test', 'run tests') | ||
.option('-R, --reset', 'reset project to empty state (removes every view, script, style and assets)') | ||
.option('-g, --generate', 'generate view, page or pattern') | ||
.parse(process.argv); | ||
console.log(chalk.grey('Starting task: ') + chalk.bold.white(task_name)); | ||
console.log(chalk.grey('Working directory: ') + chalk.bold.white(cwd)); | ||
return spawn('gulp', [task_name], { | ||
cwd: cwd | ||
}); | ||
if (program.build) { | ||
remove_compiled_assets([ | ||
path.join(config.publicDir, config.publicPaths.fontsDir), | ||
path.join(config.publicDir, config.publicPaths.imagesDir), | ||
path.join(config.publicDir, config.publicPaths.stylesDir), | ||
path.join(config.publicDir, config.publicPaths.scriptsDir) | ||
], function () { | ||
console.log(chalk.underline.green.bold('\nCompiled assets cleaned')); | ||
handle_task(spawn_task('build', process.env.HOME)); | ||
}); | ||
} | ||
/** | ||
* Handles synchronous task output | ||
* @param {[Object]} task Task result object | ||
* @return | ||
*/ | ||
function handle_task_sync(task) { | ||
if (task.error) { | ||
console.error(chalk.bold.red(task.stderr)); | ||
console.dir(JSON.stringify(task.error)); | ||
return; | ||
} | ||
console.log(chalk.green(task.stdout.toString())); | ||
else if (program.development) { | ||
handle_task(spawn_task('development', process.env.HOME)); | ||
} | ||
function handle_task(task_process) { | ||
var command_close_handler = function(code, signal) { | ||
task_process.stdout.unref(); | ||
task_process.stderr.unref(); | ||
task_process.stdin.unref(); | ||
process.exit(1); | ||
}; | ||
// subprocess exit | ||
var command_exit_handler = function(code, signal) { | ||
task_process.stdout.unref(); | ||
task_process.stderr.unref(); | ||
task_process.stdin.unref(); | ||
process.exit(1); | ||
}; | ||
// subprocess error | ||
var command_error_handler = function(err) { | ||
task_process.stdout.unref(); | ||
task_process.stderr.unref(); | ||
task_process.stdin.unref(); | ||
task_process.kill('SIGTERM'); | ||
process.exit(1); | ||
}; | ||
var command_buffer_handler = function(data) { | ||
//console.log(data.toString().replace(/(\n|\r)$/gim, '')); | ||
var stdout = data.toString(); | ||
if (!(/error:/gi).test(stdout)) { | ||
stdout = stdout | ||
.replace(/\[[0-9:]{6,10}\]/gi, chalk.white.bold('$&')) | ||
.replace(/[0-9.,]{1,32}\s\w/gi, chalk.white.bold('$&')) | ||
.replace(/gulp-[a-z]+/gi, chalk.blue.bold('$&')) | ||
.replace(/\'.+\'/gi, chalk.blue.bold('$&')) | ||
.replace(/finished|starting/gi, chalk.cyan.bold('$&')) | ||
.replace(/warning: .+/gi, chalk.yellow.bold('$&')) | ||
.replace(/doiuse: .+/gi, chalk.yellow.bold('$&')) | ||
.replace(/(\n|\r)$/g, ''); | ||
} else { | ||
stdout = stdout | ||
.replace(/.+/gi, chalk.red('$&')) | ||
.replace(/(\n|\r)$/g, ''); | ||
} | ||
console.log(stdout); | ||
}; | ||
task_process.stdout.on('data', command_buffer_handler); | ||
task_process.stderr.on('data', command_buffer_handler); | ||
task_process.stdin.on('data', command_buffer_handler); | ||
task_process.on('close', command_close_handler); | ||
task_process.on('exit', command_exit_handler); | ||
task_process.on('error', command_error_handler); | ||
else if (program.docs) { | ||
handle_task(spawn_task('docs', process.env.HOME)); | ||
} | ||
program | ||
.version(pkg.version) | ||
.option('-b, --build', 'create production build') | ||
.option('-d, --development', 'start development') | ||
.option('-D, --docs', 'generate project docs') | ||
.option('-l, --lint', 'lint markup, styles and script sources') | ||
.option('-t, --test', 'run tests') | ||
.option('-g, --generate', 'generate view, page or pattern') | ||
.parse(process.argv); | ||
if (program.build) { | ||
handle_task(spawn_task('build', path.join(__dirname, '../../'))); | ||
} else if (program.development) { | ||
handle_task(spawn_task('development', path.join(__dirname, '../../'))); | ||
} else if (program.docs) { | ||
handle_task(spawn_task('docs', path.join(__dirname, '../../'))); | ||
} else if (program.lint) { | ||
handle_task(spawn_task('lint', path.join(__dirname, '../../'))); | ||
} else if (program.test) { | ||
handle_task(spawn_task('test', path.join(__dirname, '../../'))); | ||
} else if (program.generate) { | ||
console.log(chalk.underline.cyan.bold('Not yet implemented :(')); | ||
} else { | ||
console.error('No command specified. See \'cml-cli --help\':'); | ||
program.outputHelp(); | ||
process.exit(1); | ||
else if (program.lint) { | ||
handle_task(spawn_task('lint', process.env.HOME)); | ||
} | ||
else if (program.test) { | ||
handle_task(spawn_task('test', process.env.HOME)); | ||
} | ||
else if (program.generate) { | ||
console.log(chalk.underline.cyan.bold('Not yet implemented :(')); | ||
} | ||
else if (program.reset) { | ||
empty_project(process.env.HOME, function () { | ||
console.log(chalk.underline.green.bold('\n\nProject successfully resetted')); | ||
process.exit(1); | ||
}); | ||
} | ||
else { | ||
console.error('No command specified. See \'cml-cli --help\':'); | ||
program.outputHelp(); | ||
process.exit(1); | ||
} |
{ | ||
"name": "cml-cli", | ||
"version": "0.0.22", | ||
"version": "0.0.23", | ||
"description": "Simple wrapper for build scripts to stabilize API and to scaffold views and common patterns of cml-frontend boilerplate. Not for standalone usage.", | ||
@@ -21,7 +21,9 @@ "bin": { | ||
"dependencies": { | ||
"ansi-rainbow": "0.0.8", | ||
"autocmdr": "~0.0.4", | ||
"chalk": "^1.0.0", | ||
"commander": "~2.0.0" | ||
"commander": "~2.0.0", | ||
"fs-extra": "^0.18.3" | ||
}, | ||
"devDependencies": {} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11240
18
310
5
11
4
+ Addedansi-rainbow@0.0.8
+ Addedfs-extra@^0.18.3
+ Addedansi-rainbow@0.0.8(transitive)
+ Addedansi-styles@1.0.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs-extra@0.18.4(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedgraceful-fs@3.0.124.2.11(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedjsonfile@2.4.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addednatives@1.1.6(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedwrappy@1.0.2(transitive)