From 607e522c3c0ca68068fab15d6f9f59dc6cc92a00 Mon Sep 17 00:00:00 2001 From: Benjamin Orozco Date: Fri, 21 Aug 2015 17:51:58 +0000 Subject: [PATCH] fix: better handling of stderr --- index.js | 62 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 28 deletions(-) mode change 100644 => 100755 index.js diff --git a/index.js b/index.js old mode 100644 new mode 100755 index b7f1c66..68a3f67 --- a/index.js +++ b/index.js @@ -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]]); \ No newline at end of file +#!/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); + } +});