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