/
build.ts
75 lines (64 loc) · 2.18 KB
/
build.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
import { BuildOptions } from './utils/options';
import { cli } from './bundles/cli';
import { compiler } from './bundles/compiler';
import { createLicense } from './license';
import { devServer } from './bundles/dev-server';
import { emptyDir } from 'fs-extra';
import { internal } from './bundles/internal';
import { mockDoc } from './bundles/mock-doc';
import { release } from './release';
import { screenshot } from './bundles/screenshot';
import { sysDeno } from './bundles/sys-deno';
import { sysNode, sysNodeExternalBundles } from './bundles/sys-node';
import { testing } from './bundles/testing';
import { validateBuild } from './test/validate-build';
import { rollup } from 'rollup';
export async function run(rootDir: string, args: string[]) {
try {
if (args.includes('--release')) {
await release(rootDir, args);
}
if (args.includes('--license')) {
createLicense(rootDir);
}
if (args.includes('--validate-build')) {
await validateBuild(rootDir);
}
} catch (e) {
console.error(e);
process.exit(1);
}
}
export async function createBuild(opts: BuildOptions) {
await Promise.all([
emptyDir(opts.output.cliDir),
emptyDir(opts.output.compilerDir),
emptyDir(opts.output.devServerDir),
emptyDir(opts.output.internalDir),
emptyDir(opts.output.mockDocDir),
emptyDir(opts.output.sysDenoDir),
emptyDir(opts.output.sysNodeDir),
emptyDir(opts.output.testingDir),
]);
await sysNodeExternalBundles(opts);
const bundles = await Promise.all([cli(opts), compiler(opts), devServer(opts), internal(opts), mockDoc(opts), screenshot(opts), testing(opts), sysDeno(opts), sysNode(opts)]);
return bundles.flat();
}
export async function bundleBuild(opts: BuildOptions) {
const bundles = await createBuild(opts);
await Promise.all(
bundles.map(async rollupOption => {
rollupOption.onwarn = () => {};
const bundle = await rollup(rollupOption);
if (Array.isArray(rollupOption.output)) {
await Promise.all(
rollupOption.output.map(async output => {
await bundle.write(output);
}),
);
} else {
await bundle.write(rollupOption.output);
}
}),
);
}