-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.packages.functions.js
128 lines (119 loc) · 3.67 KB
/
env.packages.functions.js
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { commandNames, dependsOnNames, nxProjectRoot, nxRoot, packagesPath, repoDir } from './env.packages.constants.js';
import { getToPath } from './scripts/fs.functions.js';
/**
* @param {string} packageName
* @param {import('./env.js').INxTargets} commands
* @returns {import('./env.js').INxProject}
*/
export function generateNxProjectJson(packageName, commands = {}) {
const projectPath = `${packagesPath}/${packageName}`;
return {
name: packageName,
projectType: 'library',
sourceRoot: projectPath,
tags: [],
targets: {
...commands,
...baseCommands(packageName, projectPath),
...containerCommands(packageName, commands),
},
};
}
/**
* @param {string} packageName
* @param {string} projectPath
* @returns {import('./env.js').INxTargets}
*/
function baseCommands(packageName, projectPath) {
const relativePath = getToPath(projectPath, packagesPath);
return {
[commandNames.repo.update]: baseCommand({
commands: [`nx run ${packageName}:${commandNames.repo.updateVersion}`, `nx run ${packageName}:${commandNames.repo.clone}`],
cwd: projectPath,
}),
[commandNames.repo.updateVersion]: baseCommand({
commands: [`node ${relativePath}/repo.update-version.js`],
cwd: projectPath,
}),
[commandNames.repo.clone]: baseCommand({
commands: [`node ${relativePath}/repo.clone.js`],
cwd: projectPath,
}),
};
}
/**
* @param {string} projectPath
* @param {string[]} packageFlags
* @param {string[]} emscriptenFlags
* @return {import('./env.d.ts').INxTargets}
*/
export function basePackageCommands(projectPath, packageFlags, emscriptenFlags) {
return {
[commandNames.package.configure]: {
dependsOn: [`${dependsOnNames.envJson}`],
...baseCommand({
commands: [`emconfigure ./configure ${packageFlags.join(' ')}`],
cwd: `${projectPath}/${repoDir}`,
}),
},
[commandNames.package.emmake]: {
dependsOn: [`${commandNames.package.configure}`],
...baseCommand({
commands: [`emmake make ${emscriptenFlags.join(' ')}`],
cwd: `${projectPath}/${repoDir}`,
}),
},
[commandNames.package.install]: {
dependsOn: [`${commandNames.package.emmake}`],
...baseCommand({
commands: ['emmake make install'],
cwd: `${projectPath}/${repoDir}`,
}),
},
[commandNames.package.make]: {
dependsOn: [`${commandNames.package.configure}`],
...baseCommand({
commands: [`make`],
cwd: `${projectPath}/${repoDir}`,
}),
},
};
}
/**
* @param {string} packageName
* @param {import('./env.js').INxTargets} commands
* @returns {import('./env.js').INxTargets}
*/
function containerCommands(packageName, commands) {
return Object.keys(commands).reduce((acc, key) => {
const runContainCommand = baseCommand({
commands: [`${commandNames.container} run -t ${commandNames.containerImg} nx run ${packageName}:${key}`],
});
const runInContainerCommand = baseCommand({
commands: [
`node shell.run-current-path.js \
"${commandNames.container} \
run -v $PWD:/${commandNames.containerImg} -t ${commandNames.containerImg} \
find ./packages -type f -exec dos2unix {} + && nx run ${packageName}:${key}"`,
],
});
acc[`${commandNames.container}:${key}`] = runContainCommand;
acc[`${commandNames.container}:mount:${key}`] = runInContainerCommand;
return acc;
}, {});
}
/**
* @param {import('./env.js').INxTargetOptions} options
* @returns {import('./env.js').INxTarget}
*/
function baseCommand(options) {
return {
executor: 'nx:run-commands',
options: {
parallel: false,
cwd: '',
color: true,
...options,
},
};
}