Files
ele-HeiXiu/scripts/publish-release.mjs
YoungestSongMo 8b697e775d feat: 去除构建时版控变量 + 窗口标题动态版控 + 退出登录保留缓存 (0.0.24)
版控体系重构(13 文件):
- 移除 build.mjs --personal/--enterprise 参数和 EDITION 环境变量
- 统一安装包文件名:船长-HeiXiu-{os}-{版本号}-Setup.{ext}
- 简化 package.json 构建脚本,移除 :enterprise 变体
- scripts/*.mjs 不再接受 edition 参数
- 移除 shared/constants/app.ts 的 parseEdition()

窗口标题动态版控:
- 新格式:船长-HeiXiu-{os}-{版本号}(登录前)/ ·{版控} 后缀(登录后)
- 链路:AppProvider(account_type) → useEffect → appRuntime IPC → main process
- 移除 updater.ts 更新检查 API 的 edition 查询参数

本地存储生命周期修正:
- 退出登录不再自动清空缓存(user_id 隔离,重新登录命中缓存)
- clearUserStorage 添加 isOpen() 竞态守卫
- 移除 closeDatabase() 避免退出→重新登录后数据库不可用
- 手动「清理缓存」按钮保留

文档:
- CHANGELOG.md 新增 0.0.24 条目
- TODO.md 新增已完成项
2026-06-22 13:36:42 +08:00

129 lines
4.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// ============================================================
// 发布版本信息到后端 API
//
// 用法:
// node scripts/publish-release.mjs <platform> [version] [--url <url>]
//
// 环境变量:
// UPDATE_API_URL — API 基地址(默认 https://www.heixiu.com
// UPDATE_API_KEY — API 鉴权 Key通过 Authorization: Bearer 头传递)
// ============================================================
import { readFileSync, readdirSync } from 'node:fs';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import axios from 'axios';
const __dirname = dirname(fileURLToPath(import.meta.url));
const ROOT = join(__dirname, '..');
// ---------- 参数 ----------
const args = process.argv.slice(2);
const positional = [];
let urlOverride = '';
let jsonOverride = '';
for (let i = 0; i < args.length; i++) {
if (args[i] === '--url' && args[i + 1]) {
urlOverride = args[++i];
} else if (args[i] === '--json' && args[i + 1]) {
jsonOverride = args[++i];
} else if (!args[i].startsWith('--')) {
positional.push(args[i]);
}
}
const platform = positional[0];
if (!platform) {
console.error('用法: node scripts/publish-release.mjs <platform> [version] [--url <url>]');
console.error('示例: node scripts/publish-release.mjs win32 0.1.0');
process.exit(1);
}
const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf-8'));
const version = positional[1] || pkg.version;
// ---------- 读取 update-info.json ----------
let updateInfo;
if (jsonOverride) {
try {
updateInfo = JSON.parse(jsonOverride);
} catch {
console.error('错误: --json 参数不是有效的 JSON');
process.exit(1);
}
} else {
const releaseDir = join(ROOT, 'release', version);
let infoFile;
try {
const all = readdirSync(releaseDir);
infoFile = all.find((f) =>
f.includes(platform) && f.endsWith('-update-info.json'),
);
if (!infoFile) console.error(`未找到 ${platform} 的 update-info.json`);
} catch (err) {
console.error(`错误: ${releaseDir}${err.message}`);
process.exit(1);
}
updateInfo = JSON.parse(readFileSync(join(releaseDir, infoFile), 'utf-8'));
if (urlOverride) updateInfo.downloadUrl = urlOverride;
}
// ---------- 发送到 API ----------
const apiBase = (process.env.UPDATE_API_URL || 'https://www.heixiu.com').replace(/\/+$/, '');
const apiKey = process.env.UPDATE_API_KEY || '';
const payload = {
platform,
latestVersion: updateInfo.latestVersion || version,
downloadUrl: updateInfo.downloadUrl,
fileSize: updateInfo.fileSize,
sha512: updateInfo.sha512,
changelog: updateInfo.changelog,
releaseDate: updateInfo.releaseDate,
forceUpdate: updateInfo.forceUpdate || false,
minimumVersion: updateInfo.minimumVersion || '0.0.0',
};
const endpoint = `${apiBase}/api/v1/releases`;
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
console.log('📡 发布版本到 API');
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
console.log(`POST ${endpoint}`);
console.log(`版本: ${version} (${platform})`);
console.log(`URL: ${payload.downloadUrl}\n`);
try {
const response = await axios.post(endpoint, payload, {
headers: {
'Content-Type': 'application/json',
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
},
timeout: 30000,
});
console.log('✅ 发布成功');
console.log(`响应: ${JSON.stringify(response.data, null, 2)}`);
} catch (err) {
const status = err.response?.status;
const data = err.response?.data;
if (status) {
console.error(`❌ 发布失败 HTTP ${status}: ${JSON.stringify(data)}`);
} else {
console.error(`❌ 请求失败: ${err.message}`);
}
console.log('\n💡 手动备选 — 把以下 JSON 发给后端:');
console.log(JSON.stringify(payload, null, 2));
process.exit(1);
}
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');