2022-07-23 20:32:10 +00:00
|
|
|
|
import fs from 'fs'
|
|
|
|
|
import lodash from 'lodash'
|
2023-03-09 20:34:25 +00:00
|
|
|
|
import { Data } from '#miao'
|
2022-05-22 13:10:10 +00:00
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
let packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'))
|
2022-05-22 13:10:10 +00:00
|
|
|
|
|
|
|
|
|
const getLine = function (line) {
|
2022-07-23 20:32:10 +00:00
|
|
|
|
line = line.replace(/(^\s*\*|\r)/g, '')
|
|
|
|
|
line = line.replace(/\s*`([^`]+`)/g, '<span class="cmd">$1')
|
|
|
|
|
line = line.replace(/`\s*/g, '</span>')
|
2022-07-23 22:28:25 +00:00
|
|
|
|
line = line.replace(/\s*\*\*([^\*]+\*\*)/g, '<span class="strong">$1')
|
2022-07-23 20:32:10 +00:00
|
|
|
|
line = line.replace(/\*\*\s*/g, '</span>')
|
|
|
|
|
line = line.replace(/ⁿᵉʷ/g, '<span class="new"></span>')
|
|
|
|
|
return line
|
2022-05-22 13:10:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-09 20:34:25 +00:00
|
|
|
|
const readLogFile = function (root, versionCount = 4) {
|
|
|
|
|
root = Data.getRoot(root)
|
|
|
|
|
let logPath = `${root}/CHANGELOG.md`
|
|
|
|
|
let logs = {}
|
|
|
|
|
let changelogs = []
|
|
|
|
|
let currentVersion
|
2022-05-22 13:10:10 +00:00
|
|
|
|
|
2023-03-09 20:34:25 +00:00
|
|
|
|
try {
|
|
|
|
|
if (fs.existsSync(logPath)) {
|
|
|
|
|
logs = fs.readFileSync(logPath, 'utf8') || ''
|
|
|
|
|
logs = logs.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)
|
|
|
|
|
if (versionRet && versionRet[1]) {
|
|
|
|
|
let v = versionRet[1].trim()
|
|
|
|
|
if (!currentVersion) {
|
|
|
|
|
currentVersion = v
|
2022-05-22 13:10:10 +00:00
|
|
|
|
} else {
|
2023-03-09 20:34:25 +00:00
|
|
|
|
changelogs.push(temp)
|
|
|
|
|
if (/0\s*$/.test(v) && versionCount > 0) {
|
|
|
|
|
versionCount = 0
|
|
|
|
|
} else {
|
|
|
|
|
versionCount--
|
|
|
|
|
}
|
2022-05-22 13:10:10 +00:00
|
|
|
|
}
|
2022-04-27 19:10:04 +00:00
|
|
|
|
|
2023-03-09 20:34:25 +00:00
|
|
|
|
temp = {
|
|
|
|
|
version: v,
|
2022-05-22 13:10:10 +00:00
|
|
|
|
logs: []
|
|
|
|
|
}
|
2023-03-09 20:34:25 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (!line.trim()) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (/^\*/.test(line)) {
|
|
|
|
|
lastLine = {
|
|
|
|
|
title: getLine(line),
|
|
|
|
|
logs: []
|
|
|
|
|
}
|
|
|
|
|
temp.logs.push(lastLine)
|
|
|
|
|
} else if (/^\s{2,}\*/.test(line)) {
|
|
|
|
|
lastLine.logs.push(getLine(line))
|
|
|
|
|
}
|
2022-04-27 19:10:04 +00:00
|
|
|
|
}
|
2023-03-09 20:34:25 +00:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// do nth
|
2022-04-26 14:25:47 +00:00
|
|
|
|
}
|
2023-03-09 20:34:25 +00:00
|
|
|
|
return { changelogs, currentVersion }
|
2022-04-26 14:25:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-09 20:34:25 +00:00
|
|
|
|
const { changelogs, currentVersion } = readLogFile('miao')
|
|
|
|
|
|
|
|
|
|
|
2022-07-23 20:32:10 +00:00
|
|
|
|
const yunzaiVersion = packageJson.version
|
|
|
|
|
const isV3 = yunzaiVersion[0] === '3'
|
2023-07-20 00:31:09 +00:00
|
|
|
|
let isMiao = false
|
|
|
|
|
let name = "Yunzai-Bot"
|
|
|
|
|
if (packageJson.name === 'miao-yunzai') {
|
|
|
|
|
isMiao = true
|
|
|
|
|
name = "Miao-Yunzai"
|
|
|
|
|
} else if (packageJson.name === 'trss-yunzai') {
|
|
|
|
|
isMiao = true
|
|
|
|
|
name = "TRSS-Yunzai"
|
|
|
|
|
}
|
2022-05-22 13:10:10 +00:00
|
|
|
|
|
2022-08-18 10:13:42 +00:00
|
|
|
|
let Version = {
|
|
|
|
|
isV3,
|
2023-03-04 09:41:23 +00:00
|
|
|
|
isMiao,
|
2023-07-20 00:31:09 +00:00
|
|
|
|
name,
|
2022-08-18 10:13:42 +00:00
|
|
|
|
get version () {
|
|
|
|
|
return currentVersion
|
|
|
|
|
},
|
|
|
|
|
get yunzai () {
|
|
|
|
|
return yunzaiVersion
|
|
|
|
|
},
|
|
|
|
|
get changelogs () {
|
|
|
|
|
return changelogs
|
2022-11-24 18:17:31 +00:00
|
|
|
|
},
|
|
|
|
|
runtime () {
|
|
|
|
|
console.log(`未能找到e.runtime,请升级至最新版${isV3 ? 'V3' : 'V2'}-Yunzai以使用miao-plugin`)
|
2023-03-09 20:34:25 +00:00
|
|
|
|
},
|
|
|
|
|
readLogFile
|
2022-08-18 10:13:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default Version
|