2025-12-29 19:09:03 +02:00

52 lines
1.7 KiB
TypeScript

import { join } from "path";
import BuildHelper from "../../../scripts/build-utils";
import { build as esbuild } from "esbuild";
import { LOCALES } from "@triliumnext/commons";
const build = new BuildHelper("packages/pdfjs-viewer");
const LOCALE_MAPPINGS: Record<string, string> = {
"es": "es-ES"
};
async function main() {
// Copy the viewer files.
for (const file of [ "viewer.css", "viewer.html", "viewer.mjs" ]) {
build.copy(`viewer/${file}`, `web/${file}`);
}
build.copy(`viewer/images`, `web/images`);
// Copy the custom files.
await buildScript("web/custom.mjs");
build.copy("src/custom.css", "web/custom.css");
// Copy locales.
const localeMappings = {};
for (const locale of LOCALES) {
if (locale.id === "en" || locale.contentOnly || locale.devOnly) continue;
const mappedLocale = LOCALE_MAPPINGS[locale.electronLocale] || locale.electronLocale.replace("_", "-");
const localePath = `${locale.id}/viewer.ftl`;
build.copy(`viewer/locale/${mappedLocale}/viewer.ftl`, `web/locale/${localePath}`);
localeMappings[locale.id] = localePath;
}
build.writeJson("web/locale/locale.json", localeMappings);
// Copy pdfjs-dist files.
build.copy("/node_modules/pdfjs-dist/build/pdf.mjs", "build/pdf.mjs");
build.copy("/node_modules/pdfjs-dist/build/pdf.worker.mjs", "build/pdf.worker.mjs");
}
async function buildScript(outPath: string) {
await esbuild({
entryPoints: [join(build.projectDir, "src/custom.ts")],
tsconfig: join(build.projectDir, "tsconfig.app.json"),
bundle: true,
outfile: join(build.outDir, outPath),
format: "esm",
platform: "browser",
minify: true,
});
}
main();