Add "build-client" and "patch" scripts to package.json
parent
14c94507f3
commit
998ecc3bd4
32
build.js
32
build.js
|
@ -15,6 +15,7 @@ fs.writeFileSync("./build/index.html", fs.readFileSync("./build/index.html").toS
|
||||||
fs.writeFileSync("./build/sw.js", fs.readFileSync("./build/sw.js").toString().replace("buildTimestamp", buildTimestamp));
|
fs.writeFileSync("./build/sw.js", fs.readFileSync("./build/sw.js").toString().replace("buildTimestamp", buildTimestamp));
|
||||||
|
|
||||||
const buildClientCode = () => /** @type {Promise<void>} */(new Promise((resolve, reject) => {
|
const buildClientCode = () => /** @type {Promise<void>} */(new Promise((resolve, reject) => {
|
||||||
|
console.log("Building client code...");
|
||||||
webpack({
|
webpack({
|
||||||
mode: 'production',
|
mode: 'production',
|
||||||
entry: { fxClient: "./src/main.js" },
|
entry: { fxClient: "./src/main.js" },
|
||||||
|
@ -27,16 +28,22 @@ const buildClientCode = () => /** @type {Promise<void>} */(new Promise((resolve,
|
||||||
if (err.details) console.error(err.details);
|
if (err.details) console.error(err.details);
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
const info = stats.toJson();
|
const info = stats?.toJson();
|
||||||
if (stats.hasWarnings()) console.warn(info.warnings);
|
if (stats?.hasWarnings()) console.warn(info?.warnings);
|
||||||
if (stats.hasErrors()) {
|
if (stats?.hasErrors()) {
|
||||||
console.error(info.errors);
|
console.error(info?.errors);
|
||||||
reject("Webpack compilation error");
|
return reject("Webpack compilation error");
|
||||||
}
|
}
|
||||||
else resolve();
|
fs.writeFileSync(
|
||||||
|
"./build/fx.bundle.js",
|
||||||
|
Buffer.concat([fs.readFileSync("./game/build_artefacts.js"), fs.readFileSync("./build/fx.bundle.js")])
|
||||||
|
);
|
||||||
|
resolve();
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
async function patchGameCode() {
|
||||||
|
|
||||||
let script = fs.readFileSync('./game/latest.js', { encoding: 'utf8' }).trim();
|
let script = fs.readFileSync('./game/latest.js', { encoding: 'utf8' }).trim();
|
||||||
|
|
||||||
const exposeVarsToGlobalScope = true;
|
const exposeVarsToGlobalScope = true;
|
||||||
|
@ -55,7 +62,7 @@ script = script.replace(/\bS\[(\d+)\]/g, (_match, index) => `"${stringArray[inde
|
||||||
|
|
||||||
const modUtils = new ModUtils(minifyCode(script));
|
const modUtils = new ModUtils(minifyCode(script));
|
||||||
|
|
||||||
import applyPatches from './patches/main.js';
|
const { default: applyPatches } = await import('./patches/main.js');
|
||||||
console.log("Applying patches...");
|
console.log("Applying patches...");
|
||||||
applyPatches(modUtils);
|
applyPatches(modUtils);
|
||||||
|
|
||||||
|
@ -103,14 +110,10 @@ rawCodeSegments.forEach(code => {
|
||||||
modUtils.executePostMinifyHandlers();
|
modUtils.executePostMinifyHandlers();
|
||||||
script = modUtils.script;
|
script = modUtils.script;
|
||||||
|
|
||||||
console.log("Building client code...")
|
|
||||||
|
|
||||||
await buildClientCode();
|
|
||||||
// the dictionary should maybe get embedded into one of the files in the bundle
|
// the dictionary should maybe get embedded into one of the files in the bundle
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
"./build/fx.bundle.js",
|
"./game/build_artefacts.js",
|
||||||
`const buildTimestamp = "${buildTimestamp}"; const dictionary = ${JSON.stringify(dictionary)};\n`
|
`const buildTimestamp = "${buildTimestamp}"; const dictionary = ${JSON.stringify(dictionary)};\n`
|
||||||
+ fs.readFileSync("./build/fx.bundle.js").toString()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log("Formatting code...");
|
console.log("Formatting code...");
|
||||||
|
@ -138,4 +141,9 @@ script = beautify(script, {
|
||||||
|
|
||||||
fs.writeFileSync("./build/game.js", script);
|
fs.writeFileSync("./build/game.js", script);
|
||||||
console.log("Wrote ./build/game.js");
|
console.log("Wrote ./build/game.js");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!process.argv.includes("--skip-patching")) await patchGameCode();
|
||||||
|
if (!process.argv.includes("--patch-only")) await buildClientCode();
|
||||||
|
|
||||||
console.log("Build done");
|
console.log("Build done");
|
|
@ -6,7 +6,9 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node index.js",
|
"build": "node index.js",
|
||||||
"build-only": "node build.js"
|
"build-only": "node build.js",
|
||||||
|
"build-client": "node build.js --skip-patching",
|
||||||
|
"patch": "node build.js --patch-only"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
Loading…
Reference in New Issue