CostPrediction/scripts/build_win.ps1
2024-11-28 13:22:29 +08:00

78 lines
2.4 KiB
PowerShell

# Set console encoding to UTF-8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
# Ensure PowerShell stops on error
$ErrorActionPreference = "Stop"
# Create virtual environment
Write-Host "Creating virtual environment..."
python -m venv .venv
.\.venv\Scripts\Activate.ps1
# Install dependencies
Write-Host "Installing dependencies..."
pip install -e .
# Build frontend
Write-Host "Building frontend..."
Push-Location frontend
npm install
npm run build
Copy-Item dist/* . -Recurse -Force
Remove-Item dist -Recurse -Force
Pop-Location
# Package with PyInstaller
Write-Host "Starting packaging..."
# Create necessary directories
New-Item -ItemType Directory -Force -Path "logs"
New-Item -ItemType Directory -Force -Path "data"
New-Item -ItemType Directory -Force -Path "models"
pyinstaller --clean `
--add-data "src/loitering_munition_data.sql;data" `
--add-data "src/rocket_artillery_data.sql;data" `
--add-data "src/manufacturer_data.sql;data" `
--add-data "src/schema.sql;data" `
--add-data "config.py;." `
--add-data "src;src" `
--add-data "frontend;frontend" `
--add-data "logs;logs" `
--add-data "data;data" `
--add-data "models;models" `
--collect-all "xgboost" `
--collect-all "lightgbm" `
--collect-all "torch" `
--collect-all "sklearn" `
--collect-all "numpy" `
--collect-all "pandas" `
--collect-all "sqlalchemy" `
--collect-all "pymysql" `
--collect-all "cryptography" `
--collect-all "flask" `
--collect-all "flask_cors" `
--hidden-import "xgboost.testing" `
--hidden-import "torch.utils.tensorboard" `
--hidden-import "pytest" `
run.py
# Copy necessary files
Write-Host "Copying configuration files..."
Copy-Item "src/start.bat" -Destination "dist/run"
# Create release package
Write-Host "Creating release package..."
$version = (Get-Content pyproject.toml | Select-String 'version = "(.*?)"').Matches.Groups[1].Value
# Create complete offline installation package directory
$RELEASE_DIR = "dist/release"
New-Item -ItemType Directory -Force -Path $RELEASE_DIR
# Copy application files
Copy-Item "dist/run/*" -Destination $RELEASE_DIR -Recurse
# Create final zip package
Compress-Archive -Path "$RELEASE_DIR/*" -DestinationPath "cost-prediction-$version-win64.zip" -Force
Write-Host "Package completed: cost-prediction-$version-win64.zip"