Files
Trilium/scripts/update-nightly-version.ts
Elian Doran da7a61a8b6 Merge remote-tracking branch 'origin/main' into HEAD
; Conflicts:
;	apps/client/src/index.ts
;	apps/client/src/widgets/sql_table_schemas.tsx
;	apps/server/package.json
;	apps/server/src/app.ts
;	apps/server/src/becca/entities/bnote.ts
;	apps/server/src/services/import/single.ts
;	apps/server/src/services/import/zip.ts
;	apps/server/src/services/note-interface.ts
;	apps/server/src/services/notes.ts
;	apps/server/src/services/tree.ts
;	apps/server/src/services/utils.ts
;	apps/server/src/share/shaca/entities/snote.ts
;	pnpm-lock.yaml
;	scripts/update-nightly-version.ts
;	scripts/update-version.ts
2026-01-29 21:47:06 +02:00

61 lines
2.2 KiB
TypeScript

/**
* @module
*
* The nightly version works uses the version described in `package.json`, just like any release.
* The problem with this approach is that production builds have a very aggressive cache, and
* usually running the nightly with this cached version of the application will mean that the
* user might run into module not found errors or styling errors caused by an old cache.
*
* This script is supposed to be run in the CI, which will update locally the version field of
* `package.json` to contain the date. For example, `0.90.9-beta` will become `0.90.9-test-YYMMDD-HHMMSS`.
*
*/
import fs from "fs";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
function processVersion(version) {
// Remove the beta suffix if any.
version = version.replace("-beta", "");
// Add the nightly suffix, plus the date.
const referenceDate = new Date().toISOString().substring(2, 19).replace(/[-:]*/g, "").replace("T", "-");
version = `${version}-test-${referenceDate}`;
return version;
}
function patchPackageJson(packageJsonPath) {
// Read the version from package.json and process it.
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
const currentVersion = packageJson.version.split("-test-")[0];
const adjustedVersion = processVersion(currentVersion);
console.log("Current version is", currentVersion);
console.log("Adjusted version is", adjustedVersion);
// Write the adjusted version back in.
packageJson.version = adjustedVersion;
const formattedJson = JSON.stringify(packageJson, null, 4);
fs.writeFileSync(packageJsonPath, formattedJson);
}
function main() {
const scriptDir = dirname(fileURLToPath(import.meta.url));
const rootPackageJson = join(scriptDir, "..", "package.json");
patchPackageJson(rootPackageJson);
for (const app of ["server", "client", "client-standalone", "desktop"]) {
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();