-
Notifications
You must be signed in to change notification settings - Fork 28
/
build.js
47 lines (37 loc) · 1.32 KB
/
build.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
const esbuild = require('esbuild');
const fs = require('fs');
const path = require('path');
const rootBuildFolder = path.join(__dirname, "build");
const tsConfig = path.join(__dirname, "tsconfig.json");
const buildSrcPath = path.join(rootBuildFolder, "build-src.js");
const toolsPath = path.join(rootBuildFolder, "tools.js");
const rootFiles = fs.readdirSync(__dirname);
(async() => {
const entryPoints = [];
for (const file of rootFiles) {
if (!file.endsWith('.ts') || file.endsWith('.d.ts')) continue;
entryPoints.push(path.join(__dirname, file));
}
const result = esbuild.buildSync({
entryPoints,
format: 'cjs',
platform: 'node',
sourcemap: true,
tsconfig: tsConfig,
outdir: rootBuildFolder,
});
if (result.errors.length) {
console.log("Error building root folder: " + result.errors.map(x => x.text).join("\n"));
process.exit(1);
}
const options = require(toolsPath).getRunOptions(__filename);
let previousOffline = options.offline;
options.offline = true;
// building here allows normal TypeScript imports of src files in root level files
await require(buildSrcPath).buildSrc(options).catch(e => {
console.log(e);
process.exit(1);
});
options.offline = previousOffline;
process.exit();
})();