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
const GitHub = require('github');
const exec = require('child_process').execSync;
const fs = require('fs');
const path = require('path');
const github = new GitHub({
debug: process.env.NODE_ENV === 'development',
});
github.authenticate({
type: 'token',
token: process.env.GITHUB_TOKEN || process.env.GITHUB_AUTH,
});
const getChangelog = (content, version) => {
const lines = content.split('\n');
const changeLog = [];
const startPattern = new RegExp(`^## ${version}`);
const stopPattern = /^## /; // 前一个版本
const skipPattern = /^`/; // 日期
let begin = false;
for (let i = 0; i < lines.length; i += 1) {
const line = lines[i];
if (begin && stopPattern.test(line)) {
break;
}
if (begin && line && !skipPattern.test(line)) {
changeLog.push(line);
}
if (!begin) {
begin = startPattern.test(line);
}
}
return changeLog.join('\n');
};
const getMds = (allVersion = false) => {
const docDir = path.join(__dirname, '..', 'docs');
const mdFils = fs.readdirSync(docDir).filter((name) => name.includes('changelog.md'));
// eslint-disable-next-line array-callback-return
mdFils.map((mdFile) => {
const pkg = mdFile.replace('pro-', '').replace('.changelog.md', '');
const content = fs.readFileSync(path.join(docDir, mdFile)).toString();
let versions = [
// eslint-disable-next-line global-require,import/no-dynamic-require
require(path.join(path.join(__dirname, '..', 'packages', pkg, 'package.json'))).version,
];
if (allVersion) {
versions = exec('git tag')
.toString()
.split('\n')
.filter((tag) => tag.includes(pkg))
.map((tag) => tag.split('@').pop());
}
console.log(versions.toString());
// eslint-disable-next-line array-callback-return
versions.map((version) => {
const versionPkg = `@wisdom-components/pro-${pkg}@${version}`;
const changeLog = getChangelog(content, versionPkg);
if (!changeLog) {
return;
}
github.repos
.createRelease({
owner: 'wisdom-extend-components',
repo: 'wisdom-extend-components',
tag_name: versionPkg,
name: versionPkg,
body: changeLog,
})
.catch((e) => {
console.log(e);
});
});
});
};
getMds();