Created
May 6, 2014 02:00
-
-
Save bustardcelly/399bafdf1b0c52593067 to your computer and use it in GitHub Desktop.
Little script to run node on change to single file target
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 | |
var path = require('path'); | |
var watch = require('node-watch'); | |
var parseArgs = require('minimist'); | |
var argv = parseArgs(process.argv.slice(2)); | |
var exec = require('child_process').spawn; | |
var trimNewLine = /\s+$/; | |
require('colors'); | |
if(argv._.length > 0) { | |
var filepath = argv._[0]; | |
watch(filepath, function(filename) { | |
var child = exec('node', [filename]); | |
child.stdout.on('data', function(data) { | |
console.log((data.toString().replace(trimNewLine,'')).white); | |
}); | |
child.stderr.on('data', function(data) { | |
console.log(('Error: ' + data.toString()).red); | |
}); | |
child.on('exit', function(err) { | |
if(err) { | |
console.log(('Error in running node on ' + filename).yellow); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ npm install minimist && npm install node-watch && npm install colors
alias watchfile='node /path/to/node-watcher.js $1'
$ watchfile quickidea.js