Improve use of Typescript (#474)
* Switch out needle with node-fetch * Iterate * Update asar package and switch to canonical name * Use ts-node for scripts * Iterate * Update yarn.lock * Use node:stream.promises * Remove logfile * Fix types * Fix types
This commit is contained in:
committed by
GitHub
parent
b52787a49e
commit
56370de568
58
scripts/set-version.ts
Executable file
58
scripts/set-version.ts
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env -S npx ts-node
|
||||
|
||||
/*
|
||||
* 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 "fs";
|
||||
import * as asar from "asar";
|
||||
import * as childProcess from "child_process";
|
||||
|
||||
export async function versionFromAsar(): Promise<string> {
|
||||
try {
|
||||
await fs.stat('webapp.asar');
|
||||
} catch (e) {
|
||||
throw new Error("No 'webapp.asar' found. Run 'yarn 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' ? 'yarn.cmd' : 'yarn', [
|
||||
'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();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function main(args: string[]): Promise<number> {
|
||||
let version = args[0];
|
||||
|
||||
if (version === undefined) version = await versionFromAsar();
|
||||
|
||||
await setPackageVersion(version);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main(process.argv.slice(2)).then((ret) => {
|
||||
process.exit(ret);
|
||||
}).catch(e => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user