-
Notifications
You must be signed in to change notification settings - Fork 8
/
consoleBuild.cjs
126 lines (111 loc) · 4.07 KB
/
consoleBuild.cjs
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const fs = require("fs");
const path = require("path");
// const requireResolvePlugin = require('@chialab/esbuild-plugin-require-resolve');
// const { resolve } = require('path');
// const tsc = require('tsc-prog');
// rimraf console-build/* && tsc --project ./tsconfig.lambda.json && copyfiles -u 1 src/**/*.wasm console-build
// tsc.build({
// basePath: __dirname,
// configFilePath: 'tsconfig.lambda.json',
// copyOtherToOutDir: true,
// clean: { outDir: true }
// });
// writeFileSync(
// resolve(__dirname, 'console-build/package.json'),
// JSON.stringify(
// {
// // type: 'commonjs',
// main: './lambdaSearch.js'
// // exports: {
// // '.': {
// // require: './lambdaSearch.js' // CJS
// // "import": "./index.mjs" // ESM
// // }
// // }
// },
// null,
// 2
// )
// );
const mkDir = dir => {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
};
["console-build", "console-build/workers", "console-build/noita_random"].forEach(mkDir);
const pkg = require(path.resolve("./package.json"));
const external = [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})];
require("esbuild")
.build({
entryPoints: [
"./src/services/SeedInfo/infoHandler/index.ts",
"./src/consoleSearch.ts",
"./src/workers/seedSearcher.worker.node.ts",
"./src/services/imageActions/nodeImageActions.ts",
],
bundle: true,
loader: { ".wasm": "file", ".node": "copy" },
platform: "node",
metafile: true,
sourcemap: true,
// minify: true,
target: ["node20"],
format: "esm",
banner: {
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`,
},
outdir: "console-build",
packages: "external",
external,
})
.then(() => {
const mainPackageJson = JSON.parse(fs.readFileSync(path.resolve(__dirname, "package.json")));
const searchPackageJson = JSON.parse(fs.readFileSync(path.resolve(__dirname, "search.package.json")));
searchPackageJson.version = mainPackageJson.version;
fs.writeFileSync(
path.resolve(__dirname, "console-build", "package.json"),
JSON.stringify(searchPackageJson, null, 2),
);
{
// Need to figure out how to correctly fix URL requires with esbuild
const fixFile = path.resolve(__dirname, "console-build", "consoleSearch.js");
let f = fs.readFileSync(fixFile, "utf8");
let result = f.replace("../workers/seedSearcher.worker.node.ts", "./workers/seedSearcher.worker.node.js");
fs.writeFileSync(fixFile, result);
}
{
// Need to figure out how to correctly fix URL requires with esbuild
const fixFile = path.resolve(__dirname, "console-build", "workers/seedSearcher.worker.node.js");
let f = fs.readFileSync(fixFile, "utf8");
let result = "" + f;
result = result.replaceAll(`.json";`, `.json"assert{type:"json"};`);
result = result.replaceAll(`__dirname`, `import.meta.url`);
result = result.replaceAll(`__dirname`, `import.meta.url`);
fs.writeFileSync(fixFile, result);
}
{
// Need to figure out how to correctly fix URL requires with esbuild
const fixFile = path.resolve(__dirname, "console-build", "workers/seedSearcher.worker.node.js");
let f = fs.readFileSync(fixFile, "utf8");
let result = f.replace("./nodeImageActions", "../services/imageActions/nodeImageActions.js");
fs.writeFileSync(fixFile, result);
}
{
fs.copyFileSync(
path.resolve(__dirname, "src/services/SeedInfo/noita_random/noita_random.wasm"),
path.resolve(__dirname, "console-build", "noita_random/noita_random.wasm"),
);
}
{
fs.copyFileSync(
path.resolve(__dirname, "src/services/SeedInfo/infoHandler/InfoProviders/Alchemy/Alchemy.wasm"),
path.resolve(__dirname, "console-build", "workers/Alchemy.wasm"),
);
}
{
fs.copyFileSync(
path.resolve(__dirname, "src/services/SeedInfo/infoHandler/InfoProviders/FungalShift/FungalShift.wasm"),
path.resolve(__dirname, "console-build", "workers/FungalShift.wasm"),
);
}
});