25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

76 satır
2.4 KiB

  1. const { exec } = require('child_process');
  2. const fs = require('fs');
  3. const readline = require('readline');
  4. const path = require('path');
  5. const versionRegex = /^\d{1,4}\.\d{1,4}\.\d{1,4}$/;
  6. const changelogPath = path.join(__dirname, '..', 'CHANGELOG.md');
  7. console.log(changelogPath);
  8. let data = fs.readFileSync(changelogPath, 'utf8');
  9. // Find the current version number
  10. const match = /\[unreleased\]: https:\/\/github\.com\/gitkraken\/vscode-gitlens\/compare\/v(.+)\.\.\.HEAD/.exec(data);
  11. const currentVersion = match?.[1];
  12. if (currentVersion == null || versionRegex.test(currentVersion) === false) {
  13. console.error('Unable to find current version number.');
  14. return;
  15. }
  16. // Create readline interface for getting input from user
  17. const rl = readline.createInterface({
  18. input: process.stdin,
  19. output: process.stdout,
  20. });
  21. // Ask for new version number
  22. rl.question(`Enter the new version number (format x.x.x, current is ${currentVersion}): `, function (version) {
  23. // Validate the version input
  24. if (!versionRegex.test(version)) {
  25. console.error(
  26. 'Invalid version number. Please use the format x.y.z where x, y, and z are positive numbers no greater than 4 digits.',
  27. );
  28. rl.close();
  29. return;
  30. }
  31. // Get today's date
  32. const today = new Date();
  33. const yyyy = today.getFullYear();
  34. const mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  35. const dd = String(today.getDate()).padStart(2, '0');
  36. const newVersionHeader = `## [Unreleased]\n\n## [${version}] - ${yyyy}-${mm}-${dd}`;
  37. const newVersionLink = `[${version}]: https://github.com/gitkraken/vscode-gitlens/compare/v${currentVersion}...gitkraken:v${version}`;
  38. // Add the new version header below the ## [Unreleased] header
  39. data = data.replace('## [Unreleased]', newVersionHeader);
  40. const unreleasedLink = match[0].replace(/\/compare\/v(.+?)\.\.\.HEAD/, `\/compare\/v${version}...HEAD`);
  41. // Update the [unreleased]: line
  42. data = data.replace(match[0], `${unreleasedLink}\n${newVersionLink}`);
  43. // Writing the updated version data to CHANGELOG
  44. fs.writeFileSync(changelogPath, data);
  45. // Stage CHANGELOG
  46. exec('git add CHANGELOG.md', err => {
  47. if (err) {
  48. console.error(`Unable to stage CHANGELOG.md: ${err}`);
  49. return;
  50. }
  51. // Call 'yarn version' to commit and create the tag
  52. exec(`yarn version --new-version ${version}`, err => {
  53. if (err) {
  54. console.error(`'yarn version' failed: ${err}`);
  55. return;
  56. }
  57. console.log(`${version} is ready for release.`);
  58. });
  59. });
  60. rl.close();
  61. });