ai-courseware/openClaw/scripts/build_in_win.ps1

56 lines
2.0 KiB
PowerShell

<#
.SYNOPSIS
Run this script in Windows PowerShell to package OpenClawPrecheck.ps1 into an EXE.
.DESCRIPTION
1. Automatically detects and installs the PS2EXE module.
2. Compiles OpenClawPrecheck.ps1 into a console-less EXE.
#>
$ErrorActionPreference = "Stop"
# Get the directory of the current script
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
$sourceFile = Join-Path $scriptDir "OpenClawPrecheck.ps1"
$targetFile = Join-Path $scriptDir "OpenClawPrecheck.exe"
Write-Host "`n[1/3] Checking environment..." -ForegroundColor Cyan
# Check source file
if (-not (Test-Path $sourceFile)) {
Write-Error "Error: Source file not found: $sourceFile`nPlease ensure this script is in the same directory as OpenClawPrecheck.ps1."
exit 1
}
# Check and install PS2EXE module
if (-not (Get-Module -ListAvailable -Name PS2EXE)) {
Write-Warning "PS2EXE module not found. Installing... (Internet connection required)"
try {
# Install to current user scope, no admin rights required usually
Install-Module -Name PS2EXE -Scope CurrentUser -Force -SkipPublisherCheck
Write-Host "PS2EXE installed successfully!" -ForegroundColor Green
} catch {
Write-Error "Installation failed. Please try running PowerShell as Administrator.`nError: $_"
exit 1
}
}
Write-Host "[2/3] Packaging..." -ForegroundColor Cyan
try {
# -NoConsole: Critical parameter to hide the console window
Invoke-PS2EXE -InputFile $sourceFile `
-OutputFile $targetFile `
-NoConsole `
-Title "OpenClaw Environment Check" `
-Version "1.0.0.0" `
-Description "OpenClaw Windows 11 Pre-check Tool" `
-Verbose
} catch {
Write-Error "Packaging failed: $_"
exit 1
}
Write-Host "`n[3/3] Done!" -ForegroundColor Cyan
Write-Host "EXE generated at: $targetFile" -ForegroundColor Green
Write-Host "You can now double-click the EXE to run it." -ForegroundColor Gray