2021-05-17 16:43:53 +03:00
|
|
|
/**
|
2022-01-18 11:18:10 +03:00
|
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
2021-05-17 16:43:53 +03:00
|
|
|
*/
|
2021-06-10 19:17:12 +03:00
|
|
|
import * as fse from "fs-extra";
|
2021-04-26 16:42:59 +03:00
|
|
|
import * as path from "path";
|
|
|
|
import appInfo from "../package.json";
|
|
|
|
import semver from "semver";
|
2021-06-07 08:30:37 +03:00
|
|
|
import fastGlob from "fast-glob";
|
2021-04-26 16:42:59 +03:00
|
|
|
|
|
|
|
const packagePath = path.join(__dirname, "../package.json");
|
|
|
|
const versionInfo = semver.parse(appInfo.version);
|
2021-06-10 19:17:12 +03:00
|
|
|
const buildNumber = process.env.BUILD_NUMBER || Date.now().toString();
|
|
|
|
|
|
|
|
function getBuildChannel(): string {
|
2021-09-09 09:30:41 +03:00
|
|
|
const preRelease = versionInfo.prerelease?.[0];
|
|
|
|
|
|
|
|
switch (preRelease) {
|
|
|
|
case "alpha":
|
2021-06-10 19:17:12 +03:00
|
|
|
case "beta":
|
2021-09-09 09:30:41 +03:00
|
|
|
case "rc":
|
|
|
|
return preRelease;
|
2021-07-05 23:17:35 +03:00
|
|
|
case undefined:
|
2021-11-30 18:30:42 +03:00
|
|
|
case "latest":
|
2021-09-09 09:30:41 +03:00
|
|
|
return "latest"; // needed because electron-updater does not take build information into account when resolving if update is available
|
2021-06-10 19:17:12 +03:00
|
|
|
default:
|
2021-09-09 09:30:41 +03:00
|
|
|
throw new Error(`invalid pre-release ${preRelease}`);
|
2021-04-26 16:42:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-10 19:17:12 +03:00
|
|
|
async function writeOutExtensionVersion(manifestPath: string) {
|
|
|
|
const extensionPackageJson = await fse.readJson(manifestPath);
|
|
|
|
|
2021-06-15 21:14:03 +03:00
|
|
|
extensionPackageJson.version = appInfo.version;
|
2021-04-26 16:42:59 +03:00
|
|
|
|
2021-06-10 19:17:12 +03:00
|
|
|
return fse.writeJson(manifestPath, extensionPackageJson, {
|
|
|
|
spaces: 2,
|
|
|
|
});
|
|
|
|
}
|
2021-06-07 08:30:37 +03:00
|
|
|
|
2021-06-10 19:17:12 +03:00
|
|
|
async function writeOutNewVersions() {
|
|
|
|
await Promise.all([
|
|
|
|
fse.writeJson(packagePath, appInfo, {
|
|
|
|
spaces: 2,
|
|
|
|
}),
|
|
|
|
...(await fastGlob(["extensions/*/package.json"])).map(writeOutExtensionVersion),
|
|
|
|
]);
|
|
|
|
}
|
2021-06-07 08:30:37 +03:00
|
|
|
|
2021-06-10 19:17:12 +03:00
|
|
|
function main() {
|
2021-07-05 23:17:35 +03:00
|
|
|
const prereleaseParts: string[] = [getBuildChannel()];
|
2021-07-05 10:57:49 +03:00
|
|
|
|
2021-07-05 23:17:35 +03:00
|
|
|
if (versionInfo.prerelease && versionInfo.prerelease.length > 1) {
|
2021-06-10 19:17:12 +03:00
|
|
|
prereleaseParts.push(versionInfo.prerelease[1].toString());
|
|
|
|
}
|
|
|
|
|
2021-07-05 23:17:35 +03:00
|
|
|
prereleaseParts.push(buildNumber);
|
|
|
|
|
|
|
|
appInfo.version = `${versionInfo.major}.${versionInfo.minor}.${versionInfo.patch}-${prereleaseParts.join(".")}`;
|
|
|
|
|
2021-06-10 19:17:12 +03:00
|
|
|
writeOutNewVersions()
|
|
|
|
.catch((error) => {
|
|
|
|
console.error(error);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2021-06-07 08:30:37 +03:00
|
|
|
}
|
2021-06-10 19:17:12 +03:00
|
|
|
|
|
|
|
main();
|