-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-graph.ts
110 lines (97 loc) · 2.66 KB
/
generate-graph.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { execSync } from 'child_process';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
import * as yargs from 'yargs';
import { ensureDirSync, statSync } from 'fs-extra';
async function generateGraph(directory: string, name: string) {
if (!existsSync(directory)) {
console.error(`Could not find directory ${directory}`);
return;
}
try {
execSync(
'npx nx graph --file ./node_modules/.cache/nx-graph-gen/graph.html',
{ cwd: directory, stdio: 'ignore', windowsHide: false }
);
} catch {
console.error(`Could not run graph command in directory ${directory}`);
return;
}
const environmentJs = readFileSync(
join(directory, 'node_modules/.cache/nx-graph-gen/static/environment.js'),
{ encoding: 'utf-8' }
);
const projectGraphResponse = environmentJs.match(
/window.projectGraphResponse = (.*?);/
);
const taskGraphResponse = environmentJs.match(
/window.taskGraphResponse = (.*?);/
);
const expandedTaskInputsReponse = environmentJs.match(
/window.expandedTaskInputsResponse = (.*?);/
);
const sourceMapsResponse = environmentJs.match(
/window.sourceMapsResponse = (.*?);/
);
ensureDirSync(
join(__dirname, '../graph/client/src/assets/generated-project-graphs/')
);
ensureDirSync(
join(__dirname, '../graph/client/src/assets/generated-task-graphs/')
);
ensureDirSync(
join(__dirname, '../graph/client/src/assets/generated-task-inputs/')
);
ensureDirSync(
join(__dirname, '../graph/client/src/assets/generated-source-maps/')
);
writeFileSync(
join(
__dirname,
'../graph/client/src/assets/generated-project-graphs/',
`${name}.json`
),
projectGraphResponse[1]
);
writeFileSync(
join(
__dirname,
'../graph/client/src/assets/generated-task-graphs/',
`${name}.json`
),
taskGraphResponse[1]
);
writeFileSync(
join(
__dirname,
'../graph/client/src/assets/generated-task-inputs/',
`${name}.json`
),
expandedTaskInputsReponse[1]
);
writeFileSync(
join(
__dirname,
'../graph/client/src/assets/generated-source-maps/',
`${name}.json`
),
sourceMapsResponse[1]
);
}
(async () => {
const parsedArgs = yargs
.scriptName('pnpm generate-graph')
.strictOptions()
.option('name', {
type: 'string',
requiresArg: true,
description: 'The snake-case name of the file created',
})
.option('directory', {
type: 'string',
requiresArg: true,
description: 'Directory of workspace',
})
.parseSync();
await generateGraph(parsedArgs.directory, parsedArgs.name);
})();