-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
changelog.js
82 lines (71 loc) · 2.57 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
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const fs = require('fs');
var lines = fs.readFileSync('./CHANGELOG.md', 'utf8').split('\n');
let findCurrentVersion = false;
let findStart = false;
let changeType = '';
let write = fs.createWriteStream(process.cwd() + '/src/changelog.ts', { encoding: 'utf8', flags: 'w' });
write.write(`import { ChangeLogItem, ChangeLogKind } from "@landing-page/index";\n`);
write.write(`export const changeLog: ChangeLogItem[] = [\n`);
for (let i = 0; i < lines.length; i++) {
let line = lines[i];
if (!findCurrentVersion && line.startsWith('## Current Version')) {
findCurrentVersion = true;
continue;
}
if (findCurrentVersion && !findStart && line.startsWith('---')) {
findStart = true;
continue;
}
if (findStart) {
if (line.startsWith('#### Added')) {
changeType = 'Added';
continue;
} else if (line.startsWith('#### Removed')) {
changeType = 'Removed';
continue;
} else if (line.startsWith('#### Changed')) {
changeType = 'Changed';
continue;
} else if (line.startsWith('#### Fixed')) {
changeType = 'Fixed';
continue;
} else if (line.startsWith('#### Plan')) {
changeType = 'Plan';
continue;
}
else if (line.startsWith('### ')) {
changeType = 'Version';
line = line.substring(4);
write.write(` { kind: ChangeLogKind.${changeType.toUpperCase()}, message: \`${line}\`},\n`);
continue;
}
}
if (findStart && line.startsWith('---')) {
//console.log("changelog.ts generated")
//break;
continue;
}
if (findStart && changeType) {
if (line.trim() == '') continue;
line = line.trim().replace(/^- \[ \]/, '').replace(/^- \[x\]/, '').replace(/^- /, '').trim();
line = line.trim().replace(/^\* \[ \]/, '').replace(/^\* \[x\]/, '').replace(/^\* /, '').trim();
switch (changeType) {
case 'Added':
break;
case 'Removed':
break;
case 'Fixed':
break;
case 'Changed':
break;
case 'Plan':
break;
default:
throw new Error(`bad change type ${changeType}`);
break;
}
write.write(` { kind: ChangeLogKind.${changeType.toUpperCase()}, message: \`${line}\`},\n`);
}
}
write.write('];\n');
write.close();