-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathgenerate-scripts-json.ps1
More file actions
47 lines (37 loc) · 1.55 KB
/
generate-scripts-json.ps1
File metadata and controls
47 lines (37 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<#
.SYNOPSIS
Gera o arquivo app/scripts.json com a lista de todos os scripts SQL do repositório.
.DESCRIPTION
Percorre recursivamente o repositório, coleta todos os arquivos .sql
e gera um JSON estruturado utilizado pela app de listagem (app/index.html).
.EXAMPLE
# Rodar a partir da raiz do repositório:
.\.aux\generate-scripts-json.ps1
#>
param(
[string]$RootDir = (Split-Path $PSScriptRoot -Parent),
[string]$OutputFile = (Join-Path (Split-Path $PSScriptRoot -Parent) 'app\scripts.json')
)
$ErrorActionPreference = "Stop"
$sqlFiles = Get-ChildItem -Path $RootDir -Recurse -Filter '*.sql' |
Where-Object { $_.FullName -notmatch '[\\/]\.git[\\/]' }
$scripts = $sqlFiles | ForEach-Object {
$relativePath = [System.IO.Path]::GetRelativePath($RootDir, $_.FullName).Replace('\','/')
$parts = $relativePath -split '/'
$category = if ($parts.Count -gt 1) { $parts[0] } else { 'Root' }
$subcategory = if ($parts.Count -gt 2) { ($parts[1..($parts.Count - 2)]) -join '/' } else { '' }
[pscustomobject]@{
path = $relativePath
name = $_.Name
category = $category
subcategory = $subcategory
}
} | Sort-Object category, path
$outputDir = Split-Path $OutputFile -Parent
if (-not (Test-Path $outputDir)) {
New-Item -ItemType Directory -Path $outputDir | Out-Null
}
$scripts | ConvertTo-Json -Depth 3 | Set-Content -Path $OutputFile -Encoding UTF8
$total = @($scripts).Count
Write-Host "scripts.json gerado em: $OutputFile"
Write-Host "Total de scripts: $total"