Skip to content

Commit

Permalink
feat(core): ability to save task graph to a file when running --graph
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed May 12, 2023
1 parent 25e8439 commit 16b6b23
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 16 deletions.
4 changes: 2 additions & 2 deletions docs/generated/cli/affected.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/generated/cli/exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/generated/cli/run-many.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/generated/packages/nx/documents/affected.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/generated/packages/nx/documents/exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/generated/packages/nx/documents/run-many.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion packages/nx/src/command-line/affected/affected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,19 @@ 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,
open: true,
view: 'tasks',
targets: nxArgs.targets,
projects: projectNames,
file,
},
projectNames
);
Expand Down
6 changes: 6 additions & 0 deletions packages/nx/src/command-line/run-many/run-many.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -55,6 +60,7 @@ export async function runMany(
all: nxArgs.all,
targets: nxArgs.targets,
projects: projectNames,
file,
},
projectNames
);
Expand Down
6 changes: 6 additions & 0 deletions packages/nx/src/command-line/run/run-one.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -74,6 +79,7 @@ export async function runOne(
view: 'tasks',
targets: nxArgs.targets,
projects: projectNames,
file,
},
projectNames
);
Expand Down
5 changes: 3 additions & 2 deletions packages/nx/src/command-line/yargs-utils/shared-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
11 changes: 10 additions & 1 deletion packages/nx/src/utils/command-line-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface NxArgs {
plain?: boolean;
projects?: string[];
select?: string;
graph?: boolean;
graph?: string | boolean;
skipNxCache?: boolean;
outputStyle?: string;
nxBail?: boolean;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 16b6b23

Please sign in to comment.