Skip to content

Commit

Permalink
Merge branch 'feature/run-stdio' into builded/petcommunities
Browse files Browse the repository at this point in the history
* feature/run-stdio:
  run: allow custom stdio
  • Loading branch information
LoicMahieu committed Jun 20, 2016
2 parents da0778d + d116f4d commit c89f1d9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
3 changes: 2 additions & 1 deletion bin/lerna.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ var cli = meow([
" --force-publish Force publish for the specified packages (comma-separated) or all packages using * (skips the git diff check for changed packages)",
" --yes Skip all confirmation prompts",
" --repo-version Specify repo version to publish",
" --concurrency How many threads to use if lerna parallelises the tasks (defaults to 4)"
" --concurrency How many threads to use if lerna parallelises the tasks (defaults to 4)",
" --stdio Specify stdio for run script (defaults to ignore)"
], {
alias: {
independent: "i",
Expand Down
14 changes: 12 additions & 2 deletions src/NpmUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,18 @@ export default class NpmUtilities {
}

@logger.logifyAsync
static runScriptInDir(script, args, directory, callback) {
NpmUtilities.execInDir(`run ${script}`, args, directory, callback);
static runScriptInDir(script, args, directory, options, callback) {
if (typeof options === 'function') {
callback = options
}

args = ["run", script].concat(args);
const opts = Object.assign({
cwd: directory,
stdio: "ignore"
}, options)

ChildProcessUtilities.spawn("npm", args, opts, callback);
}

@logger.logifyAsync
Expand Down
4 changes: 3 additions & 1 deletion src/commands/RunCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export default class RunCommand extends Command {
}

runScriptInPackage(pkg, callback) {
NpmUtilities.runScriptInDir(this.script, this.args, pkg.location, (err, stdout) => {
NpmUtilities.runScriptInDir(this.script, this.args, pkg.location, {
stdio: this.flags.stdio
}, (err, stdout) => {
if (err) {
this.logger.error(`Errored while running npm script '${this.script}' in '${pkg.name}'`, err);
} else {
Expand Down
23 changes: 22 additions & 1 deletion test/RunCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("RunCommand", () => {
runCommand.runPreparations();

const ranInPackages = [];
stub(ChildProcessUtilities, "exec", (command, options, callback) => {
stub(ChildProcessUtilities, "spawn", (command, args, options, callback) => {
ranInPackages.push(options.cwd.substr(path.join(testDir, "packages/").length));
callback();
});
Expand All @@ -51,4 +51,25 @@ describe("RunCommand", () => {
done();
}));
});

it("should run a command with a given stdio", done => {
const runCommand = new RunCommand(["my-script"], {stdio: "inherit"});

runCommand.runValidations();
runCommand.runPreparations();

const stdios = [];
stub(ChildProcessUtilities, "spawn", (command, args, options, callback) => {
stdios.push([options.stdio, args]);
callback();
});

runCommand.runCommand(exitWithCode(0, () => {
assert.deepEqual(stdios, [
["inherit", ["run", "my-script"]],
["inherit", ["run", "my-script"]]
]);
done();
}));
});
});

0 comments on commit c89f1d9

Please sign in to comment.