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
|
|
|
|
|
|
|
async function main() {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ver = asar.extractFile('webapp.asar', 'version').toString().trim();
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2019-12-13 11:45:27 +01:00
|
|
|
|
|
|
|
// Also create a debian package control file with the version.
|
|
|
|
// We use a custom control file so we need to do this ourselves
|
|
|
|
const outFile = await fs.open('pkg/control', 'w');
|
|
|
|
const template = await fs.readFile('pkg/control.template');
|
|
|
|
await outFile.write(template);
|
|
|
|
await outFile.write('Version: ' + ver + "\n");
|
|
|
|
await outFile.close();
|
|
|
|
|
2019-12-12 20:33:29 +01:00
|
|
|
console.log("Version set to " + ver);
|
|
|
|
}
|
|
|
|
|
|
|
|
main().then((ret) => process.exit(ret));
|