Update build.js

This commit is contained in:
秋云
2025-04-28 21:39:03 +08:00
committed by GitHub
parent 1d40349c25
commit 68bb1a54f7

View File

@@ -1,6 +1,7 @@
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const { execSync } = require('child_process');
// 在文件开头添加全局变量
const pathingDirsWithoutIcon = new Set();
@@ -12,6 +13,17 @@ function calculateSHA1(filePath) {
return hashSum.digest('hex');
}
function getGitTimestamp(filePath) {
try {
// 获取最后一次提交时间ISO 格式)
const iso = execSync(`git log -1 --format=\"%ci\" -- "${filePath}"`, { encoding: 'utf8' }).trim();
return new Date(iso);
} catch (e) {
console.warn(`无法通过 Git 获取时间: ${filePath}`, e);
return null;
}
}
function convertNewlines(text) {
return text.replace(/\\n/g, '\n');
}
@@ -72,10 +84,12 @@ function extractInfoFromPathingFile(filePath, parentFolders) {
const contentObj = JSON.parse(content);
// 提取版本字段,若不存在则使用创建时间
const version = contentObj.info && contentObj.info.version
? contentObj.info.version
: : `${formatTime(stats.birthtime)}_${formatTime(stats.mtime)}`;
// 提取版本字段,若不存在则使用上传时间,还不存在就使用 SHA
let version = contentObj.info && contentObj.info.version;
if (!version) {
const gitDate = getGitTimestamp(filePath);
version = gitDate ? formatTime(gitDate) : calculateSHA1(filePath).substring(0, 7);
}
let tags = parentFolders.slice(2)
.filter(tag => !tag.includes('@'))