加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
version.js 2.37 KB
一键复制 编辑 原始数据 按行查看 历史
yxyos 提交于 2024-02-06 15:57 . up
import fs from 'fs'
import lodash from 'lodash'
import cfg from '../../lib/config/config.js'
const Plugin_Path = `${process.cwd()}/plugins/Mini-world-plugin`;
const README_path = `${Plugin_Path}/README.md`
const CHANGELOG_path = `${Plugin_Path}/CHANGELOG.md`
const yunzai_ver = `v${cfg.package.version}`;
let logs = {}
let changelogs = []
let currentVersion
let versionCount = 6
const getLine = function (line) {
line = line.replace(/(^\s*\*|\r)/g, '')
line = line.replace(/\s*`([^`]+`)/g, '<span class="cmd">$1')
line = line.replace(/`\s*/g, '</span>')
line = line.replace(/\s*\*\*([^\*]+\*\*)/g, '<span class="strong">$1')
line = line.replace(/\*\*\s*/g, '</span>')
line = line.replace(/ⁿᵉʷ/g, '<span class="new"></span>')
return line
}
try {
if (fs.existsSync(CHANGELOG_path)) {
logs = fs.readFileSync(CHANGELOG_path, 'utf8') || ''
logs = logs.replace(/\t/g,' ').split('\n')
let temp = {};
let lastLine = {}
lodash.forEach(logs, (line) => {
if (versionCount <= -1) {
return false
}
let versionRet = /^#\s*([0-9a-zA-Z\\.~\s]+?)\s*$/.exec(line.trim())
if (versionRet && versionRet[1]) {
let v = versionRet[1].trim()
if (!currentVersion) {
currentVersion = v
} else {
changelogs.push(temp)
if (/0\s*$/.test(v) && versionCount > 0) {
//versionCount = 0
versionCount--
} else {
versionCount--
}
}
temp = {
version: v,
logs: []
}
} else {
if (!line.trim()) {
return
}
if (/^\*/.test(line)) {
lastLine = {
title: getLine(line),
logs: []
}
if(!temp.logs){
temp = {
version: line,
logs: []
}
}
temp.logs.push(lastLine)
} else if (/^\s{2,}\*/.test(line)) {
lastLine.logs.push(getLine(line))
}
}
})
}
} catch (e) {
logger.error(e);
// do nth
}
try{
if(fs.existsSync(README_path)){
let README = fs.readFileSync(README_path, 'utf8') || ''
let reg = /版本:(.*)/.exec(README)
if(reg){
currentVersion = reg[1]
}
}
}catch(err){}
let Version = {
get ver () {
return currentVersion;
},
get yunzai(){
return yunzai_ver;
},
get logs(){
return changelogs;
}
}
export default Version
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化