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

feat(core): add prefixColor property to @nx:run-commands #29348

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/generated/packages/nx/executors/run-commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 16 additions & 5 deletions packages/nx/src/executors/run-commands/run-commands.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface RunCommandsOptions extends Json {
*/
description?: string;
prefix?: string;
prefixColor?: string;
color?: string;
bgColor?: string;
}
Expand Down Expand Up @@ -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".'
);
}

Expand Down Expand Up @@ -317,6 +320,7 @@ async function createProcess(
color?: string;
bgColor?: string;
prefix?: string;
prefixColor?: string;
},
readyWhenStatus: { stringToMatch: string; found: boolean }[] = [],
color: boolean,
Expand Down Expand Up @@ -377,6 +381,7 @@ function nodeProcess(
color?: string;
bgColor?: string;
prefix?: string;
prefixColor?: string;
},
cwd: string,
env: Record<string, string>,
Expand Down Expand Up @@ -438,16 +443,22 @@ function addColorAndPrefix(
out: string,
config: {
prefix?: string;
prefixColor?: string;
color?: string;
bgColor?: string;
}
) {
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]) {
Expand Down
14 changes: 14 additions & 0 deletions packages/nx/src/executors/run-commands/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down