Created
June 15, 2015 19:47
-
-
Save melihovv/9e94cb41ff28ecb58d53 to your computer and use it in GitHub Desktop.
Pre-commit hook.
This file contains 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 | |
"use strict"; | |
var path = require('path'); | |
var execSync = require('child_process').execSync; | |
var hook = path.basename(__filename); | |
var config = require(path.resolve(process.cwd(), 'package')); | |
if (!config[hook]) { | |
process.exit(0); | |
} | |
var output = []; | |
var error = false; | |
var errorStatus = ''; | |
config[hook].forEach(function (command) { | |
var cmd = config.scripts[command]; | |
try { | |
output.push(execSync(cmd, {encoding: 'utf-8'})); | |
} catch (e) { | |
console.log(e.stdout); | |
console.error(e.stderr); | |
error = true; | |
errorStatus = e.status; | |
} | |
}); | |
if (error) { | |
process.exit(errorStatus); | |
} else { | |
output.forEach(function(message) { | |
if (message) { | |
console.log(message); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
package.json: