2024-05-04 19:19:58 +02:00
|
|
|
import fs from "node:fs/promises";
|
2024-05-05 14:04:20 +02:00
|
|
|
import path, { join } from "node:path";
|
|
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
|
|
|
|
const repositoryRootDir = join(path.dirname(fileURLToPath(import.meta.url)), "../");
|
|
|
|
const file = (relativePath) => join(repositoryRootDir, relativePath);
|
2024-05-04 19:19:58 +02:00
|
|
|
|
|
|
|
await (async () => {
|
2024-05-05 14:04:20 +02:00
|
|
|
await fs.rm(file("built/_client_dist_/locales"), { recursive: true, force: true });
|
2024-05-04 19:19:58 +02:00
|
|
|
await Promise.all([
|
2024-05-05 14:04:20 +02:00
|
|
|
fs.cp(file("packages/backend/src/server/web"), file("packages/backend/built/server/web"), { recursive: true }),
|
|
|
|
fs.cp(file("custom/assets"), file("packages/backend/assets"), { recursive: true }),
|
|
|
|
fs.cp(file("packages/client/node_modules/three/examples/fonts"), file("built/_client_dist_/fonts"), { recursive: true }),
|
|
|
|
fs.mkdir(file("built/_client_dist_/locales"), { recursive: true }),
|
2024-05-04 19:19:58 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
const locales = (await import("../locales/index.mjs")).default;
|
|
|
|
const meta = (await import("../built/meta.json", { assert: { type: "json" } })).default;
|
|
|
|
|
|
|
|
for await (const [lang, locale] of Object.entries(locales)) {
|
|
|
|
await fs.writeFile(
|
2024-05-05 14:04:20 +02:00
|
|
|
file(`built/_client_dist_/locales/${lang}.${meta.version}.json`),
|
2024-05-04 19:19:58 +02:00
|
|
|
JSON.stringify({ ...locale, _version_: meta.version }),
|
|
|
|
"utf-8",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const js_assets = [
|
2024-05-05 14:04:20 +02:00
|
|
|
file("packages/backend/built/server/web/boot.js"),
|
|
|
|
file("packages/backend/built/server/web/bios.js"),
|
|
|
|
file("packages/backend/built/server/web/cli.js"),
|
2024-05-04 19:19:58 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
for await (const js_file of js_assets) {
|
|
|
|
const content = (await fs.readFile(js_file, "utf-8"))
|
|
|
|
.replace("SUPPORTED_LANGS", JSON.stringify(Object.keys(locales)));
|
|
|
|
await fs.writeFile(js_file, content, "utf-8");
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO?: minify packages/backend/built/server/web/*.css
|
|
|
|
})();
|