Last active
September 18, 2015 09:43
-
-
Save lotterfriends/ad8cdeda13d6a03bf53f to your computer and use it in GitHub Desktop.
default node script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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