-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.js
49 lines (42 loc) · 1.13 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
48
49
import esbuild from 'esbuild';
import { writeFileSync } from 'fs';
const commonEsbuildSettings = {
bundle: true,
format: 'iife',
write: false,
sourcemap: false,
minify: false,
target: ['es2020'],
};
const processes = [
{
entryPoints: ['src/game/process/hub.mjs'],
outfile: 'dist/output-hub.js',
...commonEsbuildSettings,
},
{
entryPoints: ['src/game/process/game.mjs'],
outfile: 'dist/output-game.js',
...commonEsbuildSettings,
},
];
processes.forEach(async (process) => {
console.log(`Building ${process.entryPoints[0]}`);
const result = await esbuild.build(process);
for (let out of result.outputFiles) {
let contractSrc = out.text;
const lines = contractSrc.trim().split('\n');
const first = lines[0];
const last = lines[lines.length - 1];
if (
(/\(\s*\(\)\s*=>\s*{/g.test(first) || /\s*\(\s*function\s*\(\)\s*{/g.test(first)) &&
/}\s*\)\s*\(\)\s*;/g.test(last)
) {
lines.shift();
lines.pop();
contractSrc = lines.join('\n');
}
writeFileSync(out.path, contractSrc);
//console.log(out.path, out.contents, out.hash, out.text)
}
});