2019-12-12 20:33:29 +01:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
/*
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const fs = require('fs').promises;
|
|
|
|
const asar = require('asar');
|
2020-02-17 15:49:26 +01:00
|
|
|
const childProcess = require('child_process');
|
2019-12-12 20:33:29 +01:00
|
|
|
|
2020-02-26 12:56:59 +01:00
|
|
|
async function versionFromAsar() {
|
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) {
|
|
|
|
console.log("No 'webapp.asar' found. Run 'yarn run fetch'");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-02-26 12:56:59 +01:00
|
|
|
return asar.extractFile('webapp.asar', 'version').toString().trim();
|
|
|
|
}
|
2019-12-13 11:45:27 +01:00
|
|
|
|
2020-02-26 12:56:59 +01:00
|
|
|
async function setPackageVersion(ver) {
|
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
|
2019-12-12 20:33:29 +01:00
|
|
|
await new Promise((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
|
|
|
|
2020-02-26 12:56:59 +01:00
|
|
|
async function main(args) {
|
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);
|
2020-02-26 12:56:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
main(process.argv.slice(2)).then((ret) => process.exit(ret));
|
|
|
|
}
|
|
|
|
|
2021-05-27 15:39:26 +02:00
|
|
|
module.exports = { versionFromAsar, setPackageVersion };
|