You can use scripts with node run-script command. npm run
is a shortcut of it.
Package json:
"scripts" : {
"build-windows" : "node build-windows.js",
"build-linux" : "node build-linux.js",
"build-mac" : "node build-mac.js",
"build" : "node build.js"
}
Command line:
npm run build-windows
If you don't like it, you can use commands inside node.js.
Package json:
"scripts" : {
"build" : "node build.js"
}
Build.js
var sys = require('sys');
var exec = require('child_process').exec;
var os = require('os');
function puts(error, stdout, stderr) { sys.puts(stdout) }
// Run command depending on the OS
if (os.type() === 'Linux')
exec("node build-linux.js", puts);
else if (os.type() === 'Darwin')
exec("node build-mac.js", puts);
else if (os.type() === 'Windows_NT')
exec("node build-windows.js", puts);
else
throw new Error("Unsupported OS found: " + os.type());
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…