forked from jdf2e/nutui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateChangelog.js
85 lines (84 loc) · 1.94 KB
/
updateChangelog.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
83
84
85
const fs = require('fs');
const path = require('path');
const changelog = fs.readFileSync(
path.join(__dirname, '../CHANGELOG.md'),
'utf8'
);
const typeList = [
{ type: 'fix', icon: '🐛' },
{ type: 'feat', icon: '✨' },
{ type: 'chore', icon: '👷' },
{ type: 'docs', icon: '📝 ' },
{ type: 'style', icon: '💄' },
{ type: 'refactor', icon: '🎨' },
{ type: 'perf', icon: '⚡' },
{ type: 'test', icon: '✅ ' }
];
const replaceMd = {
content: '',
setContent(content) {
replaceMd.content = content;
return replaceMd;
},
getContent() {
return replaceMd.content;
},
//版本号改成二级标题
changeTitle() {
replaceMd.content = replaceMd.content.replace(
/### (?=\[\d\.\d\.\d\])/g,
'## '
);
return replaceMd;
},
//修改日期位置
changeDate() {
replaceMd.content = replaceMd.content.replace(
/(?<=\[\d\.\d\.\d\]\([\s\S]+\)) \((\d\d\d\d\-\d\d\-\d\d)\)(?=\n)/g,
'\n`$1`'
);
return replaceMd;
},
//增加type内容
changeType() {
function replaceType(type, icon) {
replaceMd.content = replaceMd.content.replace(
new RegExp(
`(?<=### ${type}\\n\\n)\\* ([\\s\\S]+?)\\n+(?=[###|##])`,
'g'
),
function(match) {
return match.replace(
new RegExp(`\\* ([\\s\\S]+?)(?=\\n)`, 'g'),
`* ${icon} ${type}: $1`
);
}
);
}
typeList.forEach(e => {
replaceType(e.type, e.icon);
});
return replaceMd;
},
//删除type标题
deleteType() {
typeList.forEach(e => {
replaceMd.content = replaceMd.content.replace(
new RegExp(`### ${e.type}\\n+`, 'g'),
''
);
});
return replaceMd;
}
};
const newChangelog = replaceMd
.setContent(changelog)
.changeTitle()
.changeDate()
.changeType()
.deleteType();
fs.writeFileSync(
path.join(__dirname, '../CHANGELOG.md'),
newChangelog.getContent(),
'utf8'
);