-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-lang.ts
59 lines (53 loc) · 1.42 KB
/
build-lang.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
/**
* Builds a TypeScript file to a directory.
* @param filePath The file path.
* @param outputDir Directory to output the compiled file.
* @param minify Whether or not to minify the compiled output. Useful for debugging.
* @returns void
*/
export async function compile(
filePath: string,
outputDir: string
): Promise<any> {
let output = (await Bun.build({
entrypoints: [filePath],
outdir: outputDir,
splitting: true,
emitDCEAnnotations: true,
minify: {
identifiers: true,
syntax: true,
whitespace: true,
},
}).catch((e) => {
console.error("Failed to build:", e);
})) as BuildOutput;
if (output.logs) {
for (const log of output.logs) {
console.error(log.message);
}
}
}
import { join } from "path";
import { watch } from "fs";
import { Glob, type BuildOutput } from "bun";
async function build() {
const glob = new Glob("*.{ts,tsx}");
const scannedFiles = await Array.fromAsync(
glob.scan({ cwd: "./src/l10n/lang" })
);
scannedFiles.forEach((s) => {
compile("./src/l10n/lang/" + s, "./public/dist/lang/");
});
console.log("Built", scannedFiles.length, "languages.");
}
const watcher = watch(
join(import.meta.dir, "./src"),
{ recursive: true },
async (event, filename) => {
console.log(`Detected ${event} in ${filename}`);
build();
}
);
console.log("Watching!");
build();