|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const fs = require('fs'), |
| 4 | + exec = require('child_process').execSync; |
| 5 | + |
| 6 | +if (!process.argv || process.argv.length < 3) { |
| 7 | + throw new Error('missing argument (ver nr)'); |
| 8 | +} |
| 9 | + |
| 10 | +const versionNumber = process.argv[2]; |
| 11 | + |
| 12 | +console.log('Create release branch'); |
| 13 | + |
| 14 | +exec(`git checkout -b release/${versionNumber}`); |
| 15 | + |
| 16 | +console.log(`Update package.json to version v${versionNumber}`); |
| 17 | + |
| 18 | +let packageJson = fs.readFileSync('./package.json', 'utf-8'); |
| 19 | +packageJson = packageJson.replace(/"version": .*,/, `"version": "${versionNumber}",`); |
| 20 | + |
| 21 | +fs.writeFileSync('./package.json', packageJson, { encoding: 'utf-8' }); |
| 22 | + |
| 23 | +console.log(`Update changelog`); |
| 24 | + |
| 25 | +let changelog = fs.readFileSync('./CHANGELOG.md', 'utf-8'); |
| 26 | +changelog = changelog.replace(/## \[Unreleased\]/, `## [Unreleased]\n\n## [${versionNumber}]`); |
| 27 | +changelog = changelog.replace(/\[Unreleased\]\:.*v(.*)\.\.\.master/, `[Unreleased]: https://github.com/buehler/typescript-hero/compare/v${versionNumber}...master |
| 28 | +[${versionNumber}]: https://github.com/buehler/typescript-hero/compare/v$1...v${versionNumber}`); |
| 29 | + |
| 30 | +fs.writeFileSync('./CHANGELOG.md', changelog, { encoding: 'utf-8' }); |
| 31 | + |
| 32 | +console.log('Commit package.json'); |
| 33 | + |
| 34 | +exec('git add package.json'); |
| 35 | +exec(`git commit -m "Version bump to v${versionNumber}"`); |
| 36 | + |
| 37 | +console.log('Commit changelog'); |
| 38 | + |
| 39 | +exec('git add CHANGELOG.md'); |
| 40 | +exec(`git commit -m "Update changelog to v${versionNumber}"`); |
0 commit comments