-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathchangelog-fixer.js
More file actions
44 lines (30 loc) · 1018 Bytes
/
changelog-fixer.js
File metadata and controls
44 lines (30 loc) · 1018 Bytes
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
module.exports = function() {
const fs = require('fs');
const md = fs.readFileSync('CHANGELOG.md', 'utf8');
let versions = md.match(/#{2,3} \[([0-9.]+)\]/g).slice(0, 5);
let _VersionTree = {};
let lastVersion = undefined;
for (let version of versions) {
if (!!lastVersion) {
_VersionTree[lastVersion].endOfVersion = md.indexOf(version);
}
let fixedVersion = version.replace(/#/g, '').trim();
_VersionTree[fixedVersion] = {
version: fixedVersion,
startOfVersion: md.indexOf(fixedVersion),
endOfVersion: !!lastVersion ? md.indexOf(lastVersion) : -1
};
lastVersion = fixedVersion;
}
delete _VersionTree[lastVersion];
let outputChangelog = '';
for (let version in _VersionTree) {
let _md = md.substring(_VersionTree[version].startOfVersion, _VersionTree[version].endOfVersion).replace(/### /g, '#### ').trim();
_VersionTree[version] = {
..._VersionTree[version],
MarkdownContent: _md
};
outputChangelog += '### ' + _md + '\n\n';
}
return outputChangelog;
};