From a16f58c0c5ca979a25aaca67167bdc3a321207d3 Mon Sep 17 00:00:00 2001 From: nc1z Date: Fri, 13 Dec 2024 16:04:40 +0000 Subject: [PATCH 1/2] feat(core): add prefixColor to run-commands --- .../packages/nx/executors/run-commands.json | 14 ++++++++++++++ .../run-commands/run-commands.impl.ts | 19 ++++++++++++++----- .../nx/src/executors/run-commands/schema.json | 14 ++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) 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..d29773b2df86a 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,11 @@ 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 +318,7 @@ async function createProcess( color?: string; bgColor?: string; prefix?: string; + prefixColor?: string; }, readyWhenStatus: { stringToMatch: string; found: boolean }[] = [], color: boolean, @@ -377,6 +379,7 @@ function nodeProcess( color?: string; bgColor?: string; prefix?: string; + prefixColor?: string; }, cwd: string, env: Record, @@ -438,6 +441,7 @@ function addColorAndPrefix( out: string, config: { prefix?: string; + prefixColor?: string; color?: string; bgColor?: string; } @@ -445,9 +449,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", From 00e4c5b3c20b86f88acc16c66078f94b7690ea52 Mon Sep 17 00:00:00 2001 From: nc1z Date: Sat, 14 Dec 2024 02:00:30 +0000 Subject: [PATCH 2/2] fix(core): formatting --- packages/nx/src/executors/run-commands/run-commands.impl.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 d29773b2df86a..4df466e46f1f4 100644 --- a/packages/nx/src/executors/run-commands/run-commands.impl.ts +++ b/packages/nx/src/executors/run-commands/run-commands.impl.ts @@ -118,7 +118,9 @@ export default async function ( } if ( - options.commands.find((c: any) => c.prefix || c.prefixColor || c.color || c.bgColor) && + options.commands.find( + (c: any) => c.prefix || c.prefixColor || c.color || c.bgColor + ) && !options.parallel ) { throw new Error(