-
Notifications
You must be signed in to change notification settings - Fork 8
/
runner.js
274 lines (256 loc) · 8.01 KB
/
runner.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
const yargs = require('yargs');
const path = require('path');
const fs = require('fs-extra');
const process = require('node:child_process');
const { exec } = require('node:child_process');
const { pathExists } = require('@nx/eslint-plugin/src/utils/graph-utils');
const crypto = require('crypto');
const JSONValidator = {
build: async function () {
await buildLibrary('json-sets');
},
};
async function buildLibrary(libraryName) {
if (await pathExists(`dist/libs/${libraryName}`)) {
await fs.rm(`dist/libs/${libraryName}`, {
recursive: true
})
}
await run(`nx build ${libraryName} --skip-nx-cache`);
await fs.copyFile(
`libs/${libraryName}/LICENSE.txt`,
`dist/libs/${libraryName}/LICENSE.txt`
);
await fs.copyFile(
`libs/${libraryName}/README.md`,
`dist/libs/${libraryName}/README.md`
);
await fs.copyFile(
`libs/${libraryName}/CHANGELOG.md`,
`dist/libs/${libraryName}/CHANGELOG.md`
);
}
const Project = {
updateLicenses: async function () {
await fs.copyFile(`./LICENSE.txt`, `./libs/annotation/src/LICENSE.txt`);
await fs.copyFile(`./LICENSE.txt`, `./libs/assets/src/LICENSE.txt`);
await fs.copyFile(`./LICENSE.txt`, `./libs/media/src/LICENSE.txt`);
await fs.copyFile(`./LICENSE.txt`, `./libs/utilities/src/LICENSE.txt`);
await fs.copyFile(`./LICENSE.txt`, `./apps/web-components/src/LICENSE.txt`);
await fs.copyFile(`./LICENSE.txt`, `./libs/json-sets/LICENSE.txt`);
await fs.copyFile(`./LICENSE.txt`, `./libs/ngx-components/LICENSE.txt`);
await fs.copyFile(`./LICENSE.txt`, `./libs/ngx-utilities/LICENSE.txt`);
},
prepareDocs: async function () {
let content = await fs.readFile(`./typedocs/index.html`, 'utf-8');
content = content.replace(/\.\/([^/]+)\/src\//g, (g0, g1) => {
return `modules/_octra_${g1.replace(/-/g, '_')}.html`;
});
content = content.replace(/apps\/([^/]+)\/src\//g, (g0, g1) => {
return `modules/_octra_${g1.replace(/-/g, '_')}.html`;
});
await fs.writeFile(`./typedocs/index.html`, content, {
encoding: 'utf-8',
});
},
};
const OCTRA = {
start: async function () {
await run('npm run modernizr', true, true);
await run('nx serve', true, false);
},
buildProd: async function () {
await run('node ./build.js dev=false isUpdate=true url=/apps/octra/octra/');
await setBuildVariable();
},
buildRelease: async function () {
await run('node ./build.js dev=false isUpdate=false url=/');
await setBuildVariable();
},
buildDev: async function () {
await run(
'node ./build.js dev=true isUpdate=true url=/apps/octra/octra-dev/'
);
await setBuildVariable();
},
buildBetaDevUpdate: async function () {
await run(
'node ./build.js beta=dev isUpdate=true url=/apps/octra/octra-dev/'
);
await setBuildVariable();
},
buildBetaProdUpdate: async function () {
await run(
'node ./build.js beta=true isUpdate=true url=/apps/octra/octra-2/'
);
await setBuildVariable();
},
buildBetaProd: async function () {
await run('node ./build.js beta=true isUpdate=false url=/');
await setBuildVariable();
await fs.rm('dist/apps/octra/media', { recursive: true });
await fs.rm('dist/apps/octra/config/appconfig.json');
},
prepareExtern: async function () {
if (fs.pathExistsSync('extern')) {
fs.emptydirSync('extern');
fs.rmdirSync('extern');
}
fs.copySync('dist/libs', 'extern/libs', { recursive: true });
},
buildExtern: async function () {
await OCTRA.buildLibs();
await OCTRA.prepareExtern();
},
buildLibs: async function () {
await buildLibrary('ngx-components');
await buildLibrary('ngx-utilities');
await run(`node prepare_web-components.js`);
await fs.copyFile(
`apps/web-components/src/README.md`,
`dist/libs/web-components/README.md`
);
await fs.copyFile(
`apps/web-components/CHANGELOG.md`,
`dist/libs/web-components/CHANGELOG.md`
);
await JSONValidator.build();
await buildLibrary('utilities');
await OCTRA.buildAssets();
await buildLibrary('annotation');
await buildLibrary('media');
await buildLibrary('web-media');
},
buildAssets: async function () {
await buildLibrary('assets');
await fs.copyFile(
'./libs/assets/src/lib/schemata/inputs_outputs.set.json',
'./dist/libs/assets/lib/schemata/inputs_outputs.set.json'
);
await fs.copyFile(
'./libs/assets/src/lib/schemata/guidelines.schema.json',
'./dist/libs/assets/lib/schemata/guidelines.schema.json'
);
await fs.copyFile(
'./libs/assets/src/lib/schemata/logging.schema.json',
'./dist/libs/assets/lib/schemata/logging.schema.json'
);
await fs.copyFile(
'./libs/assets/src/lib/schemata/projectconfig.schema.json',
'./dist/libs/assets/lib/schemata/projectconfig.schema.json'
);
},
};
yargs
.version('1.0.0')
.help()
.alias('help', 'h')
.command('start', 'Starts serving OCTRA.', OCTRA.start)
.command(
'build:release',
'Builds release version of OCTRA.',
OCTRA.buildRelease
)
.command('build:prod', 'Builds production version of OCTRA.', OCTRA.buildProd)
.command('build:dev', 'Builds development version of OCTRA.', OCTRA.buildDev)
.command('build:beta', 'Builds beta version of OCTRA.', OCTRA.buildBeta)
.command(
'build:prod:beta',
'Builds prod beta version of OCTRA.',
OCTRA.buildBetaProd
)
.command(
'build:prod:update:beta',
'Builds prod beta update version of OCTRA.',
OCTRA.buildBetaProdUpdate
)
.command(
'build:dev:update:beta',
'Builds dev beta update version of OCTRA.',
OCTRA.buildBetaDevUpdate
)
.command('build:libs', 'Builds all libraries.', OCTRA.buildLibs)
.command(
'build:lib [library]',
'Builds a library.',
(yargs) =>
yargs.positional('library', {
describe: 'library name',
}),
(argv) => {
buildLibrary(argv.library);
}
)
.command('build:assets', 'Builds assets library.', OCTRA.buildAssets)
.command('build:extern', 'Builds extern libraries.', OCTRA.buildExtern)
.command('build:json-sets', 'Builds json-sets library.', JSONValidator.build)
.command(
'update:licenses',
'Updates licenses with current version from root.',
Project.updateLicenses
)
.command('prepare:docs', 'Prepares docs', Project.prepareDocs).argv;
async function run(scriptPath, showOutput = true, returnAfterExit = true) {
return new Promise((resolve, reject) => {
let output = '';
const process = exec(scriptPath);
if (process) {
process.stdout.on('data', (data) => {
if (showOutput) {
if (returnAfterExit) {
output += data;
} else {
console.log(data);
}
}
});
process.stdout.on('error', (data) => {
if (showOutput) {
if (returnAfterExit) {
output += data;
} else {
console.log(data);
}
}
});
process.stderr.on('data', (data) => {
if (showOutput) {
if (returnAfterExit) {
output += data;
} else {
console.log(data);
}
}
});
// what to do when the command is done
process.on('close', (code) => {
if (showOutput && returnAfterExit) {
console.log(output);
}
resolve(output);
});
} else {
reject("Can't run script.");
}
});
}
async function setBuildVariable() {
let content = await fs.readFile('./dist/apps/octra/index.html', {
encoding: 'utf-8',
});
const pkg = await fs.readJSON('./package.json', {
encoding: 'utf-8',
});
let hash = crypto.randomUUID();
content = content.replace(/(var BUILD =)([^;]*)(;)/gs, (g0, g1, g2, g3) => {
const build = JSON.parse(g2);
build.version = pkg.version;
build.timestamp = new Date().toISOString();
build.hash = hash;
return `${g1} ${JSON.stringify(build)}${g3}`;
});
await fs.writeFile('./dist/apps/octra/index.html', content, {
encoding: 'utf-8',
});
console.log(`BUILD-HASH: ${hash}`);
}