Parcourir la source

Adds release prep script

main
Eric Amodio il y a 1 an
Parent
révision
e0a0136ad2
2 fichiers modifiés avec 77 ajouts et 0 suppressions
  1. +1
    -0
      package.json
  2. +76
    -0
      scripts/prep-release.js

+ 1
- 0
package.json Voir le fichier

@ -14686,6 +14686,7 @@
"package": "vsce package --yarn",
"package-pre": "yarn run patch-pre && yarn run package --pre-release",
"patch-pre": "node ./scripts/applyPreReleasePatch.js",
"prep-release": "node ./scripts/prep-release.js",
"pretty": "prettier --config .prettierrc --log-level warn --write .",
"pub": "vsce publish --yarn",
"pub-pre": "vsce publish --yarn --pre-release",

+ 76
- 0
scripts/prep-release.js Voir le fichier

@ -0,0 +1,76 @@
const { exec } = require('child_process');
const fs = require('fs');
const readline = require('readline');
const path = require('path');
const versionRegex = /^\d{1,4}\.\d{1,4}\.\d{1,4}$/;
const changelogPath = path.join(__dirname, '..', 'CHANGELOG.md');
console.log(changelogPath);
let data = fs.readFileSync(changelogPath, 'utf8');
// Find the current version number
const match = /\[unreleased\]: https:\/\/github\.com\/gitkraken\/vscode-gitlens\/compare\/v(.+)\.\.\.HEAD/.exec(data);
const currentVersion = match?.[1];
if (currentVersion == null || versionRegex.test(currentVersion) === false) {
console.error('Unable to find current version number.');
return;
}
// Create readline interface for getting input from user
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
// Ask for new version number
rl.question(`Enter the new version number (format x.x.x, current is ${currentVersion}): `, function (version) {
// Validate the version input
if (!versionRegex.test(version)) {
console.error(
'Invalid version number. Please use the format x.y.z where x, y, and z are positive numbers no greater than 4 digits.',
);
rl.close();
return;
}
// Get today's date
const today = new Date();
const yyyy = today.getFullYear();
const mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
const dd = String(today.getDate()).padStart(2, '0');
const newVersionHeader = `## [Unreleased]\n\n## [${version}] - ${yyyy}-${mm}-${dd}`;
const newVersionLink = `[${version}]: https://github.com/gitkraken/vscode-gitlens/compare/v${currentVersion}...gitkraken:v${version}`;
// Add the new version header below the ## [Unreleased] header
data = data.replace('## [Unreleased]', newVersionHeader);
const unreleasedLink = match[0].replace(/\/compare\/v(.+?)\.\.\.HEAD/, `\/compare\/v${version}...HEAD`);
// Update the [unreleased]: line
data = data.replace(match[0], `${unreleasedLink}\n${newVersionLink}`);
// Writing the updated version data to CHANGELOG
fs.writeFileSync(changelogPath, data);
// Stage CHANGELOG
exec('git add CHANGELOG.md', err => {
if (err) {
console.error(`Unable to stage CHANGELOG.md: ${err}`);
return;
}
// Call 'yarn version' to commit and create the tag
exec(`yarn version --new-version ${version}`, err => {
if (err) {
console.error(`'yarn version' failed: ${err}`);
return;
}
console.log(`${version} is ready for release.`);
});
});
rl.close();
});

Chargement…
Annuler
Enregistrer