feat: 支持win打包
This commit is contained in:
28
scripts/pack-mac.sh
Normal file
28
scripts/pack-mac.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "🔧 设置 Electron 镜像源..."
|
||||
echo ""
|
||||
|
||||
# 设置 Electron 镜像环境变量
|
||||
export ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/
|
||||
export ELECTRON_BUILDER_BINARIES_MIRROR=https://npmmirror.com/mirrors/electron-builder-binaries/
|
||||
export ELECTRON_CUSTOM_DIR='{{ version }}'
|
||||
export ELECTRON_CUSTOM_FILENAME='{{ filename }}'
|
||||
|
||||
echo "✅ 环境变量已设置:"
|
||||
echo " ELECTRON_MIRROR: $ELECTRON_MIRROR"
|
||||
echo " ELECTRON_BUILDER_BINARIES_MIRROR: $ELECTRON_BUILDER_BINARIES_MIRROR"
|
||||
echo ""
|
||||
|
||||
echo "🚀 开始打包 Mac 版本..."
|
||||
echo ""
|
||||
|
||||
npm run pack:mac
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo ""
|
||||
echo "✅ 打包成功!"
|
||||
else
|
||||
echo ""
|
||||
echo "❌ 打包失败,请检查错误信息"
|
||||
fi
|
||||
30
scripts/pack-win.bat
Normal file
30
scripts/pack-win.bat
Normal file
@@ -0,0 +1,30 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
echo 🔧 设置 Electron 镜像源...
|
||||
echo.
|
||||
|
||||
REM 设置 Electron 镜像环境变量
|
||||
set ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/
|
||||
set ELECTRON_BUILDER_BINARIES_MIRROR=https://npmmirror.com/mirrors/electron-builder-binaries/
|
||||
set ELECTRON_CUSTOM_DIR={{ version }}
|
||||
set ELECTRON_CUSTOM_FILENAME={{ filename }}
|
||||
|
||||
echo ✅ 环境变量已设置:
|
||||
echo ELECTRON_MIRROR: %ELECTRON_MIRROR%
|
||||
echo ELECTRON_BUILDER_BINARIES_MIRROR: %ELECTRON_BUILDER_BINARIES_MIRROR%
|
||||
echo.
|
||||
|
||||
echo 🚀 开始打包 Windows 版本...
|
||||
echo.
|
||||
|
||||
call npm run pack:win
|
||||
|
||||
if %ERRORLEVEL% EQU 0 (
|
||||
echo.
|
||||
echo ✅ 打包成功!
|
||||
) else (
|
||||
echo.
|
||||
echo ❌ 打包失败,请检查错误信息
|
||||
)
|
||||
|
||||
pause
|
||||
47
scripts/prepare-electron.cjs
Normal file
47
scripts/prepare-electron.cjs
Normal file
@@ -0,0 +1,47 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const root = path.join(__dirname, '..')
|
||||
const distDir = path.join(root, 'dist')
|
||||
const electronDir = path.join(root, 'electron')
|
||||
const targetDistDir = path.join(electronDir, 'dist')
|
||||
|
||||
console.log('📦 Preparing Electron packaging...')
|
||||
|
||||
// 1. Verify dist directory exists
|
||||
if (!fs.existsSync(distDir)) {
|
||||
console.error('❌ dist directory not found. Please run `npm run build` first.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// 2. Remove old dist directory in electron folder if exists
|
||||
if (fs.existsSync(targetDistDir)) {
|
||||
console.log('🗑️ Removing old dist directory in electron folder...')
|
||||
fs.rmSync(targetDistDir, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
// 3. Copy dist directory to electron folder
|
||||
console.log('📁 Copying dist directory to electron folder...')
|
||||
copyRecursiveSync(distDir, targetDistDir)
|
||||
|
||||
console.log('✅ Electron packaging preparation complete!')
|
||||
|
||||
// Helper function to copy directories recursively
|
||||
function copyRecursiveSync(src, dest) {
|
||||
const exists = fs.existsSync(src)
|
||||
const stats = exists && fs.statSync(src)
|
||||
const isDirectory = exists && stats.isDirectory()
|
||||
if (isDirectory) {
|
||||
if (!fs.existsSync(dest)) {
|
||||
fs.mkdirSync(dest, { recursive: true })
|
||||
}
|
||||
fs.readdirSync(src).forEach((childItemName) => {
|
||||
copyRecursiveSync(
|
||||
path.join(src, childItemName),
|
||||
path.join(dest, childItemName)
|
||||
)
|
||||
})
|
||||
} else {
|
||||
fs.copyFileSync(src, dest)
|
||||
}
|
||||
}
|
||||
35
scripts/verify-mirrors.cjs
Normal file
35
scripts/verify-mirrors.cjs
Normal file
@@ -0,0 +1,35 @@
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
console.log('🔍 验证 Electron 镜像源配置...\n')
|
||||
|
||||
// 检查 npm 配置
|
||||
try {
|
||||
const registry = execSync('npm config get registry', { encoding: 'utf-8' }).trim()
|
||||
const electronMirror = execSync('npm config get electron_mirror', { encoding: 'utf-8' }).trim()
|
||||
const builderMirror = execSync('npm config get electron_builder_binaries_mirror', { encoding: 'utf-8' }).trim()
|
||||
|
||||
console.log('✅ npm 配置:')
|
||||
console.log(' registry:', registry)
|
||||
console.log(' electron_mirror:', electronMirror)
|
||||
console.log(' electron_builder_binaries_mirror:', builderMirror)
|
||||
console.log()
|
||||
|
||||
// 验证是否使用了镜像源
|
||||
const isUsingMirror = electronMirror.includes('npmmirror.com') ||
|
||||
electronMirror.includes('huaweicloud.com') ||
|
||||
electronMirror.includes('cloud.tencent.com')
|
||||
|
||||
if (isUsingMirror) {
|
||||
console.log('✅ 已配置国内镜像源,无需翻墙即可打包!')
|
||||
} else {
|
||||
console.log('⚠️ 未检测到国内镜像源,可能需要翻墙才能打包')
|
||||
}
|
||||
|
||||
console.log()
|
||||
console.log('📦 现在可以执行打包命令:')
|
||||
console.log(' npm run pack:win # Windows')
|
||||
console.log(' npm run pack:mac # Mac')
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 验证失败:', error.message)
|
||||
}
|
||||
Reference in New Issue
Block a user