Skip to content

Instantly share code, notes, and snippets.

@lotterfriends
Last active September 18, 2015 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lotterfriends/ad8cdeda13d6a03bf53f to your computer and use it in GitHub Desktop.
Save lotterfriends/ad8cdeda13d6a03bf53f to your computer and use it in GitHub Desktop.
default node script
#!/usr/bin/env node
require('shelljs/global');
var when = require('when');
var pipeline = require('when/pipeline');
var colors = require('colors');
var debug = false;
function runCommand(command) {
if (debug) {
console.log('run command: %s', command);
}
return when.promise(function(resolve, reject) {
exec(command, {silent: !debug}, function(code, output) {
if (debug) {
console.log('exitcode: ', code);
}
if (code === 1) {
console.error(output.red);
reject();
} else {
if (debug) {
console.log('output: %s', output);
}
resolve();
}
});
});
}
function doSth() {
return runCommand('ls -l');
}
function doSthWithPara(param) {
return runCommand('ls ' + param);
}
var phasen = [];
phasen.push(doSth);
phasen.push(doSthWithPara.bind(this, '-a'));
var lintPipe = pipeline([phasen]);
lintPipe.then(function() {
console.log('done!'.green);
process.exit(0);
}).catch(function(error) {
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment