support configloader deployment
This commit is contained in:
106
ConfigLoader.ps1
106
ConfigLoader.ps1
@@ -85,14 +85,84 @@ function Get-ProjectsRoot {
|
||||
return $candidate
|
||||
}
|
||||
|
||||
function Get-ProjectPathFromUser {
|
||||
param(
|
||||
[string]$Prompt = "Paste the project path to deploy in"
|
||||
)
|
||||
|
||||
do {
|
||||
$inputPath = Read-Host -Prompt $Prompt
|
||||
if ([string]::IsNullOrWhiteSpace($inputPath)) {
|
||||
Write-Warning "Path cannot be empty. Please try again."
|
||||
continue
|
||||
}
|
||||
|
||||
# Remove quotes if present
|
||||
$inputPath = $inputPath.Trim('"', "'")
|
||||
|
||||
# Try to resolve the path
|
||||
try {
|
||||
if (Test-Path -LiteralPath $inputPath -PathType Container) {
|
||||
$resolved = Resolve-Path -LiteralPath $inputPath -ErrorAction Stop
|
||||
return $resolved.Path
|
||||
}
|
||||
else {
|
||||
Write-Warning "Path does not exist or is not a directory: $inputPath"
|
||||
$retry = Read-Host "Try again? (Y/N)"
|
||||
if ($retry -notmatch '^[Yy]') {
|
||||
return $null
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Warning "Invalid path: $($_.Exception.Message)"
|
||||
$retry = Read-Host "Try again? (Y/N)"
|
||||
if ($retry -notmatch '^[Yy]') {
|
||||
return $null
|
||||
}
|
||||
}
|
||||
} while ($true)
|
||||
}
|
||||
|
||||
function Use-IsoDailyFormat {
|
||||
$dailyFormat = Get-ConfigValue -Name 'dailyFormat' -Default $true
|
||||
return [bool]$dailyFormat
|
||||
|
||||
# Handle backward compatibility with boolean values
|
||||
if ($dailyFormat -is [bool]) {
|
||||
return $dailyFormat
|
||||
}
|
||||
|
||||
# Handle string values
|
||||
if ($dailyFormat -is [string]) {
|
||||
$formatStr = $dailyFormat.Trim()
|
||||
# ISO format contains YYYY-MM-DD pattern
|
||||
if ($formatStr -match 'YYYY-MM-DD' -or $formatStr -match '\d{4}-\d{2}-\d{2}') {
|
||||
return $true
|
||||
}
|
||||
# daily_YYMMDD or other formats are not ISO
|
||||
return $false
|
||||
}
|
||||
|
||||
# Default to false (not ISO format) for unknown types
|
||||
return $false
|
||||
}
|
||||
|
||||
function Use-7Zip {
|
||||
$zipper = Get-ConfigValue -Name 'zipper' -Default $true
|
||||
return [bool]$zipper
|
||||
|
||||
# Handle backward compatibility with boolean values
|
||||
if ($zipper -is [bool]) {
|
||||
return $zipper
|
||||
}
|
||||
|
||||
# Handle string values
|
||||
if ($zipper -is [string]) {
|
||||
$zipperStr = $zipper.Trim().ToLower()
|
||||
return ($zipperStr -eq '7z')
|
||||
}
|
||||
|
||||
# Default to false (use zip) for unknown types
|
||||
return $false
|
||||
}
|
||||
|
||||
function Get-ZipCompressionLevel {
|
||||
@@ -111,3 +181,35 @@ function Get-ZipCompressionLevel {
|
||||
return [Math]::Min(9, [Math]::Max(0, $value))
|
||||
}
|
||||
|
||||
# If script is run directly (not dot-sourced), prompt for project path and deploy
|
||||
# When dot-sourced, InvocationName is '.'; when run directly, it's the script path or name
|
||||
if ($MyInvocation.InvocationName -ne '.') {
|
||||
$projectPath = Get-ProjectPathFromUser
|
||||
if ($null -ne $projectPath) {
|
||||
Write-Host "`nDeploying to: $projectPath" -ForegroundColor Cyan
|
||||
|
||||
# Find UpdateProjectBatches.ps1 in the same directory as ConfigLoader.ps1
|
||||
$updateScript = Join-Path -Path $script:LoaderRoot -ChildPath 'UpdateProjectBatches.ps1'
|
||||
if (Test-Path -LiteralPath $updateScript) {
|
||||
Write-Host "Running UpdateProjectBatches.ps1...`n" -ForegroundColor Yellow
|
||||
& powershell -NoProfile -ExecutionPolicy Bypass -File $updateScript -ProjectPath $projectPath
|
||||
$exitCode = $LASTEXITCODE
|
||||
if ($exitCode -eq 0) {
|
||||
Write-Host "`nDeployment completed successfully." -ForegroundColor Green
|
||||
}
|
||||
else {
|
||||
Write-Host "`nDeployment completed with errors (exit code: $exitCode)." -ForegroundColor Red
|
||||
}
|
||||
exit $exitCode
|
||||
}
|
||||
else {
|
||||
Write-Warning "UpdateProjectBatches.ps1 not found in $script:LoaderRoot"
|
||||
Write-Host "Project path: $projectPath" -ForegroundColor Green
|
||||
return $projectPath
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Host "No project path provided." -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user