fix: build.ps1 pkg PATH 修复 + gen-authcode pkg路径兼容
This commit is contained in:
parent
b06f6cc582
commit
ee8fa10fdc
@ -96,13 +96,16 @@ if ($buildAdmin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# 安装/检查 pkg
|
# 安装/检查 pkg
|
||||||
$pkgCmd = Get-Command pkg -ErrorAction SilentlyContinue
|
# 优先找 npm global bin 目录下的 pkg(不依赖 PATH 是否刷新)
|
||||||
|
$npmGlobalBin = Join-Path (npm root -g 2>$null) "..\pkg.cmd" | Resolve-Path -ErrorAction SilentlyContinue
|
||||||
|
$pkgCmd = if ($npmGlobalBin) { $npmGlobalBin.Path } else { (Get-Command pkg -ErrorAction SilentlyContinue)?.Source }
|
||||||
if (-not $pkgCmd) {
|
if (-not $pkgCmd) {
|
||||||
Write-Warn "pkg 未安装,正在安装..."
|
Write-Warn "pkg 未安装,正在安装..."
|
||||||
npm install -g pkg
|
npm install -g pkg
|
||||||
# 刷新 PATH
|
|
||||||
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" +
|
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" +
|
||||||
[System.Environment]::GetEnvironmentVariable("Path","User")
|
[System.Environment]::GetEnvironmentVariable("Path","User")
|
||||||
|
$npmGlobalBin = Join-Path (npm root -g 2>$null) "..\pkg.cmd" | Resolve-Path -ErrorAction SilentlyContinue
|
||||||
|
$pkgCmd = $npmGlobalBin.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
$inputJs = Join-Path $ScriptDir "gen-authcode.js"
|
$inputJs = Join-Path $ScriptDir "gen-authcode.js"
|
||||||
@ -117,7 +120,7 @@ if ($buildAdmin) {
|
|||||||
Write-Host " 输出: $outputExe" -ForegroundColor Gray
|
Write-Host " 输出: $outputExe" -ForegroundColor Gray
|
||||||
Write-Host " (内嵌 Node.js 运行时,首次打包约 1 分钟)" -ForegroundColor Gray
|
Write-Host " (内嵌 Node.js 运行时,首次打包约 1 分钟)" -ForegroundColor Gray
|
||||||
|
|
||||||
pkg $inputJs --targets node18-win-x64 --output $outputExe 2>&1 |
|
& $pkgCmd $inputJs --targets node18-win-x64 --output $outputExe 2>&1 |
|
||||||
ForEach-Object { Write-Host " $_" -ForegroundColor Gray }
|
ForEach-Object { Write-Host " $_" -ForegroundColor Gray }
|
||||||
|
|
||||||
if (Test-Path $outputExe) {
|
if (Test-Path $outputExe) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user