-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.js
105 lines (99 loc) · 3.37 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
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
import * as fsPromises from 'node:fs/promises';
import * as process from 'node:process';
import * as esbuild from 'esbuild';
const logLevel = 'info';
const outdir = 'dist';
// An esbuild plugin that rewrites module specifiers for the external modules.
const resolveExternalModules = {
name: 'resolveExternalModules',
setup(build) {
build.onResolve({ filter: /^[^.]/ }, async (args) => {
switch (args.path) {
case '7z-wasm': return { path: './lib/7zz.es6.js', external: true };
case 'js-fatfs': return { path: './lib/fatfs.js', external: true };
case '@irori/idbfs': return { path: './lib/idbfs.js', external: true };
}
})
},
}
async function installExternalModules() {
await fsPromises.mkdir('dist/soundfonts', { recursive: true });
return Promise.all([
fsPromises.copyFile('node_modules/7z-wasm/7zz.es6.js', 'dist/lib/7zz.es6.js'),
fsPromises.copyFile('node_modules/7z-wasm/7zz.wasm', 'dist/lib/7zz.wasm'),
fsPromises.copyFile('node_modules/js-fatfs/dist/fatfs.js', 'dist/lib/fatfs.js'),
fsPromises.copyFile('node_modules/js-fatfs/dist/fatfs.wasm', 'dist/lib/fatfs.wasm'),
fsPromises.copyFile('node_modules/@irori/idbfs/idbfs.js', 'dist/lib/idbfs.js'),
fsPromises.copyFile('node_modules/font-awesome/css/font-awesome.min.css', 'dist/lib/font-awesome.min.css'),
fsPromises.copyFile('node_modules/font-awesome/fonts/fontawesome-webfont.woff2', 'dist/fonts/fontawesome-webfont.woff2'),
fsPromises.copyFile('SpessaSynth/src/spessasynth_lib/synthetizer/worklet_processor.min.js', 'dist/worklet_processor.min.js'),
fsPromises.copyFile('SpessaSynth/src/spessasynth_lib/synthetizer/audio_effects/impulse_response_2.flac', 'dist/impulse_response_2.flac'),
fsPromises.copyFile('SpessaSynth/soundfonts/GeneralUserGS.sf3', 'dist/soundfonts/GeneralUserGS.sf3'),
]);
}
const configs = [
// Shell
{
entryPoints: [
'shell/shell.ts',
'shell/fdimage.ts',
'shell/spessasynth.ts',
],
external: [
'./fdimage.js',
'./spessasynth.js',
'./system3.js',
'./xsystem35.js',
],
plugins: [resolveExternalModules],
bundle: true,
minify: true,
charset: 'utf8',
format: 'esm',
target: ['es2021'],
outdir,
sourcemap: true,
logLevel,
},
// Worker
{
entryPoints: [
'worker/archiveworker.ts',
],
plugins: [resolveExternalModules],
bundle: true,
minify: true,
charset: 'utf8',
format: 'esm',
target: ['es2021'],
outdir,
sourcemap: true,
logLevel,
},
// CSS
{
entryPoints: [
'css/style.css',
],
supported: {
nesting: false,
},
bundle: true,
outdir,
logLevel,
},
];
for (const config of configs) {
if (process.argv[2] === '--watch') {
(await esbuild.context(config)).watch();
} else if (process.argv[2] === '--serve') {
const ctx = await esbuild.context(config);
if (config === configs[0])
ctx.serve({ servedir: outdir });
else
ctx.watch();
} else {
esbuild.build(config);
}
}
await installExternalModules();