ConfigLoader now changes config structDir when ran

This commit is contained in:
2025-12-17 00:42:29 -07:00
parent 22e286a151
commit 11f286e87f
6 changed files with 505 additions and 296 deletions

View File

@@ -45,6 +45,11 @@ function Get-ConfigValue {
}
function Get-StructDirectory {
# When script is run directly (not dot-sourced), always use script's directory for portability
if ($MyInvocation.InvocationName -ne '.') {
return $script:LoaderRoot
}
$value = Get-ConfigValue -Name 'structDir'
if ($null -eq $value -or [string]::IsNullOrWhiteSpace($value)) {
return $script:LoaderRoot
@@ -181,9 +186,30 @@ function Get-ZipCompressionLevel {
return [Math]::Min(9, [Math]::Max(0, $value))
}
function Update-ConfigStructDir {
param(
[Parameter(Mandatory)] [string]$StructDir
)
$config = Get-ProjectStructureConfig
$config.structDir = $StructDir
try {
$json = $config | ConvertTo-Json -Depth 10
Set-Content -LiteralPath $script:ConfigPath -Value $json -NoNewline -ErrorAction Stop
$script:ConfigCache = $config
}
catch {
Write-Warning "Failed to update config.json: $($_.Exception.Message)"
}
}
# 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 '.') {
# Update config.json to use script's directory as structDir for portability
Update-ConfigStructDir -StructDir $script:LoaderRoot
$projectPath = Get-ProjectPathFromUser
if ($null -ne $projectPath) {
# Deploy batch files and config to the project