Files
please-pay-me/mobile/run.ps1
T
2026-09-21 04:06:43 +03:00

103 lines
2.6 KiB
PowerShell

#Requires -Version 5.1
<#
.SYNOPSIS
Run the Please Pay Me Flutter app.
Config comes from mobile/.env (PPM_API_BASE_URL, PPM_WEB_URL, PPM_DEMO).
Optional -ApiBaseUrl / -WebUrl override the file for one run.
.EXAMPLE
.\run.ps1
.\run.ps1 -Device chrome
.\run.ps1 -Target widgetbook
#>
param(
[ValidateSet("chrome", "windows", "edge")]
[string]$Device = "windows",
[ValidateSet("app", "widgetbook")]
[string]$Target = "app",
[string]$ApiBaseUrl = "",
[string]$WebUrl = "",
[switch]$SkipPubGet
)
$ErrorActionPreference = "Stop"
$MobileRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
if ($Target -eq "widgetbook") {
& (Join-Path $MobileRoot "widgetbook\run.ps1") -Device $Device -SkipPubGet:$SkipPubGet
exit $LASTEXITCODE
}
Set-Location $MobileRoot
function Find-Flutter {
$cmd = Get-Command flutter -ErrorAction SilentlyContinue
if ($cmd) { return $cmd.Source }
$candidates = @(
"$env:USERPROFILE\flutter\bin\flutter.bat",
"$env:LOCALAPPDATA\flutter\bin\flutter.bat",
"C:\flutter\bin\flutter.bat",
"C:\src\flutter\bin\flutter.bat"
)
foreach ($path in $candidates) {
if (Test-Path $path) { return $path }
}
return $null
}
$flutter = Find-Flutter
if (-not $flutter) {
Write-Error "Flutter SDK not found. Add it to PATH, e.g. %USERPROFILE%\flutter\bin"
}
$envFile = Join-Path $MobileRoot ".env"
$exampleFile = Join-Path $MobileRoot ".env.example"
if (-not (Test-Path $envFile)) {
if (Test-Path $exampleFile) {
Copy-Item $exampleFile $envFile
Write-Host "Created .env from .env.example" -ForegroundColor DarkYellow
}
}
$defines = @()
if (Test-Path $envFile) {
$defines += "--dart-define-from-file=$envFile"
}
if ($ApiBaseUrl) {
$defines += "--dart-define=PPM_API_BASE_URL=$ApiBaseUrl"
if (-not $WebUrl) { $WebUrl = $ApiBaseUrl }
}
if ($WebUrl) {
$defines += "--dart-define=PPM_WEB_URL=$WebUrl"
}
if ($defines.Count -eq 0) {
$defines += "--dart-define=PPM_DEMO=true"
}
$mode = "demo (in-memory)"
if (Test-Path $envFile) { $mode = $envFile }
if ($ApiBaseUrl) { $mode = $ApiBaseUrl }
Write-Host "Flutter: $flutter" -ForegroundColor DarkGray
Write-Host "Target: app" -ForegroundColor DarkGray
Write-Host "Device: $Device" -ForegroundColor DarkGray
Write-Host "Config: $mode" -ForegroundColor DarkGray
Write-Host ""
if (-not $SkipPubGet) {
Write-Host "flutter pub get" -ForegroundColor Cyan
& $flutter pub get
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
$defineArgs = $defines -join " "
Write-Host "flutter run -d $Device $defineArgs" -ForegroundColor Cyan
& $flutter run -d $Device @defines
exit $LASTEXITCODE