Skip to content

Commit

Permalink
fix(child-process): Ensure adjacent prefixes are always a different c…
Browse files Browse the repository at this point in the history
…olor

Validated manually with this command:
```
npx lerna exec --stream --concurrency 1 -- 'echo $PWD'
```
  • Loading branch information
evocateur committed May 16, 2019
1 parent c4d165a commit 5a10146
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/child-process/index.js
Expand Up @@ -12,6 +12,9 @@ let children = 0;
const colorWheel = ["cyan", "magenta", "blue", "yellow", "green", "red"];
const NUM_COLORS = colorWheel.length;

// ever-increasing index ensures colors are always sequential
let currentColor = 0;

function exec(command, args, opts) {
const options = Object.assign({ stdio: "pipe" }, opts);
const spawned = spawnProcess(command, args, options);
Expand All @@ -35,14 +38,17 @@ function spawnStreaming(command, args, opts, prefix) {
const options = Object.assign({}, opts);
options.stdio = ["ignore", "pipe", "pipe"];

const colorName = colorWheel[children % NUM_COLORS];
const color = chalk[colorName];
const spawned = spawnProcess(command, args, options);

const stdoutOpts = {};
const stderrOpts = {}; // mergeMultiline causes escaped newlines :P

if (prefix) {
const colorName = colorWheel[currentColor % NUM_COLORS];
const color = chalk[colorName];

currentColor += 1;

stdoutOpts.tag = `${color.bold(prefix)}:`;
stderrOpts.tag = `${color(prefix)}:`;
}
Expand Down

0 comments on commit 5a10146

Please sign in to comment.