64 lines
2.3 KiB
PowerShell
64 lines
2.3 KiB
PowerShell
#!/usr/bin/env powershell
|
|
# -*- coding: utf-8 -*-
|
|
<#
|
|
.SYNOPSIS
|
|
壁纸更换器 - 编译脚本
|
|
.DESCRIPTION
|
|
使用 Nuitka 将 Python 源码打包为独立目录模式(--standalone)。
|
|
输出: .\dist\WallpaperChanger.exe
|
|
#>
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host " 壁纸更换器 - 编译打包 (Nuitka)" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
Write-Host "[1/5] 激活 conda 环境 ..." -ForegroundColor Yellow
|
|
conda activate 312
|
|
if ($LASTEXITCODE -ne 0) { throw "激活 conda 环境失败 (312)" }
|
|
|
|
Write-Host "[2/5] 安装编译依赖 ..." -ForegroundColor Yellow
|
|
python -m pip install nuitka --quiet
|
|
if ($LASTEXITCODE -ne 0) { throw "安装 Nuitka 失败" }
|
|
|
|
python -m pip install -r "$ScriptDir\requirements.txt" --quiet
|
|
|
|
Write-Host "[3/5] 清理旧产物 ..." -ForegroundColor Yellow
|
|
Remove-Item -Recurse -Force "$ScriptDir\dist" -ErrorAction SilentlyContinue
|
|
Remove-Item -Recurse -Force "$ScriptDir\build" -ErrorAction SilentlyContinue
|
|
|
|
Write-Host "[4/5] 生成图标(若无)..." -ForegroundColor Yellow
|
|
python -c "
|
|
import os; p = os.path.join('$ScriptDir', 'assets'); os.makedirs(p, exist_ok=True)
|
|
ico = os.path.join(p, 'icon.ico')
|
|
if not os.path.exists(ico):
|
|
from PIL import Image
|
|
img = Image.new('RGB', (64, 64), color=(66, 133, 244))
|
|
img.save(ico, format='ICO', sizes=[(16,16),(32,32),(48,48),(64,64)])
|
|
"
|
|
|
|
Write-Host "[5/5] Nuitka 打包 ..." -ForegroundColor Yellow
|
|
Set-Location -LiteralPath $ScriptDir
|
|
python -m nuitka `
|
|
--standalone `
|
|
--windows-disable-console `
|
|
--enable-plugin=anti-bloat `
|
|
--include-package=requests `
|
|
--include-package=pystray `
|
|
--include-package=PIL `
|
|
--output-dir="$ScriptDir\dist" `
|
|
--output-filename=WallpaperChanger.exe `
|
|
--assume-yes-for-downloads `
|
|
"$ScriptDir\main.py"
|
|
|
|
if ($LASTEXITCODE -ne 0) { throw "Nuitka 打包失败" }
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
Write-Host " 编译完成!" -ForegroundColor Green
|
|
Write-Host " 输出: $ScriptDir\dist\WallpaperChanger.dist\WallpaperChanger.exe" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Green
|