-
Notifications
You must be signed in to change notification settings - Fork 7
/
changelog.js
34 lines (28 loc) · 1.21 KB
/
changelog.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
#!/usr/bin/env node
const git = require('simple-git');
const generate_changelog = require('generate-changelog');
const fs = require('fs');
const idx = require('idx');
const argv = require('minimist')(process.argv.slice(1));
// eslint-disable-next-line handle-callback-err
git().tags((err, tags) => {
const currentChangelog = fs.readFileSync('./CHANGELOG.md');
const matched = tags && tags.latest ? tags.latest.match(/v\d+.\d+.\d+-(\d+)/) : 'v1.0.0';
const build = (idx(matched, _ => Number(_[1])) || 0) + 1;
generate_changelog
.generate({
major: argv.major,
minor: argv.minor,
patch: argv.patch
})
.then(function(changelog) {
const rxVersion = /\d+\.\d+\.\d+/;
const newVersion = argv.version || idx(changelog.match(rxVersion), _ => _[0]) + `-${build}`;
changelog = changelog.replace(rxVersion, newVersion) + currentChangelog;
fs.writeFileSync('./CHANGELOG.md', changelog);
const addFile = c => git().add('CHANGELOG.md', c);
const commit = c => git().commit(`build(change-log): v${newVersion}`, c);
const addTag = c => git().addAnnotatedTag(`v${newVersion}`, `build(tag): v${newVersion}`, c);
addFile(() => commit(() => addTag()));
});
});