mirror of
https://github.com/ILoveBingLu/CipherTalk.git
synced 2026-05-20 03:23:21 +08:00
chore: release 2.3.5
This commit is contained in:
@@ -10,7 +10,7 @@ if (!fs.existsSync(ymlPath)) {
|
||||
}
|
||||
|
||||
// 读取 yml 内容
|
||||
let content = fs.readFileSync(ymlPath, 'utf-8')
|
||||
const content = fs.readFileSync(ymlPath, 'utf-8')
|
||||
const lines = content.split('\n')
|
||||
|
||||
// 从 yml 中提取文件名
|
||||
@@ -32,10 +32,11 @@ if (!fs.existsSync(exePath)) {
|
||||
const stats = fs.statSync(exePath)
|
||||
const size = stats.size
|
||||
|
||||
// 找到 files 块内第一个 sha512 行,在其后插入 size
|
||||
// electron-builder 新版本已经会生成 files[0].size,这里只在缺失时补齐,避免写出重复键
|
||||
const newLines = []
|
||||
let inFiles = false
|
||||
let sizeAdded = false
|
||||
let fileItemIndent = ''
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i]
|
||||
@@ -43,11 +44,36 @@ for (let i = 0; i < lines.length; i++) {
|
||||
|
||||
if (line.startsWith('files:')) {
|
||||
inFiles = true
|
||||
fileItemIndent = ''
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
if (!inFiles) {
|
||||
continue
|
||||
}
|
||||
|
||||
const trimmed = line.trim()
|
||||
const indent = line.match(/^\s*/)?.[0] || ''
|
||||
|
||||
if (trimmed.startsWith('- ')) {
|
||||
fileItemIndent = `${indent} `
|
||||
continue
|
||||
}
|
||||
|
||||
if (trimmed.startsWith('size:')) {
|
||||
console.log('latest.yml 已包含 size,跳过写入')
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
// 离开 files 块
|
||||
if (trimmed && !line.startsWith(' ') && !line.startsWith('\t')) {
|
||||
inFiles = false
|
||||
continue
|
||||
}
|
||||
|
||||
// 在 files 块内的第一个 sha512 后添加 size
|
||||
if (inFiles && !sizeAdded && line.trim().startsWith('sha512:')) {
|
||||
newLines.push(` size: ${size}`)
|
||||
if (!sizeAdded && trimmed.startsWith('sha512:')) {
|
||||
newLines.push(`${fileItemIndent || ' '}size: ${size}`)
|
||||
sizeAdded = true
|
||||
inFiles = false
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const rootDir = path.resolve(__dirname, '..')
|
||||
const releaseDir = path.join(rootDir, 'release')
|
||||
const tempDir = path.join(rootDir, '.tmp')
|
||||
const bodyPath = path.join(releaseDir, 'release-body.md')
|
||||
const forceUpdatePath = path.join(releaseDir, 'force-update.json')
|
||||
const outputPath = path.join(tempDir, 'release-announcement.json')
|
||||
const packageJsonPath = path.join(rootDir, 'package.json')
|
||||
|
||||
function readJsonIfExists(filePath) {
|
||||
if (!fs.existsSync(filePath)) return null
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(filePath, 'utf8'))
|
||||
} catch (error) {
|
||||
console.warn(`[ReleaseAnnouncement] 读取 JSON 失败: ${filePath}`, String(error))
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function readTextIfExists(filePath) {
|
||||
if (!fs.existsSync(filePath)) return ''
|
||||
try {
|
||||
return fs.readFileSync(filePath, 'utf8').trim()
|
||||
} catch (error) {
|
||||
console.warn(`[ReleaseAnnouncement] 读取文本失败: ${filePath}`, String(error))
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
function buildFallbackBody(version, releaseNotes) {
|
||||
const normalizedNotes = String(releaseNotes || '').trim()
|
||||
const overview = normalizedNotes
|
||||
? normalizedNotes
|
||||
.split(/\r?\n/)
|
||||
.map((line) => line.trim())
|
||||
.filter(Boolean)
|
||||
.map((line) => (line.startsWith('-') || line.startsWith('*') ? line : `- ${line}`))
|
||||
.join('\n')
|
||||
: '- 本次版本已完成发布,详细内容将在后续发布说明中补充。'
|
||||
|
||||
return [
|
||||
`## CipherTalk v${version}`,
|
||||
'',
|
||||
'### 概览',
|
||||
overview,
|
||||
'',
|
||||
'### 感谢贡献者',
|
||||
'- 感谢每一位使用与反馈的用户',
|
||||
'',
|
||||
'### 相关提交与 PR',
|
||||
'- 详见本次发布记录',
|
||||
''
|
||||
].join('\n')
|
||||
}
|
||||
|
||||
function main() {
|
||||
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
|
||||
const version = String(pkg.version || '').trim()
|
||||
if (!version) {
|
||||
throw new Error('package.json 中未找到 version')
|
||||
}
|
||||
|
||||
const releaseBody = readTextIfExists(bodyPath)
|
||||
const forceUpdate = readJsonIfExists(forceUpdatePath) || {}
|
||||
const releaseNotes = String(forceUpdate.releaseNotes || '').trim()
|
||||
|
||||
const payload = {
|
||||
version,
|
||||
releaseBody: releaseBody || buildFallbackBody(version, releaseNotes),
|
||||
releaseNotes: releaseNotes || releaseBody || '',
|
||||
generatedAt: new Date().toISOString()
|
||||
}
|
||||
|
||||
fs.mkdirSync(tempDir, { recursive: true })
|
||||
fs.writeFileSync(outputPath, `${JSON.stringify(payload, null, 2)}\n`, 'utf8')
|
||||
console.log(`[ReleaseAnnouncement] 已生成 ${outputPath}`)
|
||||
}
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user