autocode
Version:
spec-driven code generator
69 lines (64 loc) • 2 kB
JavaScript
// Generated by CoffeeScript 1.10.0
(function() {
var path, spawn;
path = require('path');
spawn = require('cross-spawn');
module.exports = function() {
var cwd, i, scripts, stopCmd;
this.stopped = true;
if (!this.config.scripts || !this.config.scripts.stop) {
return 'No scripts for: stop';
}
cwd = this.path;
console.log("\nSTOP:".bold);
scripts = this.config.scripts;
i = 0;
stopCmd = function() {
var command, description, dir, proc;
if (!scripts.stop[i]) {
console.log("\nDone!");
return;
}
if (scripts.stop[i].title && !scripts.stop[i].command) {
console.log(' STOP TITLE '.bgGreen.white + (' ' + scripts.stop[i].title + ' ').bgWhite + " \n");
i++;
stopCmd();
return;
}
description = scripts.stop[i].description || scripts.stop[i];
command = scripts.stop[i].command || scripts.stop[i];
if (scripts.stop[i].path) {
if (scripts.stop[i].path.match(/^\//)) {
dir = scripts.stop[i].path;
} else {
dir = cwd + "/" + scripts.stop[i].path;
}
dir = path.normalize(dir);
} else {
dir = cwd;
}
console.log(' STOP SCRIPT '.bgGreen.white + (' ' + description + ' ').bgWhite + " \n" + command.gray);
proc = spawn('bash', ['-c', command], {
cwd: dir
});
proc.stderr.on('data', function(data) {
return console.log(data.toString().red);
});
proc.stdout.on('error', function(data) {
return console.log(data.toString());
});
proc.stdout.on('data', function(data) {
return console.log(data.toString());
});
proc.on('close', function(err) {
return stopCmd();
});
proc.on('error', function(err) {
return console.log(' ERROR '.bgRed.white + (' ' + err.message + ' ').bgWhite);
});
return i++;
};
stopCmd();
return 'Stopping...';
};
}).call(this);