[feat] fullfil tasks to minify manual actions
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
* --version <version> 版本号(可选,默认从 tauri.conf.json 读取)
|
||||
* --notes <notes> 更新说明(可选)
|
||||
* --target <target> 构建类型(可选,默认 release,可选值:debug、release、fast-release)
|
||||
* --rename 在生成 latest.json 之前,将文件名中的 "CS工具箱" 改为 "CS_Toolbox"
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
@@ -34,6 +35,7 @@ const version = getArg('--version', tauriConfig.version);
|
||||
const baseUrl = getArg('--base-url');
|
||||
const notes = getArg('--notes', '');
|
||||
const target = getArg('--target', 'release');
|
||||
const shouldRename = args.includes('--rename');
|
||||
|
||||
// 验证 target 参数
|
||||
const validTargets = ['debug', 'release', 'fast-release'];
|
||||
@@ -48,6 +50,22 @@ if (!baseUrl) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// 如果需要重命名,先执行重命名脚本
|
||||
if (shouldRename) {
|
||||
console.log('\n执行文件重命名...');
|
||||
const { execSync } = require('child_process');
|
||||
try {
|
||||
execSync(`node scripts/rename-build-artifacts.js --target ${target}`, {
|
||||
stdio: 'inherit',
|
||||
cwd: path.join(__dirname, '..')
|
||||
});
|
||||
console.log('✓ 文件重命名完成\n');
|
||||
} catch (err) {
|
||||
console.error('✗ 文件重命名失败:', err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// 确保 baseUrl 不以 / 结尾
|
||||
const cleanBaseUrl = baseUrl.replace(/\/$/, '');
|
||||
|
||||
@@ -63,13 +81,20 @@ if (githubReleasesMatch) {
|
||||
|
||||
// 生成文件 URL
|
||||
function generateFileUrl(filename) {
|
||||
// 如果使用了 --rename,文件名应该已经是 CS_Toolbox 了
|
||||
// 但为了兼容,我们检查一下是否需要替换
|
||||
let finalFilename = filename;
|
||||
if (shouldRename && filename.includes('CS工具箱')) {
|
||||
finalFilename = filename.replace(/CS工具箱/g, 'CS_Toolbox');
|
||||
}
|
||||
|
||||
if (githubOwner && githubRepo) {
|
||||
// GitHub releases 下载 URL 格式: https://github.com/{owner}/{repo}/releases/download/{tag}/{filename}
|
||||
const tag = version.startsWith('v') ? version : `v${version}`;
|
||||
return `https://github.com/${githubOwner}/${githubRepo}/releases/download/${tag}/${filename}`;
|
||||
return `https://github.com/${githubOwner}/${githubRepo}/releases/download/${tag}/${finalFilename}`;
|
||||
}
|
||||
// 普通 URL
|
||||
return `${cleanBaseUrl}/${filename}`;
|
||||
return `${cleanBaseUrl}/${finalFilename}`;
|
||||
}
|
||||
|
||||
// 根据 target 确定构建产物目录
|
||||
@@ -196,7 +221,25 @@ for (const [platform, config] of Object.entries(platforms)) {
|
||||
|
||||
const result = findFiles(config.dir, version, config.extensions);
|
||||
if (result) {
|
||||
console.log(` ✓ 找到文件: ${result.file}`);
|
||||
// 如果使用了 --rename,文件名应该已经是 CS_Toolbox 了
|
||||
// 但如果仍然包含 CS工具箱,说明重命名可能失败了,尝试手动处理
|
||||
let fileName = result.file;
|
||||
if (shouldRename && fileName.includes('CS工具箱')) {
|
||||
console.warn(` 警告: 文件 ${fileName} 仍包含中文,尝试查找重命名后的文件...`);
|
||||
const renamedFile = fileName.replace(/CS工具箱/g, 'CS_Toolbox');
|
||||
const renamedPath = path.join(config.dir, renamedFile);
|
||||
if (fs.existsSync(renamedPath)) {
|
||||
fileName = renamedFile;
|
||||
result.file = renamedFile;
|
||||
result.url = generateFileUrl(renamedFile);
|
||||
// 检查重命名后的签名文件
|
||||
const renamedSigPath = renamedPath + '.sig';
|
||||
if (fs.existsSync(renamedSigPath)) {
|
||||
result.signature = fs.readFileSync(renamedSigPath, 'utf-8').trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(` ✓ 找到文件: ${fileName}`);
|
||||
platformsData[platform] = {
|
||||
url: result.url,
|
||||
signature: result.signature
|
||||
|
||||
Reference in New Issue
Block a user