Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix colors option when using wildcard commands #286

Merged
merged 10 commits into from
Oct 2, 2021
3 changes: 2 additions & 1 deletion bin/concurrently.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ concurrently(args._.map((command, index) => {
restartDelay: args.restartAfter,
restartTries: args.restartTries,
successCondition: args.success,
timestampFormat: args.timestampFormat
timestampFormat: args.timestampFormat,
prefixColors
}).then(
() => process.exit(0),
() => process.exit(1)
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ module.exports = exports = (commands, options = {}) => {
logger,
conditions: options.killOthers
})
]
],
prefixColors: options.prefixColors || []
});
};

Expand Down
36 changes: 22 additions & 14 deletions src/concurrently.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ module.exports = (commands, options) => {
assert.ok(Array.isArray(commands), '[concurrently] commands should be an array');
assert.notStrictEqual(commands.length, 0, '[concurrently] no commands provided');

const prefixColors = options.prefixColors;

delete options.prefixColors;
options = _.defaults(options, defaults);

const commandParsers = [
Expand All @@ -32,21 +35,25 @@ module.exports = (commands, options) => {
new ExpandNpmWildcard()
];

let lastColor = undefined;
commands = _(commands)
.map(mapToCommandInfo)
.flatMap(command => parseCommand(command, commandParsers))
.map((command, index) => new Command(
Object.assign({
index,
spawnOpts: getSpawnOpts({
raw: options.raw,
env: command.env,
cwd: command.cwd || options.cwd,
}),
killProcess: options.kill,
spawn: options.spawn,
}, command)
))
.map((command, index) => {
lastColor = prefixColors && prefixColors[index] || lastColor;
return new Command(
Object.assign({
index,
spawnOpts: getSpawnOpts({
raw: options.raw,
env: command.env,
cwd: command.cwd || options.cwd,
}),
killProcess: options.kill,
spawn: options.spawn,
}, command, lastColor ? { prefixColor: lastColor } : null)
);
})
.value();

const handleResult = options.controllers.reduce(
Expand All @@ -55,11 +62,11 @@ module.exports = (commands, options) => {
return {
commands,
onFinishCallbacks: _.concat(onFinishCallbacks, onFinish ? [onFinish] : [])
}
};
},
{ commands, onFinishCallbacks: [] }
);
commands = handleResult.commands
commands = handleResult.commands;

const commandsLeft = commands.slice();
const maxProcesses = Math.max(1, Number(options.maxProcesses) || commandsLeft.length);
Expand All @@ -79,6 +86,7 @@ function mapToCommandInfo(command) {
command: command.command || command,
name: command.name || '',
prefixColor: command.prefixColor || '',
daniloraisi marked this conversation as resolved.
Show resolved Hide resolved
prefixColors: command.prefixColors || [],
env: command.env || {},
cwd: command.cwd || '',
};
Expand Down