mirror of
https://github.com/zadam/trilium.git
synced 2026-02-18 19:54:26 +01:00
chore(pdfjs): use version-based system for cache busting
This commit is contained in:
parent
757fc7a7fe
commit
971d6ad9e3
@ -3,6 +3,8 @@ import BuildHelper from "../../../scripts/build-utils";
|
||||
import { build as esbuild } from "esbuild";
|
||||
import { LOCALES } from "@triliumnext/commons";
|
||||
import { watch } from "chokidar";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import packageJson from "../package.json" with { type: "json "};
|
||||
|
||||
const build = new BuildHelper("packages/pdfjs-viewer");
|
||||
const watchMode = process.argv.includes("--watch");
|
||||
@ -16,6 +18,7 @@ async function main() {
|
||||
for (const file of [ "viewer.css", "viewer.html", "viewer.mjs" ]) {
|
||||
build.copy(`viewer/${file}`, `web/${file}`);
|
||||
}
|
||||
patchCacheBuster(`${build.outDir}/web/viewer.html`);
|
||||
build.copy(`viewer/images`, `web/images`);
|
||||
|
||||
// Copy the custom files.
|
||||
@ -60,6 +63,21 @@ async function rebuildCustomFiles() {
|
||||
build.copy("src/custom.css", "web/custom.css");
|
||||
}
|
||||
|
||||
function patchCacheBuster(htmlFilePath: string) {
|
||||
const version = packageJson.version;
|
||||
console.log(`Versioned URLs: ${version}.`)
|
||||
let html = readFileSync(htmlFilePath, "utf-8");
|
||||
html = html.replace(
|
||||
`<link rel="stylesheet" href="custom.css" />`,
|
||||
`<link rel="stylesheet" href="custom.css?v=${version}" />`);
|
||||
html = html.replace(
|
||||
`<script src="custom.mjs" type="module"></script>` ,
|
||||
`<script src="custom.mjs?v=${version}" type="module"></script>`
|
||||
);
|
||||
|
||||
writeFileSync(htmlFilePath, html);
|
||||
}
|
||||
|
||||
function watchForChanges() {
|
||||
console.log("Watching for changes in src directory...");
|
||||
const watcher = watch(join(build.projectDir, "src"), {
|
||||
|
||||
@ -11,9 +11,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
import { fileURLToPath } from "url";
|
||||
import { dirname, join } from "path";
|
||||
import fs from "fs";
|
||||
import { dirname, join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
function processVersion(version) {
|
||||
// Remove the beta suffix if any.
|
||||
@ -42,14 +42,19 @@ function patchPackageJson(packageJsonPath) {
|
||||
|
||||
function main() {
|
||||
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
|
||||
const rootPackageJson = join(scriptDir, "..", "package.json");
|
||||
patchPackageJson(rootPackageJson);
|
||||
|
||||
|
||||
for (const app of ["server", "client"]) {
|
||||
const appPackageJsonPath = join(scriptDir, "..", "apps", app, "package.json");
|
||||
patchPackageJson(appPackageJsonPath);
|
||||
}
|
||||
|
||||
for (const packageName of [ "pdfjs-viewer" ]) {
|
||||
const packageJsonPath = join(scriptDir, "..", "packages", packageName, "package.json");
|
||||
patchPackageJson(packageJsonPath);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user