Skip to content

Instantly share code, notes, and snippets.

@shokai
Last active January 28, 2016 08:50
Show Gist options
  • Select an option

  • Save shokai/fc08b63dec4c3a4d5282 to your computer and use it in GitHub Desktop.

Select an option

Save shokai/fc08b63dec4c3a4d5282 to your computer and use it in GitHub Desktop.
run command in each packages of lerna
#!/usr/bin/env node
"use strict";
var path = require("path");
var fs = require("fs");
var spawn = require("child_process").spawn;
var async = require("async");
var pkgs = fs.readdirSync(path.resolve(__dirname + "/../packages/"));
var each = async.eachSeries;
var args = process.argv.slice(2);
if(args[0] === "--parallel"){
each = async.each;
args.shift();
}
var cmd = args.join(' ');
console.log("command: " + cmd);
console.log("packages: " + JSON.stringify(pkgs));
if(cmd.length < 1) process.exit(0);
each(pkgs, function(pkg, next){
var pkgdir = path.resolve(__dirname + "/../packages", pkg);
var _spawn = spawn("sh", ["-c", cmd], {
cwd: pkgdir,
stdio: ['pipe', process.stdout, process.stderr],
env: process.env
})
_spawn.on("close", next);
}, function(err, res){
if(err) console.error(err);
});
@shokai
Copy link
Author

shokai commented Jan 27, 2016

lerna

each

% node bin/run-each-packages ls
% node bin/run-each-packages npm install
% node bin/run-each-packages npm test

parallel

% node bin/run-each-packages --parallel babel src/ --out-dir lib/ --watch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment