ruffle/web/packages/core/tools/bundle_texts.ts

44 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-06-08 22:12:50 +00:00
import replace from "replace-in-file";
import fs from "fs";
2023-05-02 01:57:38 +00:00
2024-06-08 22:12:50 +00:00
const bundledTexts: { [name: string]: { [key: string]: string } } = {};
const locales: string[] = [];
2023-05-02 01:57:38 +00:00
fs.readdirSync("texts", { withFileTypes: true }).forEach((entry) => {
if (entry.isDirectory()) {
locales.push(entry.name);
}
});
// For build reproducibility, sort the locales to make sure we don't accidentally rearrange them on different machines.
// The actual order isn't important, just that it's the same.
locales.sort();
locales.forEach((locale) => {
2024-06-08 22:12:50 +00:00
const files: string[] = [];
2023-05-02 01:57:38 +00:00
fs.readdirSync("texts/" + locale, { withFileTypes: true }).forEach(
(entry) => {
if (entry.isFile() && entry.name.endsWith(".ftl")) {
files.push(entry.name);
}
2023-07-20 11:19:39 +00:00
},
2023-05-02 01:57:38 +00:00
);
files.sort();
if (files.length > 0) {
2023-05-30 20:24:43 +00:00
bundledTexts[locale] = {};
2023-05-02 01:57:38 +00:00
files.forEach((filename) => {
2024-06-08 22:12:50 +00:00
bundledTexts[locale]![filename] = fs
2023-05-02 01:57:38 +00:00
.readFileSync("texts/" + locale + "/" + filename, "utf8")
.replaceAll("\r\n", "\n");
});
}
});
const options = {
files: "dist/**",
from: [/\{\s*\/\*\s*%BUNDLED_TEXTS%\s*\*\/\s*}/g],
2023-05-30 20:24:43 +00:00
to: [JSON.stringify(bundledTexts, null, 2)],
2023-05-02 01:57:38 +00:00
};
replace.sync(options);