* Fix type imports * Fix jsdoc * Fixup types * Fix stray awaits on non-thenables * Fixup imports * Fix splats * Fix this-context on callbacks * Memoise react contexts * Prefer find/flatMap * Make oxlint happier about our React keys * Avoid unsafe default function params * Fixup jsdoc * Fixup contexts * Switch from eslint to oxlint * Some oxlint-related tweaks * Iterate * Partial revert to defer some changes and shrink diff * Iterate * Add eslint-plugin-element-call and enable the copyright rule * Set strictStorePkgContentCheck * Iterate * Make sonar happy * Fix new lints
80 lines
2.3 KiB
JavaScript
Executable File
80 lines
2.3 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/*
|
|
Copyright 2026 Element Creations Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
/*
|
|
* Checks for the presence of a webapp, inspects its version and sets the
|
|
* version metadata of the package to match.
|
|
*/
|
|
|
|
import { promises as fs } from "node:fs";
|
|
import * as asar from "@electron/asar";
|
|
import * as childProcess from "node:child_process";
|
|
import * as url from "node:url";
|
|
|
|
export async function versionFromAsar(): Promise<string> {
|
|
try {
|
|
await fs.stat("webapp.asar");
|
|
} catch {
|
|
throw new Error("No 'webapp.asar' found. Run 'pnpm run fetch'");
|
|
}
|
|
|
|
return asar.extractFile("webapp.asar", "version").toString().trim();
|
|
}
|
|
|
|
export async function setPackageVersion(ver: string): Promise<void> {
|
|
// set version in package.json: electron-builder will use this to populate
|
|
// all the various version fields
|
|
await new Promise<void>((resolve, reject) => {
|
|
childProcess.execFile(
|
|
process.platform === "win32" ? "pnpm.cmd" : "pnpm",
|
|
[
|
|
"version",
|
|
"-s",
|
|
"--no-git-tag-version", // This also means "don't commit to git" as it turns out
|
|
"--new-version",
|
|
ver,
|
|
],
|
|
{
|
|
// We need shell mode on Windows to be able to launch `.cmd` executables
|
|
// See https://nodejs.org/en/blog/vulnerability/april-2024-security-releases-2
|
|
shell: process.platform === "win32",
|
|
},
|
|
(err) => {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve();
|
|
}
|
|
},
|
|
);
|
|
});
|
|
}
|
|
|
|
async function main(args: string[]): Promise<number> {
|
|
let version = args[0];
|
|
|
|
if (version === undefined) version = await versionFromAsar();
|
|
|
|
await setPackageVersion(version);
|
|
return 0;
|
|
}
|
|
|
|
if (import.meta.url.startsWith("file:")) {
|
|
const modulePath = url.fileURLToPath(import.meta.url);
|
|
if (process.argv[1] === modulePath) {
|
|
main(process.argv.slice(2))
|
|
.then((ret) => {
|
|
process.exit(ret);
|
|
})
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|
|
}
|
|
}
|