-
Notifications
You must be signed in to change notification settings - Fork 960
Expand file tree
/
Copy pathgenerate_changelog.js
More file actions
43 lines (35 loc) · 1.15 KB
/
Copy pathgenerate_changelog.js
File metadata and controls
43 lines (35 loc) · 1.15 KB
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
// @ts-check
const fs = require('fs');
const fileNames = fs.readdirSync('./');
const logsPath = './public/changelogs/';
fs.rmSync(logsPath, {force: true, recursive: true});
fs.mkdirSync(logsPath);
const processChangelog = (fileName) => {
const text = fs.readFileSync('./' + fileName).toString('utf-8');
const lang = (fileName.split('_')[1] || 'en').split('.')[0];
const writeTo = `${logsPath}${lang}_{VERSION}.md`;
const separator = '### ';
const splitted = text.split(separator);
splitted.forEach(text => {
if(!text.trim()) return;
text = separator + text;
text = text.replace(/^\*(\s)/gm, '•$1');
const splitted = text.split('\n');
for(let i = splitted.length - 1; i >= 0; --i) {
const line = splitted[i];
if(!line.trim()) {
splitted.splice(i, 1);
} else {
break;
}
}
const firstLine = splitted.shift();
const version = firstLine.split(' ')[1];
fs.writeFileSync(writeTo.replace('{VERSION}', version), splitted.join('\n') + '\n');
});
};
fileNames.forEach(fileName => {
if(fileName.endsWith('.md') && fileName.startsWith('CHANGELOG')) {
processChangelog(fileName);
}
});