Skip to content

Commit

Permalink
fix: better handling of stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
benoror committed Aug 21, 2015
1 parent b3a95c9 commit 607e522
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions index.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
#!/usr/bin/env node

console.log('running better-npm-run in', process.cwd());
var join = require('path').join;
var fullPackagePath = join(process.cwd(), 'package.json');
var pkg = require(fullPackagePath);
var exec = require('./lib/exec.js')

if (!pkg.scripts) {
process.stderr.write('ERROR: No scripts found!');
process.exit(1);
}
if (!pkg.betterScripts) {
process.stderr.write('ERROR: No betterScripts found!');
process.exit(1);
}
if (!process.argv[2]) {
process.stderr.write('ERROR: No script name provided!');
process.exit(1);
}
if (!pkg.betterScripts[process.argv[2]]) {
process.stderr.write('ERROR: No betterScript with name "'+process.argv[2]+'" was found!');
process.exit(1);
}

console.log('Executing script: ' + process.argv[2] + '\n');

exec(pkg.betterScripts[process.argv[2]]);
#!/usr/bin/env node

console.log('running better-npm-run in', process.cwd());
var join = require('path').join;
var fullPackagePath = join(process.cwd(), 'package.json');
var pkg = require(fullPackagePath);
var exec = require('./lib/exec.js')

if (!pkg.scripts) {
process.stderr.write('ERROR: No scripts found!');
process.exit(1);
}
if (!pkg.betterScripts) {
process.stderr.write('ERROR: No betterScripts found!');
process.exit(1);
}
if (!process.argv[2]) {
process.stderr.write('ERROR: No script name provided!');
process.exit(1);
}
if (!pkg.betterScripts[process.argv[2]]) {
process.stderr.write('ERROR: No betterScript with name "'+process.argv[2]+'" was found!');
process.exit(1);
}

console.log('Executing script: ' + process.argv[2] + '\n');

exec(pkg.betterScripts[process.argv[2]], function (error, stdout, stderr) {
process.stderr.write(stderr);
process.stdout.write(stdout);
if(error !== null) {
console.log('exec error: '+error);
}
});

0 comments on commit 607e522

Please sign in to comment.