-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild.ts
More file actions
100 lines (85 loc) · 2.5 KB
/
build.ts
File metadata and controls
100 lines (85 loc) · 2.5 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
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
import * as Bun from 'bun';
import { existsSync, mkdirSync, writeFileSync } from 'fs';
import { resolve } from 'path';
import { getLatestVersionSoundList } from '@nbw/sounds';
const writeSoundList = async () => {
function writeJSONFile(
dir: string,
fileName: string,
data: Record<string, any> | string[],
) {
const path = resolve(dir, fileName);
const jsonString = JSON.stringify(data, null, 0);
writeFileSync(path, jsonString);
}
const dataDir = resolve(__dirname, '..', 'public', 'data');
const soundListPath = 'soundList.json';
// Try to create the output directory if it doesn't exist
try {
mkdirSync(dataDir, { recursive: true });
} catch (err) {
if (err instanceof Error && err.message.includes('EEXIST')) {
console.log('Sound data files already exist; skipping generation.');
process.exit(0);
}
}
// If the files already exist, exit early
const files = [soundListPath].map((fileName) => resolve(dataDir, fileName));
if (files.every((file) => existsSync(file))) {
console.log('Sound data files already exist; skipping generation.');
process.exit(0);
}
console.log('Generating sound data files...');
// Write list of sounds in the latest MC version to a JSON file
// Filter the list to only include sounds that match the chosen patterns
// (defined in the shared/ module)
getLatestVersionSoundList().then((soundList) => {
writeJSONFile(dataDir, soundListPath, soundList);
});
};
const build = async () => {
await Bun.$`rm -rf dist`;
const optionalRequirePackages = [
'@nestjs/microservices',
'@nestjs/websockets',
'@fastify/static',
];
const result = await Bun.build({
entrypoints: ['./src/main.ts'],
outdir: './dist',
target: 'bun',
minify: false,
sourcemap: 'linked',
external: [
...optionalRequirePackages.filter((pkg) => {
try {
require(pkg);
return false;
} catch (_) {
return true;
}
}),
'@nbw/config',
'@nbw/database',
'@nbw/validation',
'@nbw/song',
'@nbw/sounds',
// @nestjs/swagger → @nestjs/mapped-types requires class-transformer metadata storage; bundler mis-resolves subpaths
'class-transformer',
],
splitting: true,
});
if (!result.success) {
console.log(result.logs[0]);
process.exit(1);
}
console.log('Built successfully!');
};
build()
.then(() => {
writeSoundList();
})
.catch((err) => {
console.error(err);
process.exit(1);
});