You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.1 KiB
73 lines
2.1 KiB
1 week ago
|
# 修复 npm 路径问题的启动脚本
|
||
|
param(
|
||
|
[switch]$Debug,
|
||
|
[switch]$Watch
|
||
|
)
|
||
|
|
||
|
# 设置控制台编码为 UTF-8
|
||
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||
|
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
|
||
|
$OutputEncoding = [System.Text.Encoding]::UTF8
|
||
|
|
||
|
# 设置环境变量
|
||
|
$env:VUE_CLI_BABEL_TRANSPILE_MODULES = "false"
|
||
|
$env:VUE_CLI_MODERN_BUILD = "false"
|
||
|
$env:VUE_CLI_LOG_LEVEL = "info"
|
||
|
$env:LANG = "zh_CN.UTF-8"
|
||
|
$env:LC_ALL = "zh_CN.UTF-8"
|
||
|
|
||
|
Write-Host "🔧 修复 npm 路径问题的启动脚本" -ForegroundColor Cyan
|
||
|
Write-Host ""
|
||
|
|
||
|
# 检查 Node.js 和 npm 是否可用
|
||
|
Write-Host "检查 Node.js 环境..." -ForegroundColor Yellow
|
||
|
try {
|
||
|
$nodeVersion = node --version
|
||
|
$npmVersion = npm --version
|
||
|
Write-Host "✅ Node.js: $nodeVersion" -ForegroundColor Green
|
||
|
Write-Host "✅ npm: $npmVersion" -ForegroundColor Green
|
||
|
} catch {
|
||
|
Write-Host "❌ Node.js 或 npm 未找到,请确保已正确安装" -ForegroundColor Red
|
||
|
Write-Host "请访问 https://nodejs.org 下载并安装 Node.js" -ForegroundColor Yellow
|
||
|
exit 1
|
||
|
}
|
||
|
|
||
|
# 检查依赖
|
||
|
Write-Host ""
|
||
|
Write-Host "检查依赖..." -ForegroundColor Yellow
|
||
|
if (-not (Test-Path "node_modules")) {
|
||
|
Write-Host "📦 依赖未安装,正在安装..." -ForegroundColor Yellow
|
||
|
npm install
|
||
|
if ($LASTEXITCODE -ne 0) {
|
||
|
Write-Host "❌ 依赖安装失败" -ForegroundColor Red
|
||
|
exit 1
|
||
|
}
|
||
|
}
|
||
|
|
||
|
# 预构建前端
|
||
|
Write-Host ""
|
||
|
Write-Host "预构建前端..." -ForegroundColor Yellow
|
||
|
npm run build:vue
|
||
|
if ($LASTEXITCODE -ne 0) {
|
||
|
Write-Host "❌ 前端构建失败" -ForegroundColor Red
|
||
|
exit 1
|
||
|
}
|
||
|
|
||
|
Write-Host "✅ 前端构建成功" -ForegroundColor Green
|
||
|
|
||
|
# 启动 Electron
|
||
|
Write-Host ""
|
||
|
Write-Host "启动 Electron 应用..." -ForegroundColor Green
|
||
|
|
||
|
if ($Debug) {
|
||
|
Write-Host "🐛 调试模式启动..." -ForegroundColor Magenta
|
||
|
$env:DEBUG = "*"
|
||
|
electron .
|
||
|
} elseif ($Watch) {
|
||
|
Write-Host "👀 监听模式启动..." -ForegroundColor Blue
|
||
|
npm run dev:watch
|
||
|
} else {
|
||
|
Write-Host "🚀 标准模式启动..." -ForegroundColor Green
|
||
|
electron .
|
||
|
}
|