2022-12-05 12:50:49 +01:00
|
|
|
#!/usr/bin/env -S npx ts-node
|
2019-12-12 20:33:29 +01:00
|
|
|
|
|
|
|
/*
|
2020-02-04 23:19:28 +01:00
|
|
|
* Checks for the presence of a webapp, inspects its version and sets the
|
2019-12-12 20:33:29 +01:00
|
|
|
* version metadata of the package to match.
|
|
|
|
*/
|
|
|
|
|
2022-12-05 12:50:49 +01:00
|
|
|
import { promises as fs } from "fs";
|
|
|
|
import * as asar from "asar";
|
|
|
|
import * as childProcess from "child_process";
|
2019-12-12 20:33:29 +01:00
|
|
|
|
2022-12-05 12:50:49 +01:00
|
|
|
export async function versionFromAsar(): Promise<string> {
|
2019-12-12 20:33:29 +01:00
|
|
|
try {
|
2020-02-17 15:49:26 +01:00
|
|
|
await fs.stat('webapp.asar');
|
2019-12-12 20:33:29 +01:00
|
|
|
} catch (e) {
|
2022-12-05 12:50:49 +01:00
|
|
|
throw new Error("No 'webapp.asar' found. Run 'yarn run fetch'");
|
2019-12-12 20:33:29 +01:00
|
|
|
}
|
|
|
|
|
2020-02-26 12:56:59 +01:00
|
|
|
return asar.extractFile('webapp.asar', 'version').toString().trim();
|
|
|
|
}
|
2019-12-13 11:45:27 +01:00
|
|
|
|
2022-12-05 12:50:49 +01:00
|
|
|
export async function setPackageVersion(ver: string): Promise<void> {
|
2019-12-13 11:45:27 +01:00
|
|
|
// set version in package.json: electron-builder will use this to populate
|
|
|
|
// all the various version fields
|
2022-12-05 12:50:49 +01:00
|
|
|
await new Promise<void>((resolve, reject) => {
|
2020-02-19 15:34:27 +01:00
|
|
|
childProcess.execFile(process.platform === 'win32' ? 'yarn.cmd' : 'yarn', [
|
2019-12-12 20:33:29 +01:00
|
|
|
'version',
|
|
|
|
'-s',
|
|
|
|
'--no-git-tag-version', // This also means "don't commit to git" as it turns out
|
|
|
|
'--new-version',
|
|
|
|
ver,
|
|
|
|
], (err) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
} else {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2020-02-26 12:56:59 +01:00
|
|
|
}
|
2019-12-13 11:45:27 +01:00
|
|
|
|
2022-12-05 12:50:49 +01:00
|
|
|
async function main(args: string[]): Promise<number> {
|
2020-03-07 17:12:59 +01:00
|
|
|
let version = args[0];
|
2020-02-26 12:56:59 +01:00
|
|
|
|
|
|
|
if (version === undefined) version = await versionFromAsar();
|
|
|
|
|
2020-03-07 17:12:59 +01:00
|
|
|
await setPackageVersion(version);
|
2022-12-05 12:50:49 +01:00
|
|
|
return 0;
|
2020-02-26 12:56:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (require.main === module) {
|
2022-12-05 12:50:49 +01:00
|
|
|
main(process.argv.slice(2)).then((ret) => {
|
|
|
|
process.exit(ret);
|
|
|
|
}).catch(e => {
|
|
|
|
console.error(e);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2020-02-26 12:56:59 +01:00
|
|
|
}
|