major refactor

- change autogenerated folder to autodocs/httpyac
- renamed many environment variables
- add config section to env template to manage different apps
- cleanup bruno environments for easier automation of env files
- add pre-request and post-response scripts from bruno
- manage EFTL-specific scripts
- add scripts to setup json template
- add scripts to update environment files
This commit is contained in:
2026-07-14 13:32:59 +02:00
parent 09ff0cacad
commit ca9ba75c21
18 changed files with 368 additions and 88 deletions
+121
View File
@@ -0,0 +1,121 @@
# Percorsi file
$inputJsonPath = Join-Path $PSScriptRoot ".." "env.json.template" # JSON originale
$outputJsonPath = Join-Path $PSScriptRoot ".." "env.json" # JSON di destinazione
# Lettura JSON originale mantenendo l'ordine
$rawJson = Get-Content $inputJsonPath -Raw
$parsedJson = $rawJson | ConvertFrom-Json -AsHashtable
# Se env.json esiste, lo carico per preservare le sezioni non aggiornate
$existingEnv = $null
if (Test-Path $outputJsonPath) {
$existingEnv = (Get-Content $outputJsonPath -Raw) | ConvertFrom-Json -AsHashtable
}
# Funzione per chiedere Y|S/N
function Ask-YesNo($message) {
while ($true) {
$resp = Read-Host "$message [YySs/Nn]"
switch ($resp.ToUpper()) {
"Y" { return $true }
"S" { return $true }
default { return $false }
}
}
}
# Funzione per chiedere un valore
function Ask-Value($key) {
return Read-Host "Valore per '$key' (digita `"`" per inserire stringa vuota e lascia vuoto per NON aggiornare)"
}
# Copia profonda preservando ordine
$newJson = [ordered]@{}
foreach ($topKey in $parsedJson.Keys) {
if ($topKey -eq "Config") {
# Copia Config senza modifiche, i parametri serviranno dopo la generazione
$newJson["Config"] = $parsedJson["Config"]
continue
}
# Sezione API → trattamento speciale
if ($topKey -eq "API") {
$newJson["API"] = [ordered]@{}
foreach ($sectionName in $parsedJson["API"].Keys) {
$section = $parsedJson["API"][$sectionName]
$shouldConfigure = Ask-YesNo "Vuoi configurare la sezione '$sectionName'?"
# Se NON voglio configurare → devo distinguere:
if (-not $shouldConfigure) {
Write-Host "Sezione '$sectionName' non configurata. Mantengo valori esistenti, se presenti." -ForegroundColor Yellow
# 1. Se NON esiste già env.json → creo sezione vuota uguale al template
if (-not $existingEnv) {
$newJson["API"][$sectionName] = $section
continue
}
# 2. Se esiste già env.json e sia API che la sezione sono presenti → mantengo la versione esistente
if ($existingEnv["API"] -and $existingEnv["API"].Contains($sectionName)) {
$newJson["API"][$sectionName] = $existingEnv["API"][$sectionName]
continue
}
# 3. Se esiste già env.json, ma API o la sezione non sono presenti → creo sezione vuota uguale al template
$newJson["API"][$sectionName] = $section
continue
}
# Altrimenti creo una nuova sezione (o aggiorno quella esistente)
$newSection = [ordered]@{}
foreach ($key in $section.Keys) {
if ($key -eq "_httpyac_only") {
# Mantieni la chiave speciale senza chiedere input
$newSection[$key] = $section[$key]
continue
}
$inputValue = Ask-Value $key
if ($existingEnv -and $existingEnv["API"] -and $existingEnv["API"].Contains($sectionName)) {
$oldValue = $existingEnv["API"][$sectionName][$key]
}
else {
$oldValue = ""
}
if ($inputValue -eq "") {
# Mantieni valore esistente se presente
$newSection[$key] = $oldValue
}
elseif ($inputValue -eq "`"`"") {
# Aggiorna con stringa vuota
$newSection[$key] = ""
}
else {
# Aggiorna con nuovo valore
$newSection[$key] = $inputValue
}
}
$newJson["API"][$sectionName] = $newSection
}
}
else {
# Altri elementi allo stesso livello di API → preservati integralmente
if ($existingEnv -and $existingEnv.Contains($topKey)) {
$newJson[$topKey] = $existingEnv[$topKey]
} else {
$newJson[$topKey] = $parsedJson[$topKey]
}
}
}
# Scrittura JSON finale mantenendo l'ordine
$newJson | ConvertTo-Json -Depth 20 | Set-Content $outputJsonPath -Encoding UTF8
Write-Host "`nFile env.json aggiornato correttamente."