-
Notifications
You must be signed in to change notification settings - Fork 14
/
build.ts
61 lines (48 loc) · 1.49 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
/// <reference types="node" />
import {promises} from 'node:fs';
import * as esbuild from 'esbuild';
import type {BuildOptions} from 'esbuild/lib/main';
const commonConfig = {
bundle: true,
sourcemap: true,
minify: true,
metafile: true,
};
const outdir = 'dist';
async function main() {
const processorConfig: BuildOptions = {
entryPoints: [
'processor/realtime-bpm-processor.ts',
],
outfile: `${outdir}/realtime-bpm-processor.js`,
...commonConfig,
};
// Generate JS Builds
console.time('⚡ Build complete! ⚡');
await esbuild.build(processorConfig);
let processor: string | undefined;
try {
processor = await promises.readFile('./dist/realtime-bpm-processor.js', 'utf8');
} catch (error: unknown) {
console.warn(error);
console.warn('NO PROCESSOR BUILT !');
}
// Generate processor file inlined
const generatedProcessor = ['export default `', processor, '`;\n'].join('');
await promises.writeFile('src/generated-processor.ts', generatedProcessor, 'utf8');
const esbuildEsmConfig: BuildOptions = {
entryPoints: ['src/index.ts'],
outfile: `${outdir}/index.esm.js`,
...commonConfig,
platform: 'neutral',
};
const esbuildConfig = Object.assign({}, esbuildEsmConfig);
delete esbuildConfig.platform;
esbuildConfig.outfile = `${outdir}/index.js`;
await esbuild.build(esbuildEsmConfig);
await esbuild.build(esbuildConfig);
console.timeEnd('⚡ Build complete! ⚡');
}
main().catch(error => {
console.error(error);
});