diff --git a/docs/generated/cli/affected.md b/docs/generated/cli/affected.md index 015281c82a2a9a..8ee054bb45e9d6 100644 --- a/docs/generated/cli/affected.md +++ b/docs/generated/cli/affected.md @@ -99,11 +99,11 @@ Change the way Nx is calculating the affected command by providing directly chan ### graph -Type: `boolean` +Type: `string` Default: `false` -Show the task graph of the command +Show the task graph of the command. Pass a file path to save the graph data instead of viewing it in the browser. ### head diff --git a/docs/generated/cli/exec.md b/docs/generated/cli/exec.md index f30730dd776840..2a5b82e2d2116b 100644 --- a/docs/generated/cli/exec.md +++ b/docs/generated/cli/exec.md @@ -31,11 +31,11 @@ Exclude certain projects from being processed ### graph -Type: `boolean` +Type: `string` Default: `false` -Show the task graph of the command +Show the task graph of the command. Pass a file path to save the graph data instead of viewing it in the browser. ### nx-bail diff --git a/docs/generated/cli/run-many.md b/docs/generated/cli/run-many.md index bcacf2666e21c9..21366e40cf290a 100644 --- a/docs/generated/cli/run-many.md +++ b/docs/generated/cli/run-many.md @@ -83,11 +83,11 @@ Exclude certain projects from being processed ### graph -Type: `boolean` +Type: `string` Default: `false` -Show the task graph of the command +Show the task graph of the command. Pass a file path to save the graph data instead of viewing it in the browser. ### help diff --git a/docs/generated/packages/nx/documents/affected.md b/docs/generated/packages/nx/documents/affected.md index 015281c82a2a9a..8ee054bb45e9d6 100644 --- a/docs/generated/packages/nx/documents/affected.md +++ b/docs/generated/packages/nx/documents/affected.md @@ -99,11 +99,11 @@ Change the way Nx is calculating the affected command by providing directly chan ### graph -Type: `boolean` +Type: `string` Default: `false` -Show the task graph of the command +Show the task graph of the command. Pass a file path to save the graph data instead of viewing it in the browser. ### head diff --git a/docs/generated/packages/nx/documents/exec.md b/docs/generated/packages/nx/documents/exec.md index f30730dd776840..2a5b82e2d2116b 100644 --- a/docs/generated/packages/nx/documents/exec.md +++ b/docs/generated/packages/nx/documents/exec.md @@ -31,11 +31,11 @@ Exclude certain projects from being processed ### graph -Type: `boolean` +Type: `string` Default: `false` -Show the task graph of the command +Show the task graph of the command. Pass a file path to save the graph data instead of viewing it in the browser. ### nx-bail diff --git a/docs/generated/packages/nx/documents/run-many.md b/docs/generated/packages/nx/documents/run-many.md index bcacf2666e21c9..21366e40cf290a 100644 --- a/docs/generated/packages/nx/documents/run-many.md +++ b/docs/generated/packages/nx/documents/run-many.md @@ -83,11 +83,11 @@ Exclude certain projects from being processed ### graph -Type: `boolean` +Type: `string` Default: `false` -Show the task graph of the command +Show the task graph of the command. Pass a file path to save the graph data instead of viewing it in the browser. ### help diff --git a/packages/nx/src/command-line/affected/affected.ts b/packages/nx/src/command-line/affected/affected.ts index 402f4a04264ee8..4d949b5793d512 100644 --- a/packages/nx/src/command-line/affected/affected.ts +++ b/packages/nx/src/command-line/affected/affected.ts @@ -83,7 +83,11 @@ export async function affected( const projectsWithTarget = allProjectsWithTarget(projects, nxArgs); if (nxArgs.graph) { const projectNames = projectsWithTarget.map((t) => t.name); - + const file = + typeof nxArgs.graph === 'string' && + (nxArgs.graph.endsWith('.json') || nxArgs.graph.endsWith('html')) + ? nxArgs.graph + : undefined; return await generateGraph( { watch: false, @@ -91,6 +95,7 @@ export async function affected( view: 'tasks', targets: nxArgs.targets, projects: projectNames, + file, }, projectNames ); diff --git a/packages/nx/src/command-line/run-many/run-many.ts b/packages/nx/src/command-line/run-many/run-many.ts index 16cc92e903713d..55e06f1c8aa407 100644 --- a/packages/nx/src/command-line/run-many/run-many.ts +++ b/packages/nx/src/command-line/run-many/run-many.ts @@ -46,6 +46,11 @@ export async function runMany( const projects = projectsToRun(nxArgs, projectGraph); if (nxArgs.graph) { + const file = + typeof nxArgs.graph === 'string' && + (nxArgs.graph.endsWith('.json') || nxArgs.graph.endsWith('html')) + ? nxArgs.graph + : undefined; const projectNames = projects.map((t) => t.name); return await generateGraph( { @@ -55,6 +60,7 @@ export async function runMany( all: nxArgs.all, targets: nxArgs.targets, projects: projectNames, + file, }, projectNames ); diff --git a/packages/nx/src/command-line/run/run-one.ts b/packages/nx/src/command-line/run/run-one.ts index 3ef3099fe78dd1..cf13b8b233569b 100644 --- a/packages/nx/src/command-line/run/run-one.ts +++ b/packages/nx/src/command-line/run/run-one.ts @@ -66,6 +66,11 @@ export async function runOne( if (nxArgs.graph) { const projectNames = projects.map((t) => t.name); + const file = + typeof nxArgs.graph === 'string' && + (nxArgs.graph.endsWith('.json') || nxArgs.graph.endsWith('html')) + ? nxArgs.graph + : undefined; return await generateGraph( { @@ -74,6 +79,7 @@ export async function runOne( view: 'tasks', targets: nxArgs.targets, projects: projectNames, + file, }, projectNames ); diff --git a/packages/nx/src/command-line/yargs-utils/shared-options.ts b/packages/nx/src/command-line/yargs-utils/shared-options.ts index 8aaab5e901668e..45a4046ed387a9 100644 --- a/packages/nx/src/command-line/yargs-utils/shared-options.ts +++ b/packages/nx/src/command-line/yargs-utils/shared-options.ts @@ -29,8 +29,9 @@ export function withRunOptions(yargs: Argv): Argv { hidden: true, }) .option('graph', { - type: 'boolean', - describe: 'Show the task graph of the command', + type: 'string', + describe: + 'Show the task graph of the command. Pass a file path to save the graph data instead of viewing it in the browser.', default: false, }) .option('verbose', { diff --git a/packages/nx/src/utils/command-line-utils.ts b/packages/nx/src/utils/command-line-utils.ts index 19b6d9ec4beb27..878ceb62539de7 100644 --- a/packages/nx/src/utils/command-line-utils.ts +++ b/packages/nx/src/utils/command-line-utils.ts @@ -29,7 +29,7 @@ export interface NxArgs { plain?: boolean; projects?: string[]; select?: string; - graph?: boolean; + graph?: string | boolean; skipNxCache?: boolean; outputStyle?: string; nxBail?: boolean; @@ -81,6 +81,15 @@ export function splitArgsIntoNxArgsAndOverrides( delete (nxArgs as any).$0; delete (nxArgs as any).__overrides_unparsed__; + if (!(nxArgs.graph === null || nxArgs.graph === undefined)) { + nxArgs.graph = + nxArgs.graph === 'true' || nxArgs.graph === true + ? true + : nxArgs.graph === 'false' || nxArgs.graph === false + ? false + : nxArgs.graph; + } + if (mode === 'run-many') { const args = nxArgs as any; if (!args.projects) {