Last active
March 18, 2025 05:05
-
-
Save morganrallen/9222028 to your computer and use it in GitHub Desktop.
NPM script runner.
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
var path = require("path"); | |
var spawn = require("child_process").spawn; | |
var scripts = process.argv.slice(2); | |
console.log("Running from %s", process.cwd()); | |
scripts.forEach(function(script) { | |
console.log("[executing] npm run %s", script); | |
var proc = spawn("npm", ["run", script]); | |
proc.stdout.on("data", function(data) { | |
process.stdout.write("[" + script + "] " + data); | |
}); | |
proc.stderr.on("data", function(data) { | |
process.stderr.write("[" + script + "] " + data); | |
}); | |
}); |
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
{ | |
"name": "some-project", | |
"version": "0.0.0", | |
"description": "its just this project, you know?", | |
"main": "index.js", | |
"scripts": { | |
"watchify": "watchify src/js/index.js -d -o app/js/app.js", | |
"less-dev": "cd src/less && nodemon -x lessc ./index.less ../../app/css/index.css", | |
"dev-server": "nodemon server.js", | |
"dev": "node scripts/dev.js watchify less-dev dev-server" | |
}, | |
"author": "Morgan \"ARR!\" Allen", | |
"license": "Beerware" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demonstrates the direction I've been going with using NPM as an alternative to Grunt, gulp, derp, what ever. When ditching Grunt one of the main problems I encountered was not easily being able to run multiple script, maintaining output from a single command. Telling colleagues to run 3 commands in 3 terminals is a bit unacceptable for me.
Read the very timely (for me at least) article from @substack for starting context.
http://substack.net/task_automation_with_npm_run
But two things didn't sit well for me. Firstly using
command & command
background all but the last command, rendering them unkillable by a normal CTRL-C. Deal breaker. Secondly, these are too Bash-centric (or *nix even) in my opinion andusing purely a Node script should maintain reasonable compatibility with Window.