ant-design-vue/antd-tools/utils/getChangelog.js

27 lines
667 B
JavaScript
Raw Normal View History

2019-01-12 03:33:27 +00:00
const fs = require('fs');
2018-03-18 11:59:38 +00:00
2019-01-12 03:33:27 +00:00
module.exports = function getChangelog(file, version) {
const lines = fs
.readFileSync(file)
.toString()
.split('\n');
const changeLog = [];
const startPattern = new RegExp(`^## ${version}`);
const stopPattern = /^## /; // 前一个版本
const skipPattern = /^`/; // 日期
let begin = false;
2018-03-18 11:59:38 +00:00
for (let i = 0; i < lines.length; i += 1) {
2019-01-12 03:33:27 +00:00
const line = lines[i];
2018-03-18 11:59:38 +00:00
if (begin && stopPattern.test(line)) {
2019-01-12 03:33:27 +00:00
break;
2018-03-18 11:59:38 +00:00
}
if (begin && line && !skipPattern.test(line)) {
2019-01-12 03:33:27 +00:00
changeLog.push(line);
2018-03-18 11:59:38 +00:00
}
if (!begin) {
2019-01-12 03:33:27 +00:00
begin = startPattern.test(line);
2018-03-18 11:59:38 +00:00
}
}
2019-01-12 03:33:27 +00:00
return changeLog.join('\n');
};