-
Notifications
You must be signed in to change notification settings - Fork 0
/
changelogToJson.js
46 lines (45 loc) · 1.14 KB
/
changelogToJson.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
const fs = require('fs');
fs.readFile('./CHANGELOG', 'utf8', (err, data) => {
if (err) {
return;
}
const json = [];
let passFirstPush = false;
let version = {};
let type;
data.split('\n')
.filter((line) => ['## ', '### ', '* '].some((s) => line.startsWith(s)))
.forEach((line) => {
let text = line;
if (line.startsWith('## ')) {
if (passFirstPush) {
json.push(version);
} else {
passFirstPush = true;
}
text = line.substring(3)
.replace(': version ', ' ')
.split(' ');
version = {
date: text[0].trim(),
version: text[1].trim(),
misc: [],
features: [],
bugs: [],
};
return;
}
if (line.startsWith('### ')) {
if (line.startsWith('Bug fixes', 4)) {
type = 'bugs';
} else if (line.startsWith('New features', 4)) {
type = 'features';
} else {
type = 'misc';
}
return;
}
version[type].push(line.replace('* ', ''));
});
fs.writeFileSync('./public/changelog.json', JSON.stringify(json));
});