autocode-cli
Version:
code automation for every language, framework and platform
54 lines (52 loc) • 1.69 kB
JavaScript
// Generated by CoffeeScript 1.10.0
(function() {
module.exports = function(opts) {
var autocode, i, runCmd, runInterval, scripts, spawn;
autocode = this;
spawn = require('cross-spawn');
this.build(opts);
if (!this.config.scripts || !this.config.scripts.run) {
return "\n" + ' DONE! '.bgGreen.white;
}
console.log("\nRUN:".bold);
scripts = this.config.scripts;
i = 0;
runInterval = null;
runCmd = function() {
var arg, cmd, command, description, proc, run;
clearInterval(runInterval);
runInterval = null;
if (!scripts.run[i]) {
console.log("\n" + ' DONE! '.bgGreen.white);
return;
}
description = scripts.run[i].description || scripts.run[i];
command = scripts.run[i].command || scripts.run[i];
console.log(' RUN SCRIPT '.bgGreen.white + (' ' + description + ' ').bgWhite + " \n" + command.gray);
run = command;
run = [run.substr(0, run.indexOf(' ')), run.substr(run.indexOf(' ') + 1)];
cmd = run[0];
arg = run[1].split(' ');
proc = spawn(cmd, arg, {
stdio: 'inherit'
});
proc.on('close', function(err) {
return runCmd();
});
proc.on('error', function(err) {
return console.log("\n" + ' ERROR '.bgRed.white + (' ' + err.message + ' ').bgWhite);
});
runInterval = setInterval((function() {
if (autocode.stopped) {
console.log('Project was stopped.');
autocode.stopped = false;
clearInterval(runInterval);
return proc.kill();
}
}), 1);
return i++;
};
runCmd();
return 'Running...';
};
}).call(this);