2018-12-06 19:00:10 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
const semver = require('semver');
|
|
|
|
const minimist = require('minimist');
|
|
|
|
|
2022-10-25 06:44:43 +00:00
|
|
|
const { getElectronVersion } = require('../lib/get-version');
|
2019-06-24 17:18:04 +00:00
|
|
|
const versionUtils = require('./version-utils');
|
2018-12-06 19:00:10 +00:00
|
|
|
|
|
|
|
function parseCommandLine () {
|
|
|
|
let help;
|
|
|
|
const opts = minimist(process.argv.slice(2), {
|
2020-03-20 15:12:18 +00:00
|
|
|
string: ['bump', 'version'],
|
|
|
|
boolean: ['dryRun', 'help'],
|
|
|
|
alias: { version: ['v'] },
|
2018-12-06 19:00:10 +00:00
|
|
|
unknown: arg => { help = true; }
|
|
|
|
});
|
|
|
|
if (help || opts.help || !opts.bump) {
|
|
|
|
console.log(`
|
|
|
|
Bump release version number. Possible arguments:\n
|
|
|
|
--bump=patch to increment patch version\n
|
|
|
|
--version={version} to set version number directly\n
|
|
|
|
--dryRun to print the next version without updating files
|
2023-02-01 11:59:16 +00:00
|
|
|
Note that you can use both --bump and --stable simultaneously.
|
2018-12-06 19:00:10 +00:00
|
|
|
`);
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
return opts;
|
|
|
|
}
|
|
|
|
|
|
|
|
// run the script
|
|
|
|
async function main () {
|
|
|
|
const opts = parseCommandLine();
|
2022-10-25 06:44:43 +00:00
|
|
|
const currentVersion = getElectronVersion();
|
2018-12-06 19:00:10 +00:00
|
|
|
const version = await nextVersion(opts.bump, currentVersion);
|
|
|
|
|
|
|
|
const parsed = semver.parse(version);
|
|
|
|
const components = {
|
|
|
|
major: parsed.major,
|
|
|
|
minor: parsed.minor,
|
|
|
|
patch: parsed.patch,
|
|
|
|
pre: parsed.prerelease
|
|
|
|
};
|
|
|
|
|
|
|
|
// print would-be new version and exit early
|
|
|
|
if (opts.dryRun) {
|
|
|
|
console.log(`new version number would be: ${version}\n`);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`Bumped to version: ${version}`);
|
|
|
|
}
|
|
|
|
|
2021-07-20 00:58:15 +00:00
|
|
|
// get next version for release based on [nightly, alpha, beta, stable]
|
2018-12-06 19:00:10 +00:00
|
|
|
async function nextVersion (bumpType, version) {
|
2021-07-20 00:58:15 +00:00
|
|
|
if (
|
|
|
|
versionUtils.isNightly(version) ||
|
|
|
|
versionUtils.isAlpha(version) ||
|
|
|
|
versionUtils.isBeta(version)
|
|
|
|
) {
|
2018-12-06 19:00:10 +00:00
|
|
|
switch (bumpType) {
|
|
|
|
case 'nightly':
|
2019-06-24 17:18:04 +00:00
|
|
|
version = await versionUtils.nextNightly(version);
|
2018-12-06 19:00:10 +00:00
|
|
|
break;
|
2021-07-20 00:58:15 +00:00
|
|
|
case 'alpha':
|
|
|
|
version = await versionUtils.nextAlpha(version);
|
|
|
|
break;
|
2018-12-06 19:00:10 +00:00
|
|
|
case 'beta':
|
2019-06-24 17:18:04 +00:00
|
|
|
version = await versionUtils.nextBeta(version);
|
2018-12-06 19:00:10 +00:00
|
|
|
break;
|
|
|
|
case 'stable':
|
|
|
|
version = semver.valid(semver.coerce(version));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error('Invalid bump type.');
|
|
|
|
}
|
2019-06-24 17:18:04 +00:00
|
|
|
} else if (versionUtils.isStable(version)) {
|
2018-12-06 19:00:10 +00:00
|
|
|
switch (bumpType) {
|
|
|
|
case 'nightly':
|
2019-06-24 17:18:04 +00:00
|
|
|
version = versionUtils.nextNightly(version);
|
2018-12-06 19:00:10 +00:00
|
|
|
break;
|
2021-07-20 00:58:15 +00:00
|
|
|
case 'alpha':
|
|
|
|
throw new Error('Cannot bump to alpha from stable.');
|
2018-12-06 19:00:10 +00:00
|
|
|
case 'beta':
|
|
|
|
throw new Error('Cannot bump to beta from stable.');
|
2019-10-23 18:07:10 +00:00
|
|
|
case 'minor':
|
|
|
|
version = semver.inc(version, 'minor');
|
|
|
|
break;
|
2018-12-06 19:00:10 +00:00
|
|
|
case 'stable':
|
|
|
|
version = semver.inc(version, 'patch');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error('Invalid bump type.');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new Error(`Invalid current version: ${version}`);
|
|
|
|
}
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
2021-06-02 19:53:23 +00:00
|
|
|
function isMajorStable (bump, currentVersion) {
|
|
|
|
if (versionUtils.isBeta(currentVersion) && (bump === 'stable')) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isMajorNightly (version, currentVersion) {
|
|
|
|
const parsed = semver.parse(version);
|
|
|
|
const current = semver.parse(currentVersion);
|
|
|
|
if (versionUtils.isNightly(currentVersion) && (parsed.major > current.major)) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-06 19:00:10 +00:00
|
|
|
if (process.mainModule === module) {
|
|
|
|
main().catch((error) => {
|
|
|
|
console.error(error);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-25 06:44:43 +00:00
|
|
|
module.exports = { nextVersion };
|