mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 13:10:30 +08:00
Compare commits
3 Commits
2ebb5db055
...
e357700d60
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e357700d60 | ||
|
|
109bbef3cf | ||
|
|
c01c985c91 |
@ -18,6 +18,12 @@
|
|||||||
"artifact": "node scripts/artifact.mjs",
|
"artifact": "node scripts/artifact.mjs",
|
||||||
"dev": "electron-vite dev",
|
"dev": "electron-vite dev",
|
||||||
"postinstall": "electron-builder install-app-deps",
|
"postinstall": "electron-builder install-app-deps",
|
||||||
|
"prebuild:win": "node scripts/version.js",
|
||||||
|
"prebuild:mac": "node scripts/version.js",
|
||||||
|
"prebuild:linux": "node scripts/version.js",
|
||||||
|
"postbuild:win": "node scripts/restore-version.js",
|
||||||
|
"postbuild:mac": "node scripts/restore-version.js",
|
||||||
|
"postbuild:linux": "node scripts/restore-version.js",
|
||||||
"build:win": "electron-vite build && electron-builder --publish never --win",
|
"build:win": "electron-vite build && electron-builder --publish never --win",
|
||||||
"build:mac": "electron-vite build && electron-builder --publish never --mac",
|
"build:mac": "electron-vite build && electron-builder --publish never --mac",
|
||||||
"build:linux": "electron-vite build && electron-builder --publish never --linux"
|
"build:linux": "electron-vite build && electron-builder --publish never --linux"
|
||||||
@ -97,4 +103,4 @@
|
|||||||
"vite-plugin-monaco-editor": "^1.1.0"
|
"vite-plugin-monaco-editor": "^1.1.0"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@9.15.0+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c"
|
"packageManager": "pnpm@9.15.0+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c"
|
||||||
}
|
}
|
||||||
32
scripts/restore-version.js
Normal file
32
scripts/restore-version.js
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
function restoreVersion() {
|
||||||
|
const backupPath = path.join(__dirname, '..', 'package.json.bak')
|
||||||
|
const packagePath = path.join(__dirname, '..', 'package.json')
|
||||||
|
|
||||||
|
if (fs.existsSync(backupPath)) {
|
||||||
|
try {
|
||||||
|
const backup = JSON.parse(fs.readFileSync(backupPath, 'utf8'))
|
||||||
|
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'))
|
||||||
|
|
||||||
|
// 恢复版本号
|
||||||
|
packageJson.version = backup.version
|
||||||
|
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2))
|
||||||
|
|
||||||
|
// 删除备份文件
|
||||||
|
fs.unlinkSync(backupPath)
|
||||||
|
|
||||||
|
console.log(`版本号已恢复: ${backup.version}`)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('恢复版本号时出错:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是直接运行此脚本,则执行版本恢复
|
||||||
|
if (require.main === module) {
|
||||||
|
restoreVersion()
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { restoreVersion }
|
||||||
47
scripts/version.js
Normal file
47
scripts/version.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
const { execSync } = require('child_process')
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
function getGitCommitHash() {
|
||||||
|
try {
|
||||||
|
return execSync('git rev-parse --short=7 HEAD').toString().trim()
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('无法获取 Git commit hash,使用默认值')
|
||||||
|
return 'unknown'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function processVersion() {
|
||||||
|
const packagePath = path.join(__dirname, '..', 'package.json')
|
||||||
|
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'))
|
||||||
|
|
||||||
|
// 备份原始版本号
|
||||||
|
const originalVersion = packageJson.version
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(__dirname, '..', 'package.json.bak'),
|
||||||
|
JSON.stringify({ version: originalVersion }, null, 2)
|
||||||
|
)
|
||||||
|
|
||||||
|
// 检查版本号是否以 -dev 结尾
|
||||||
|
if (originalVersion.endsWith('-dev')) {
|
||||||
|
const commitHash = getGitCommitHash()
|
||||||
|
const newVersion = originalVersion.replace('-dev', `-${commitHash}-dev`)
|
||||||
|
|
||||||
|
// 更新 package.json
|
||||||
|
packageJson.version = newVersion
|
||||||
|
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2))
|
||||||
|
|
||||||
|
console.log(`版本号已更新: ${originalVersion} -> ${newVersion}`)
|
||||||
|
return newVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`版本号未修改: ${originalVersion}`)
|
||||||
|
return originalVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是直接运行此脚本,则执行版本处理
|
||||||
|
if (require.main === module) {
|
||||||
|
processVersion()
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { processVersion, getGitCommitHash }
|
||||||
@ -26,13 +26,31 @@ export async function checkUpdate(): Promise<IAppVersion | undefined> {
|
|||||||
)
|
)
|
||||||
const latest = yaml.parse(res.data, { merge: true }) as IAppVersion
|
const latest = yaml.parse(res.data, { merge: true }) as IAppVersion
|
||||||
const currentVersion = app.getVersion()
|
const currentVersion = app.getVersion()
|
||||||
if (latest.version !== currentVersion) {
|
if (compareVersions(latest.version, currentVersion) > 0) {
|
||||||
return latest
|
return latest
|
||||||
} else {
|
} else {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1:新 -1:旧 0:相同
|
||||||
|
function compareVersions(a: string, b: string): number {
|
||||||
|
const parsePart = (part: string) => {
|
||||||
|
const numPart = part.split('-')[0]
|
||||||
|
const num = parseInt(numPart, 10)
|
||||||
|
return isNaN(num) ? 0 : num
|
||||||
|
}
|
||||||
|
const v1 = a.replace(/^v/, '').split('.').map(parsePart)
|
||||||
|
const v2 = b.replace(/^v/, '').split('.').map(parsePart)
|
||||||
|
for (let i = 0; i < Math.max(v1.length, v2.length); i++) {
|
||||||
|
const num1 = v1[i] || 0
|
||||||
|
const num2 = v2[i] || 0
|
||||||
|
if (num1 > num2) return 1
|
||||||
|
if (num1 < num2) return -1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
export async function downloadAndInstallUpdate(version: string): Promise<void> {
|
export async function downloadAndInstallUpdate(version: string): Promise<void> {
|
||||||
const { 'mixed-port': mixedPort = 7890 } = await getControledMihomoConfig()
|
const { 'mixed-port': mixedPort = 7890 } = await getControledMihomoConfig()
|
||||||
const baseUrl = `https://github.com/mihomo-party-org/mihomo-party/releases/download/v${version}/`
|
const baseUrl = `https://github.com/mihomo-party-org/mihomo-party/releases/download/v${version}/`
|
||||||
@ -113,4 +131,4 @@ export async function downloadAndInstallUpdate(version: string): Promise<void> {
|
|||||||
rm(path.join(dataDir(), file))
|
rm(path.join(dataDir(), file))
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,6 +81,7 @@
|
|||||||
|
|
||||||
*:focus {
|
*:focus {
|
||||||
outline: none;
|
outline: none;
|
||||||
|
outline-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
.flag-emoji {
|
.flag-emoji {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user