2022-04-26 14:25:47 +00:00
|
|
|
import fs from "fs";
|
|
|
|
import lodash from "lodash";
|
|
|
|
|
|
|
|
const _path = process.cwd();
|
|
|
|
const _logPath = `${_path}/plugins/miao-plugin/CHANGELOG.md`;
|
|
|
|
|
|
|
|
let logs = {};
|
|
|
|
let changelogs = [];
|
|
|
|
let currentVersion;
|
2022-04-27 19:10:04 +00:00
|
|
|
let versionCount = 2;
|
2022-04-26 14:25:47 +00:00
|
|
|
try {
|
|
|
|
if (fs.existsSync(_logPath)) {
|
|
|
|
logs = fs.readFileSync(_logPath, "utf8") || "";
|
|
|
|
logs = logs.split("\n");
|
|
|
|
lodash.forEach(logs, (line) => {
|
2022-04-27 19:10:04 +00:00
|
|
|
if (versionCount === -1) {
|
2022-04-26 14:25:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
let versionRet = /^#\s*([0-9\\.]+)\s*$/.exec(line);
|
|
|
|
if (versionRet && versionRet[1]) {
|
|
|
|
let v = versionRet[1];
|
2022-04-27 19:10:04 +00:00
|
|
|
|
|
|
|
|
2022-04-26 14:25:47 +00:00
|
|
|
if (!currentVersion) {
|
|
|
|
currentVersion = v;
|
|
|
|
}
|
2022-04-27 19:10:04 +00:00
|
|
|
versionCount--;
|
|
|
|
versionCount === 0 && changelogs.push(" ");
|
|
|
|
versionCount > -1 && changelogs.push(`【 版本: ${v} 】`)
|
|
|
|
|
2022-04-26 14:25:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-04-27 19:10:04 +00:00
|
|
|
if (versionCount > -1) {
|
|
|
|
line = line.replace(/`/g, "");
|
2022-04-27 19:13:08 +00:00
|
|
|
if (line.trim()) {
|
2022-04-27 19:10:04 +00:00
|
|
|
changelogs.push(line);
|
|
|
|
}
|
2022-04-26 14:25:47 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// do nth
|
|
|
|
}
|
|
|
|
|
|
|
|
export { currentVersion, changelogs };
|