forked from LostCityRS/Client-TS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.ts
More file actions
73 lines (57 loc) · 2.24 KB
/
bundle.ts
File metadata and controls
73 lines (57 loc) · 2.24 KB
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
import fs from 'fs';
import path from 'path';
const define = {
'process.env.SECURE_ORIGIN': JSON.stringify(process.env.SECURE_ORIGIN ?? 'false'),
// original key, used 2003-2010
'process.env.LOGIN_RSAE': JSON.stringify(process.env.LOGIN_RSAE ?? '58778699976184461502525193738213253649000149147835990136706041084440742975821'),
'process.env.LOGIN_RSAN': JSON.stringify(process.env.LOGIN_RSAN ?? '7162900525229798032761816791230527296329313291232324290237849263501208207972894053929065636522363163621000728841182238772712427862772219676577293600221789'),
'process.env.DEV_CLIENT': JSON.stringify(process.env.DEV_CLIENT ?? 'false'),
};
// ----
type BunOutput = {
source: string;
sourcemap: string;
}
async function bunBuild(entry: string, external: string[] = [], minify = true, drop: string[] = []): Promise<BunOutput> {
const build = await Bun.build({
entrypoints: [entry],
sourcemap: 'external',
define,
external,
minify,
drop,
});
if (!build.success) {
build.logs.forEach(x => console.log(x));
process.exit(1);
}
return {
source: await build.outputs[0].text(),
sourcemap: build.outputs[0].sourcemap ? await build.outputs[0].sourcemap.text() : ''
};
}
// todo: workaround due to a bun bug https://github.com/oven-sh/bun/issues/16509: not remapping external
function replaceDepsUrl(source: string) {
return source.replaceAll('#3rdparty', '.');
}
// ----
if (!fs.existsSync('out')) {
fs.mkdirSync('out');
}
fs.copyFileSync('src/3rdparty/bzip2-wasm/bzip2.wasm', 'out/bzip2.wasm');
fs.copyFileSync('src/3rdparty/tinymidipcm/tinymidipcm.wasm', 'out/tinymidipcm.wasm');
const args = process.argv.slice(2);
const prod = args[0] !== 'dev';
const entrypoints = [
'src/client/Client.ts',
'src/mapview/MapView.ts'
];
const deps = await bunBuild('./src/3rdparty/deps.js', [], true, ['console']);
fs.writeFileSync('out/deps.js', deps.source);
for (const file of entrypoints) {
const output = path.basename(file).replace('.ts', '.js').toLowerCase();
const script = await bunBuild(file, ['#3rdparty/*'], prod, prod ? ['console'] : []);
if (script) {
fs.writeFileSync('out/' + output, replaceDepsUrl(script.source));
}
}