2018-12-06 19:00:10 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const { GitProcess } = require('dugite');
|
2021-06-02 19:53:23 +00:00
|
|
|
const { promises: fs } = require('fs');
|
2020-03-20 20:28:31 +00:00
|
|
|
const semver = require('semver');
|
|
|
|
const path = require('path');
|
|
|
|
const minimist = require('minimist');
|
2018-12-06 19:00:10 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const { ELECTRON_DIR } = require('../lib/utils');
|
|
|
|
const versionUtils = require('./version-utils');
|
2021-06-02 19:53:23 +00:00
|
|
|
const supported = path.resolve(ELECTRON_DIR, 'docs', 'tutorial', 'support.md');
|
2019-06-24 17:18:04 +00:00
|
|
|
|
2021-06-02 19:53:23 +00:00
|
|
|
const writeFile = fs.writeFile;
|
|
|
|
const readFile = fs.readFile;
|
2018-12-06 19:00:10 +00:00
|
|
|
|
|
|
|
function parseCommandLine () {
|
2020-03-20 20:28:31 +00:00
|
|
|
let help;
|
2018-12-06 19:00:10 +00:00
|
|
|
const opts = minimist(process.argv.slice(2), {
|
2020-03-20 15:12:18 +00:00
|
|
|
string: ['bump', 'version'],
|
|
|
|
boolean: ['dryRun', 'help'],
|
|
|
|
alias: { version: ['v'] },
|
2020-03-20 20:28:31 +00:00
|
|
|
unknown: arg => { help = true; }
|
|
|
|
});
|
2018-12-06 19:00:10 +00:00
|
|
|
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
|
|
|
|
Note that you can use both --bump and --stable simultaneously.
|
2020-03-20 20:28:31 +00:00
|
|
|
`);
|
|
|
|
process.exit(0);
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
return opts;
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// run the script
|
|
|
|
async function main () {
|
2020-03-20 20:28:31 +00:00
|
|
|
const opts = parseCommandLine();
|
|
|
|
const currentVersion = await versionUtils.getElectronVersion();
|
|
|
|
const version = await nextVersion(opts.bump, currentVersion);
|
2018-12-06 19:00:10 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const parsed = semver.parse(version);
|
2018-12-06 19:00:10 +00:00
|
|
|
const components = {
|
|
|
|
major: parsed.major,
|
|
|
|
minor: parsed.minor,
|
|
|
|
patch: parsed.patch,
|
|
|
|
pre: parsed.prerelease
|
2020-03-20 20:28:31 +00:00
|
|
|
};
|
2018-12-06 19:00:10 +00:00
|
|
|
|
|
|
|
// print would-be new version and exit early
|
|
|
|
if (opts.dryRun) {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(`new version number would be: ${version}\n`);
|
|
|
|
return 0;
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
2021-06-02 19:53:23 +00:00
|
|
|
if (shouldUpdateSupported(opts.bump, currentVersion, version)) {
|
|
|
|
await updateSupported(version, supported);
|
|
|
|
}
|
|
|
|
|
2018-12-06 19:00:10 +00:00
|
|
|
// update all version-related files
|
|
|
|
await Promise.all([
|
|
|
|
updateVersion(version),
|
|
|
|
updatePackageJSON(version),
|
|
|
|
updateWinRC(components)
|
2020-03-20 20:28:31 +00:00
|
|
|
]);
|
2018-12-06 19:00:10 +00:00
|
|
|
|
|
|
|
// commit all updated version-related files
|
2020-03-20 20:28:31 +00:00
|
|
|
await commitVersionBump(version);
|
2018-12-06 19:00:10 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(`Bumped to version: ${version}`);
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
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':
|
2020-03-20 20:28:31 +00:00
|
|
|
version = await versionUtils.nextNightly(version);
|
|
|
|
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':
|
2020-03-20 20:28:31 +00:00
|
|
|
version = await versionUtils.nextBeta(version);
|
|
|
|
break;
|
2018-12-06 19:00:10 +00:00
|
|
|
case 'stable':
|
2020-03-20 20:28:31 +00:00
|
|
|
version = semver.valid(semver.coerce(version));
|
|
|
|
break;
|
2018-12-06 19:00:10 +00:00
|
|
|
default:
|
2020-03-20 20:28:31 +00:00
|
|
|
throw new Error('Invalid bump type.');
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
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':
|
2020-03-20 20:28:31 +00:00
|
|
|
version = versionUtils.nextNightly(version);
|
|
|
|
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':
|
2020-03-20 20:28:31 +00:00
|
|
|
throw new Error('Cannot bump to beta from stable.');
|
2019-10-23 18:07:10 +00:00
|
|
|
case 'minor':
|
2020-03-20 20:28:31 +00:00
|
|
|
version = semver.inc(version, 'minor');
|
|
|
|
break;
|
2018-12-06 19:00:10 +00:00
|
|
|
case 'stable':
|
2020-03-20 20:28:31 +00:00
|
|
|
version = semver.inc(version, 'patch');
|
|
|
|
break;
|
2018-12-06 19:00:10 +00:00
|
|
|
default:
|
2020-03-20 20:28:31 +00:00
|
|
|
throw new Error('Invalid bump type.');
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-20 20:28:31 +00:00
|
|
|
throw new Error(`Invalid current version: ${version}`);
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
return version;
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
2021-06-02 19:53:23 +00:00
|
|
|
function shouldUpdateSupported (bump, current, version) {
|
|
|
|
return isMajorStable(bump, current) || isMajorNightly(version, current);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
// update VERSION file with latest release info
|
|
|
|
async function updateVersion (version) {
|
2020-03-20 20:28:31 +00:00
|
|
|
const versionPath = path.resolve(ELECTRON_DIR, 'ELECTRON_VERSION');
|
|
|
|
await writeFile(versionPath, version, 'utf8');
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// update package metadata files with new version
|
|
|
|
async function updatePackageJSON (version) {
|
2020-03-20 20:28:31 +00:00
|
|
|
const filePath = path.resolve(ELECTRON_DIR, 'package.json');
|
|
|
|
const file = require(filePath);
|
|
|
|
file.version = version;
|
|
|
|
await writeFile(filePath, JSON.stringify(file, null, 2));
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// push bump commit to release branch
|
|
|
|
async function commitVersionBump (version) {
|
2020-03-20 20:28:31 +00:00
|
|
|
const gitArgs = ['commit', '-a', '-m', `Bump v${version}`, '-n'];
|
|
|
|
await GitProcess.exec(gitArgs, ELECTRON_DIR);
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
2020-04-13 21:28:59 +00:00
|
|
|
// updates electron.rc file with new semver values
|
2018-12-06 19:00:10 +00:00
|
|
|
async function updateWinRC (components) {
|
2020-04-13 21:28:59 +00:00
|
|
|
const filePath = path.resolve(ELECTRON_DIR, 'shell', 'browser', 'resources', 'win', 'electron.rc');
|
2020-03-20 20:28:31 +00:00
|
|
|
const data = await readFile(filePath, 'utf8');
|
|
|
|
const arr = data.split('\n');
|
2018-12-06 19:00:10 +00:00
|
|
|
arr.forEach((line, idx) => {
|
|
|
|
if (line.includes('FILEVERSION')) {
|
2020-03-20 20:28:31 +00:00
|
|
|
arr[idx] = ` FILEVERSION ${versionUtils.makeVersion(components, ',', versionUtils.preType.PARTIAL)}`;
|
|
|
|
arr[idx + 1] = ` PRODUCTVERSION ${versionUtils.makeVersion(components, ',', versionUtils.preType.PARTIAL)}`;
|
2018-12-06 19:00:10 +00:00
|
|
|
} else if (line.includes('FileVersion')) {
|
2020-03-20 20:28:31 +00:00
|
|
|
arr[idx] = ` VALUE "FileVersion", "${versionUtils.makeVersion(components, '.')}"`;
|
|
|
|
arr[idx + 5] = ` VALUE "ProductVersion", "${versionUtils.makeVersion(components, '.')}"`;
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
await writeFile(filePath, arr.join('\n'));
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
2021-06-02 19:53:23 +00:00
|
|
|
// updates support.md file with new semver values (stable only)
|
|
|
|
async function updateSupported (version, filePath) {
|
|
|
|
const v = parseInt(version);
|
2021-07-14 22:38:28 +00:00
|
|
|
const newVersions = [`* ${v}.x.y`, `* ${v - 1}.x.y`, `* ${v - 2}.x.y`, `* ${v - 3}`];
|
2021-06-02 19:53:23 +00:00
|
|
|
const contents = await readFile(filePath, 'utf8');
|
|
|
|
const previousVersions = contents.split('\n').filter((elem) => {
|
|
|
|
return (/[^\n]*\.x\.y[^\n]*/).test(elem);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const newContents = previousVersions.reduce((contents, current, i) => {
|
|
|
|
return contents.replace(current, newVersions[i]);
|
|
|
|
}, contents);
|
|
|
|
|
|
|
|
await writeFile(filePath, newContents, 'utf8');
|
|
|
|
}
|
|
|
|
|
2018-12-06 19:00:10 +00:00
|
|
|
if (process.mainModule === module) {
|
|
|
|
main().catch((error) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.error(error);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
2021-06-02 19:53:23 +00:00
|
|
|
module.exports = { nextVersion, shouldUpdateSupported, updateSupported };
|