Files
douyi_guaji_main/packaging/pyinstaller/build_windows.ps1
T

82 lines
2.9 KiB
PowerShell

param(
[string]$Version = "",
[switch]$SkipInstall
)
$ErrorActionPreference = "Stop"
$Root = Resolve-Path (Join-Path $PSScriptRoot "..\..")
Set-Location $Root
if (-not $Version) {
$Version = (python -c "from douyin.core.version import APP_VERSION; print(str(APP_VERSION).lstrip('Vv'))").Trim()
}
if (-not $SkipInstall) {
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install pyinstaller
}
$DistRoot = Join-Path $Root "dist\DouyinGuaji-$Version"
if (Test-Path $DistRoot) {
Remove-Item -LiteralPath $DistRoot -Recurse -Force
}
New-Item -ItemType Directory -Force $DistRoot | Out-Null
$CommonArgs = @(
"--clean",
"--noconfirm",
"--distpath", $DistRoot,
"--workpath", (Join-Path $Root "build\pyinstaller"),
"--paths", $Root,
"--add-data", "assets;assets",
"--add-data", "webui;webui",
"--add-data", "config\README.md;config",
"--hidden-import", "PIL._tkinter_finder",
"--hidden-import", "ttkbootstrap"
)
python -m PyInstaller @CommonArgs --name DouyinGuajiGUI --windowed "gui\gui_app.py"
python -m PyInstaller @CommonArgs --name web_gui --console "gui\web_gui.py"
python -m PyInstaller @CommonArgs --name run_cli --console "bin\run_cli.py"
foreach ($name in @("DouyinGuajiGUI", "web_gui", "run_cli")) {
$srcDir = Join-Path $DistRoot $name
Copy-Item -LiteralPath (Join-Path $srcDir "$name.exe") -Destination (Join-Path $DistRoot "$name.exe") -Force
$srcInternal = Join-Path $srcDir "_internal"
$dstInternal = Join-Path $DistRoot "_internal"
if (Test-Path $srcInternal) {
New-Item -ItemType Directory -Force $dstInternal | Out-Null
Copy-Item -LiteralPath (Join-Path $srcInternal "*") -Destination $dstInternal -Recurse -Force
}
Remove-Item -LiteralPath $srcDir -Recurse -Force
}
foreach ($dir in @("assets", "webui")) {
$target = Join-Path $DistRoot $dir
if (Test-Path $target) {
Remove-Item -LiteralPath $target -Recurse -Force
}
Copy-Item -LiteralPath (Join-Path $Root $dir) -Destination $target -Recurse -Force
}
New-Item -ItemType Directory -Force (Join-Path $DistRoot "config") | Out-Null
Copy-Item -LiteralPath (Join-Path $Root "config\README.md") -Destination (Join-Path $DistRoot "config\README.md") -Force
foreach ($dir in @("logs", "pic", "state")) {
$runtimeDir = Join-Path $DistRoot $dir
New-Item -ItemType Directory -Force $runtimeDir | Out-Null
New-Item -ItemType File -Force (Join-Path $runtimeDir ".keep") | Out-Null
}
$licensePath = Join-Path $Root "license.dat"
if (Test-Path $licensePath) {
Copy-Item -LiteralPath $licensePath -Destination (Join-Path $DistRoot "license.dat") -Force
}
Copy-Item -LiteralPath (Join-Path $Root "README.md") -Destination (Join-Path $DistRoot "README.md") -Force
python -m tools.distribution_manifest $DistRoot
Write-Host "[OK] Portable package: $DistRoot"
Write-Host "[NEXT] If Inno Setup is installed: iscc packaging\inno\douyin_guaji.iss /DMyAppVersion=$Version"