-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-graph-environment.ts
76 lines (67 loc) · 2 KB
/
generate-graph-environment.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
import { ensureDirSync } from 'fs-extra';
import { join } from 'path';
import { readdirSync, writeFileSync } from 'fs';
import { execSync } from 'child_process';
function generateFileContent(
workspaces: { id: string; label: string; url: string }[]
) {
return `
window.exclude = [];
window.watch = false;
window.environment = 'dev';
window.useXstateInspect = false;
window.appConfig = {
showDebugger: true,
showExperimentalFeatures: true,
workspaces: ${JSON.stringify(workspaces)},
defaultWorkspaceId: '${workspaces[0].id}',
};
`;
}
function writeFile() {
let generatedGraphs;
try {
generatedGraphs = readdirSync(
join(__dirname, '../graph/client/src/assets/generated-project-graphs')
).map((filename) => {
const id = filename.substring(0, filename.length - 5);
return {
id,
label: id,
projectGraphUrl: join('assets/generated-project-graphs/', filename),
taskGraphUrl: join('assets/generated-task-graphs/', filename),
};
});
} catch {
generatedGraphs = [];
}
let pregeneratedGraphs;
try {
pregeneratedGraphs = readdirSync(
join(__dirname, '../graph/client/src/assets/project-graphs')
).map((filename) => {
const id = filename.substring(0, filename.length - 5);
return {
id,
label: id,
projectGraphUrl: join('assets/project-graphs/', filename),
taskGraphUrl: join('assets/task-graphs/', filename),
};
});
} catch {
pregeneratedGraphs = [];
}
// if no generated projects are found, generate one for nx and try this again
if (generatedGraphs.length === 0) {
execSync('nx run graph-client:generate-graph --directory ./ --name nx');
writeFile();
return;
}
const projects = generatedGraphs.concat(pregeneratedGraphs);
ensureDirSync(join(__dirname, '../graph/client/src/assets/dev/'));
writeFileSync(
join(__dirname, '../graph/client/src/assets/dev/', `environment.js`),
generateFileContent(projects)
);
}
writeFile();