support configloader deployment
This commit is contained in:
File diff suppressed because one or more lines are too long
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
# Refresh helper batch scripts within a specific project directory.
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
param(
|
||||
[string]$ProjectPath
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
if (-not $PSScriptRoot) {
|
||||
$PSScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
}
|
||||
@@ -101,7 +101,7 @@ foreach ($spec in $specs) {
|
||||
foreach ($target in $targets) {
|
||||
try {
|
||||
Copy-Item -Path $spec.Source -Destination $target.FullName -Force
|
||||
Write-Host "✓ $($target.FullName)" -ForegroundColor Green
|
||||
Write-Host "[OK] $($target.FullName)" -ForegroundColor Green
|
||||
$updated++
|
||||
|
||||
$targetDir = $target.Directory.FullName
|
||||
@@ -111,14 +111,14 @@ foreach ($spec in $specs) {
|
||||
Copy-Item -Path $asset.Source -Destination (Join-Path -Path $targetDir -ChildPath $asset.Name) -Force
|
||||
}
|
||||
catch {
|
||||
Write-Host " ✗ Failed to copy $($asset.Name) into $targetDir: $($_.Exception.Message)" -ForegroundColor Red
|
||||
Write-Host " [FAIL] Failed to copy $($asset.Name) into ${targetDir}: $($_.Exception.Message)" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
$touchedDirs[$targetDir] = $true
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Host "✗ $($target.FullName)" -ForegroundColor Red
|
||||
Write-Host "[FAIL] $($target.FullName)" -ForegroundColor Red
|
||||
Write-Host " $($_.Exception.Message)" -ForegroundColor DarkRed
|
||||
$failed++
|
||||
}
|
||||
@@ -129,7 +129,7 @@ foreach ($spec in $specs) {
|
||||
Updated = $updated
|
||||
Failed = $failed
|
||||
Skipped = 0
|
||||
Total = $targets.Count
|
||||
Total = @($targets).Count
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"dailyFormat": "daily_YYMMDD",
|
||||
"structDir": "T:\\3 ProjectStructure",
|
||||
"structDir": "A:\\1 Amazon_Active_Projects\\3 ProjectStructure",
|
||||
"zipper": "7z",
|
||||
"compression": 9
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user