调整打包脚本使用 packaging 资源路径
This commit is contained in:
+47
-23
@@ -6,8 +6,14 @@ async function preparePackage() {
|
||||
console.log('📦 开始准备打包资源...\n');
|
||||
console.log('='.repeat(60));
|
||||
|
||||
const extraDir = path.join(__dirname, '../electron/resources/extra');
|
||||
const packagingDir = path.join(__dirname, '../packaging');
|
||||
const extraDir = path.join(packagingDir, 'resources');
|
||||
const vendorDir = path.join(packagingDir, 'vendor');
|
||||
const commonDir = path.join(extraDir, 'common');
|
||||
const pythonRuntimeDir = path.join(vendorDir, 'python-runtime');
|
||||
const ffmpegDir = path.join(vendorDir, 'ffmpeg');
|
||||
const modelDir = path.join(vendorDir, 'models');
|
||||
const fontBundleDir = path.join(vendorDir, 'fonts');
|
||||
|
||||
// 0. 发布前同步系统字幕模板,避免安装包带入旧候选模板或旧音效配置
|
||||
console.log('\n0锔忊儯 鍚屾绯荤粺瀛楀箷妯℃澘...');
|
||||
@@ -16,16 +22,16 @@ async function preparePackage() {
|
||||
|
||||
// 1. 确保目录存在
|
||||
console.log('\n1️⃣ 确保目录结构存在...');
|
||||
await fs.ensureDir(path.join(commonDir, 'python'));
|
||||
await fs.ensureDir(pythonRuntimeDir);
|
||||
await fs.ensureDir(path.join(commonDir, 'chromium'));
|
||||
await fs.ensureDir(path.join(commonDir, 'python-scripts'));
|
||||
await fs.ensureDir(path.join(commonDir, 'models'));
|
||||
await fs.ensureDir(path.join(commonDir, 'fonts'));
|
||||
await fs.ensureDir(path.join(commonDir, 'bgm'));
|
||||
await fs.ensureDir(modelDir);
|
||||
await fs.ensureDir(fontBundleDir);
|
||||
await fs.ensureDir(vendorDir);
|
||||
await fs.ensureDir(path.join(commonDir, 'demo'));
|
||||
await fs.ensureDir(path.join(commonDir, 'config'));
|
||||
await fs.ensureDir(path.join(commonDir, 'cover-templates'));
|
||||
await fs.ensureDir(path.join(extraDir, 'win-x86'));
|
||||
await fs.ensureDir(ffmpegDir);
|
||||
console.log(' ✅ 目录结构准备完成\n');
|
||||
|
||||
// 2. 复制 Python 脚本
|
||||
@@ -60,7 +66,6 @@ async function preparePackage() {
|
||||
const fileCount = await countFiles(pythonDest);
|
||||
console.log(` ✅ Python 脚本复制到 python-scripts 完成 (${fileCount} 个文件)`);
|
||||
|
||||
const pythonRuntimeDir = path.join(commonDir, 'python');
|
||||
await copyWithLockTolerance(pythonSrc, pythonRuntimeDir, {
|
||||
overwrite: true,
|
||||
filter: pythonFilter
|
||||
@@ -72,10 +77,13 @@ async function preparePackage() {
|
||||
|
||||
// 3. 复制字体
|
||||
console.log('3️⃣ 复制字体文件...');
|
||||
const fontSrc = path.join(__dirname, '../ziti');
|
||||
const fontDest = path.join(commonDir, 'fonts/ziti');
|
||||
const fontSrc = await firstExistingPath([
|
||||
path.join(vendorDir, 'ziti'),
|
||||
path.join(__dirname, '../ziti')
|
||||
]);
|
||||
const fontDest = path.join(fontBundleDir, 'ziti');
|
||||
|
||||
if (fs.existsSync(fontSrc)) {
|
||||
if (fontSrc && fs.existsSync(fontSrc)) {
|
||||
if (process.env.OEM_BATCH_BUILD === '1' && await fs.pathExists(fontDest)) {
|
||||
const existingFileCount = await countFiles(fontDest);
|
||||
if (existingFileCount > 0) {
|
||||
@@ -105,19 +113,26 @@ async function preparePackage() {
|
||||
|
||||
// 4. 复制 BGM
|
||||
console.log('4️⃣ 复制背景音乐...');
|
||||
const bgmSrc = path.join(__dirname, '../bgm');
|
||||
const bgmDest = path.join(commonDir, 'bgm');
|
||||
const bgmSrc = await firstExistingPath([
|
||||
path.join(vendorDir, 'bgm'),
|
||||
path.join(__dirname, '../bgm')
|
||||
]);
|
||||
const bgmDest = path.join(vendorDir, 'bgm');
|
||||
|
||||
if (fs.existsSync(bgmSrc)) {
|
||||
if (bgmSrc && fs.existsSync(bgmSrc)) {
|
||||
if (process.env.OEM_BATCH_BUILD === '1' && await fs.pathExists(bgmDest)) {
|
||||
const existingFileCount = await countFiles(bgmDest);
|
||||
if (existingFileCount > 0) {
|
||||
console.log(` [SKIP] OEM batch build reuses prepared BGM (${existingFileCount} files)\n`);
|
||||
} else {
|
||||
await copyWithLockTolerance(bgmSrc, bgmDest, { overwrite: true });
|
||||
if (path.resolve(bgmSrc) !== path.resolve(bgmDest)) {
|
||||
await copyWithLockTolerance(bgmSrc, bgmDest, { overwrite: true });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await copyWithLockTolerance(bgmSrc, bgmDest, { overwrite: true });
|
||||
if (path.resolve(bgmSrc) !== path.resolve(bgmDest)) {
|
||||
await copyWithLockTolerance(bgmSrc, bgmDest, { overwrite: true });
|
||||
}
|
||||
}
|
||||
const fileCount = await countFiles(bgmDest);
|
||||
const totalSize = await getDirSize(bgmDest);
|
||||
@@ -175,7 +190,7 @@ async function preparePackage() {
|
||||
name: 'default-ipagent-config.json'
|
||||
},
|
||||
{
|
||||
src: path.join(__dirname, '../electron/resources/extra/common/config/system-templates.json'),
|
||||
src: path.join(commonDir, 'config/system-templates.json'),
|
||||
dest: path.join(configDest, 'system-templates.json'),
|
||||
name: 'system-templates.json (系统模板配置 - 8套字幕+8套封面)'
|
||||
}
|
||||
@@ -217,7 +232,7 @@ async function preparePackage() {
|
||||
];
|
||||
|
||||
// 动态查找最新的 Playwright Chromium 版本
|
||||
const playwrightDir = path.join(commonDir, 'playwright');
|
||||
const playwrightDir = path.join(vendorDir, 'playwright');
|
||||
let playwrightChromiumCheck = null;
|
||||
if (await fs.pathExists(playwrightDir)) {
|
||||
const chromiumDirs = (await fs.readdir(playwrightDir))
|
||||
@@ -236,13 +251,13 @@ async function preparePackage() {
|
||||
}
|
||||
|
||||
const checks = [
|
||||
{ name: 'Python 环境', path: path.join(commonDir, 'python/python.exe') },
|
||||
{ name: 'Python 依赖 (opencv)', path: path.join(commonDir, 'python/Lib/site-packages/cv2') },
|
||||
{ name: 'FFmpeg (win-x86)', path: path.join(extraDir, 'win-x86/ffmpeg.exe') },
|
||||
{ name: 'FFprobe (win-x86)', path: path.join(extraDir, 'win-x86/ffprobe.exe') },
|
||||
...ffmpegDlls.map(dll => ({ name: `FFmpeg DLL (${dll})`, path: path.join(extraDir, `win-x86/${dll}`) })),
|
||||
{ name: 'Python 环境', path: path.join(pythonRuntimeDir, 'python.exe') },
|
||||
{ name: 'Python 依赖 (opencv)', path: path.join(pythonRuntimeDir, 'Lib/site-packages/cv2') },
|
||||
{ name: 'FFmpeg (win-x86)', path: path.join(ffmpegDir, 'ffmpeg.exe') },
|
||||
{ name: 'FFprobe (win-x86)', path: path.join(ffmpegDir, 'ffprobe.exe') },
|
||||
...ffmpegDlls.map(dll => ({ name: `FFmpeg DLL (${dll})`, path: path.join(ffmpegDir, dll) })),
|
||||
...(playwrightChromiumCheck ? [playwrightChromiumCheck] : []),
|
||||
{ name: 'U2-Net 模型', path: path.join(commonDir, 'models/u2net.onnx') },
|
||||
{ name: 'U2-Net 模型', path: path.join(modelDir, 'u2net.onnx') },
|
||||
];
|
||||
|
||||
let allOk = true;
|
||||
@@ -295,6 +310,15 @@ async function copyWithLockTolerance(src, dest, options = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
async function firstExistingPath(paths) {
|
||||
for (const candidate of paths) {
|
||||
if (candidate && await fs.pathExists(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 辅助函数:统计文件数量
|
||||
async function countFiles(dir) {
|
||||
let count = 0;
|
||||
|
||||
Reference in New Issue
Block a user