-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
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\/eamodio\/vscode-amethyst-theme\/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/eamodio/vscode-amethyst-theme/compare/v${currentVersion}...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(); | ||
}); |