chore(pdfjs): copy locales during build

This commit is contained in:
Elian Doran 2025-12-29 19:07:37 +02:00
parent 6e41d3591d
commit 07a1734d4b
No known key found for this signature in database
5 changed files with 44 additions and 3 deletions

View File

@ -6,6 +6,9 @@
"build": "tsx scripts/build.ts"
},
"dependencies": {
"@triliumnext/commons": "workspace:*"
},
"devDependencies": {
"pdfjs-dist": "5.4.530"
}
}

View File

@ -1,13 +1,37 @@
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() {
build.copy("viewer", "web");
// 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");
}

View File

@ -22,5 +22,8 @@
"eslint.config.mjs"
],
"references": [
{
"path": "../commons/tsconfig.app.json"
}
]
}

6
pnpm-lock.yaml generated
View File

@ -1375,6 +1375,10 @@ importers:
packages/pdfjs-viewer:
dependencies:
'@triliumnext/commons':
specifier: workspace:*
version: link:../commons
devDependencies:
pdfjs-dist:
specifier: 5.4.530
version: 5.4.530
@ -16044,8 +16048,6 @@ snapshots:
'@ckeditor/ckeditor5-ui': 47.3.0
'@ckeditor/ckeditor5-utils': 47.3.0
ckeditor5: 47.3.0
transitivePeerDependencies:
- supports-color
'@ckeditor/ckeditor5-restricted-editing@47.3.0':
dependencies:

View File

@ -87,6 +87,15 @@ export default class BuildHelper {
}
}
writeJson(relativePath: string, data: any) {
const fullPath = join(this.outDir, relativePath);
const dirPath = fullPath.substring(0, fullPath.lastIndexOf("/"));
if (dirPath) {
mkdirpSync(dirPath);
}
writeFileSync(fullPath, JSON.stringify(data, null, 4), "utf-8");
}
}
function tryPath(paths: string[]) {