-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-sandstone.ts
executable file
·71 lines (71 loc) · 1.65 KB
/
build-sandstone.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
60
61
62
63
64
65
66
67
68
69
70
71
import { mkdirSync, readdirSync, writeFileSync } from "fs";
import { resolve } from "path";
import { build } from "esbuild";
const shims = readdirSync("./web-shim");
// TODO: Env
const env = {
PROJECT_FOLDERS: JSON.stringify({
absProjectFolder: "/",
projectFolder: "/src",
rootFolder: "/",
sandstoneConfigFolder: "/",
}),
CLI_OPTIONS: JSON.stringify({}),
WORKING_DIR: "/",
PACK_OPTIONS: JSON.stringify({
datapack: {
description: ["A ", { text: "Sandstone", color: "gold" }, " datapack."],
packFormat: 19,
},
resourcepack: {
description: [
"A ",
{ text: "Sandstone", color: "gold" },
" resource pack.",
],
packFormat: 18,
},
}),
};
export const sandstoneBuild = build({
entryPoints: ["sandstone"],
bundle: true,
outfile: "./src/assets/sandstone.esm.js",
platform: "browser",
plugins: [
{
name: "shim",
setup(plugin) {
plugin.onResolve({ filter: new RegExp(shims.join("|")) }, (args) => ({
path: resolve(__dirname, `./web-shim/${args.path}/index.mjs`),
}));
},
},
],
banner: {
js:
"(()=>{globalThis.process||={};globalThis.process.env = " +
JSON.stringify(env) +
"})();",
},
external: [
"node-fetch",
"fs-extra",
"path",
"crypto",
"fs",
"zlib",
"adm-zip",
"prismarine-nbt",
],
metafile: true,
format: "esm",
minify: true,
}).then((data) => {
const exports = Object.values(data.metafile.outputs)[0].exports;
mkdirSync('./dist', { recursive: true })
writeFileSync(
"./dist/exports.js",
"export const exports = " + JSON.stringify(exports) + ";"
);
});