-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrelease-notes.js
59 lines (51 loc) · 1.6 KB
/
release-notes.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const releaseNotes = require('git-release-notes');
const simpleGit = require('simple-git/promise');
const path = require('path');
const {readFile, writeFile, ensureFile} = require('fs-extra');
async function generateReleaseNotes() {
try {
const OPTIONS = {
branch: 'master',
s: './post-processing.js',
};
const RANGE = await getRange();
const TEMPLATE = './mymarkdown.ejs';
const changelog = await releaseNotes(OPTIONS, RANGE, TEMPLATE);
const changelogPath = path.resolve(__dirname, '../..', 'CHANGELOG.md');
await ensureFile(changelogPath);
const currentFile = (await readFile(changelogPath)).toString().trim();
if (currentFile) {
console.log('Update %s', changelogPath);
} else {
console.log('Create %s', changelogPath);
}
await writeFile(changelogPath, changelog);
await writeFile(changelogPath, currentFile, {flag: 'a+'});
await addAndCommit().then(() => {
console.log('Changelog has been updated');
});
} catch (ex) {
console.error(ex);
process.exit(1);
}
}
async function getRange() {
const git = simpleGit();
const tags = (await git.tag({'--sort': 'committerdate'})).split('\n');
tags.pop();
const startTag = tags.slice(-2)[0];
const endTag = tags.slice(-1)[0];
return `${startTag}..${endTag}`;
}
async function addAndCommit() {
const git = simpleGit();
await git.add(['../../CHANGELOG.md']);
await git.commit('chore(release): changelog file', {
'--no-verify': null,
});
await git.push('origin', 'master');
}
generateReleaseNotes().catch(ex => {
console.error(ex);
process.exit(1);
});