diff --git a/docs/generated/packages/nx/executors/run-commands.json b/docs/generated/packages/nx/executors/run-commands.json index 783ed814baa76..8131cf287cd5e 100644 --- a/docs/generated/packages/nx/executors/run-commands.json +++ b/docs/generated/packages/nx/executors/run-commands.json @@ -34,6 +34,20 @@ "type": "string", "description": "Prefix in front of every line out of the output" }, + "prefixColor": { + "type": "string", + "description": "Color of the prefix", + "enum": [ + "black", + "red", + "green", + "yellow", + "blue", + "magenta", + "cyan", + "white" + ] + }, "color": { "type": "string", "description": "Color of the output", diff --git a/packages/nx/src/executors/run-commands/run-commands.impl.ts b/packages/nx/src/executors/run-commands/run-commands.impl.ts index 98520fa7bce78..4df466e46f1f4 100644 --- a/packages/nx/src/executors/run-commands/run-commands.impl.ts +++ b/packages/nx/src/executors/run-commands/run-commands.impl.ts @@ -43,6 +43,7 @@ export interface RunCommandsOptions extends Json { */ description?: string; prefix?: string; + prefixColor?: string; color?: string; bgColor?: string; } @@ -117,11 +118,13 @@ export default async function ( } if ( - options.commands.find((c: any) => c.prefix || c.color || c.bgColor) && + options.commands.find( + (c: any) => c.prefix || c.prefixColor || c.color || c.bgColor + ) && !options.parallel ) { throw new Error( - 'ERROR: Bad executor config for run-commands - "prefix", "color" and "bgColor" can only be set when "parallel=true".' + 'ERROR: Bad executor config for run-commands - "prefix", "prefixColor", "color" and "bgColor" can only be set when "parallel=true".' ); } @@ -317,6 +320,7 @@ async function createProcess( color?: string; bgColor?: string; prefix?: string; + prefixColor?: string; }, readyWhenStatus: { stringToMatch: string; found: boolean }[] = [], color: boolean, @@ -377,6 +381,7 @@ function nodeProcess( color?: string; bgColor?: string; prefix?: string; + prefixColor?: string; }, cwd: string, env: Record, @@ -438,6 +443,7 @@ function addColorAndPrefix( out: string, config: { prefix?: string; + prefixColor?: string; color?: string; bgColor?: string; } @@ -445,9 +451,14 @@ function addColorAndPrefix( if (config.prefix) { out = out .split('\n') - .map((l) => - l.trim().length > 0 ? `${chalk.bold(config.prefix)} ${l}` : l - ) + .map((l) => { + let prefixText = config.prefix; + if (config.prefixColor && chalk[config.prefixColor]) { + prefixText = chalk[config.prefixColor](prefixText); + } + prefixText = chalk.bold(prefixText); + return l.trim().length > 0 ? `${prefixText} ${l}` : l; + }) .join('\n'); } if (config.color && chalk[config.color]) { diff --git a/packages/nx/src/executors/run-commands/schema.json b/packages/nx/src/executors/run-commands/schema.json index 1bb23f11872c3..5817d0ae2d665 100644 --- a/packages/nx/src/executors/run-commands/schema.json +++ b/packages/nx/src/executors/run-commands/schema.json @@ -40,6 +40,20 @@ "type": "string", "description": "Prefix in front of every line out of the output" }, + "prefixColor": { + "type": "string", + "description": "Color of the prefix", + "enum": [ + "black", + "red", + "green", + "yellow", + "blue", + "magenta", + "cyan", + "white" + ] + }, "color": { "type": "string", "description": "Color of the output",