-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnapshot-structure.ps1
More file actions
192 lines (164 loc) · 5.38 KB
/
snapshot-structure.ps1
File metadata and controls
192 lines (164 loc) · 5.38 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<#
.SYNOPSIS
Generuje plik Markdown ze struktura katalogow i plikow projektu.
.DESCRIPTION
Skrypt skanuje katalog glowny projektu i tworzy plik .md z drzewem struktury.
Automatycznie wykrywa katalog glowny nawet gdy uruchamiany z podkatalogu _scripts/.
Plik wynikowy jest zapisywany w katalogu _project_snapshots z timestampem w nazwie.
.NOTES
Autor: DominDev
Kodowanie: UTF-8 with BOM
#>
[CmdletBinding()]
param(
[string]$OutputDir = "_project_snapshots"
)
# Wymuszenie UTF-8 z BOM
$OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# === AUTODETEKCJA KATALOGU GLOWNEGO PROJEKTU ===
$ScriptDir = if ($PSScriptRoot) { $PSScriptRoot } else { (Get-Location).Path }
$CurrentDirName = Split-Path $ScriptDir -Leaf
# Jesli skrypt jest w katalogu zaczynajacym sie od "_", przejdz do parenta
if ($CurrentDirName -match '^_') {
$ProjectPath = Split-Path $ScriptDir -Parent
Write-Host "Wykryto uruchomienie z podkatalogu '$CurrentDirName'" -ForegroundColor DarkGray
Write-Host "Katalog glowny projektu: $ProjectPath" -ForegroundColor DarkGray
} else {
$ProjectPath = $ScriptDir
}
# === KATALOGI I PLIKI DO WYKLUCZENIA ===
# Katalogi do wykluczenia (statyczna lista)
$ExcludedDirsStatic = @(
'.git',
'.claude',
'node_modules',
'.vscode',
'.idea',
'__pycache__',
'vendor',
'dist',
'build',
'.next',
'.nuxt'
)
$ExcludedFiles = @(
'.gitignore',
'.gitattributes',
'.gitmodules',
'.env',
'.env.local',
'.env.production',
'.DS_Store',
'Thumbs.db',
'desktop.ini',
'nul',
'*.log',
'package-lock.json',
'yarn.lock',
'composer.lock',
'snapshot_structure.ps1',
'snapshot_code.ps1'
)
$ExcludedExtensions = @(
'.exe', '.dll', '.so', '.dylib',
'.zip', '.tar', '.gz', '.rar', '.7z',
'.jpg', '.jpeg', '.png', '.gif', '.webp', '.ico', '.svg', '.bmp',
'.mp3', '.mp4', '.avi', '.mov', '.wav',
'.pdf', '.doc', '.docx', '.xls', '.xlsx',
'.ttf', '.woff', '.woff2', '.eot', '.otf'
)
# Funkcja sprawdzajaca czy plik/katalog jest wykluczony
function Test-IsExcluded {
param(
[string]$Name,
[string]$FullPath,
[bool]$IsDirectory
)
if ($IsDirectory) {
# Wyklucz katalogi z prefixem "_" (np. _docs, _scripts, _project_snapshots)
if ($Name -match '^_') { return $true }
# Wyklucz katalogi ze statycznej listy
return $ExcludedDirsStatic -contains $Name
}
# Sprawdz nazwe pliku
foreach ($pattern in $ExcludedFiles) {
if ($pattern.Contains('*')) {
if ($Name -like $pattern) { return $true }
} else {
if ($Name -eq $pattern) { return $true }
}
}
# Sprawdz rozszerzenie
$ext = [System.IO.Path]::GetExtension($Name).ToLower()
if ($ExcludedExtensions -contains $ext) { return $true }
return $false
}
# Funkcja budujaca drzewo struktury
function Get-DirectoryTree {
param(
[string]$Path,
[string]$Prefix = "",
[string]$RelativePath = "."
)
$output = @()
try {
$items = Get-ChildItem -Path $Path -Force -ErrorAction SilentlyContinue |
Where-Object { -not (Test-IsExcluded -Name $_.Name -FullPath $_.FullName -IsDirectory $_.PSIsContainer) } |
Sort-Object { -not $_.PSIsContainer }, Name
}
catch {
return $output
}
$count = $items.Count
$index = 0
foreach ($item in $items) {
$index++
$isLast = ($index -eq $count)
if ($isLast) {
$connector = [char]0x2514 + [string][char]0x2500 + [string][char]0x2500 + " " # L--
$newPrefix = $Prefix + " "
} else {
$connector = [char]0x251C + [string][char]0x2500 + [string][char]0x2500 + " " # |--
$newPrefix = $Prefix + [char]0x2502 + " " # |
}
$itemRelPath = Join-Path $RelativePath $item.Name
if ($item.PSIsContainer) {
$output += "$Prefix$connector$($item.Name)/"
$output += Get-DirectoryTree -Path $item.FullName -Prefix $newPrefix -RelativePath $itemRelPath
} else {
$output += "$Prefix$connector$($item.Name)"
}
}
return $output
}
# Utworz katalog wyjsciowy jesli nie istnieje
$outputPath = Join-Path $ProjectPath $OutputDir
if (-not (Test-Path $outputPath)) {
New-Item -ItemType Directory -Path $outputPath -Force | Out-Null
Write-Host "Utworzono katalog: $OutputDir" -ForegroundColor Green
}
# Generuj timestamp
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$outputFile = Join-Path $outputPath "structure_$timestamp.md"
# Pobierz nazwe projektu
$projectName = Split-Path $ProjectPath -Leaf
# Buduj zawartosc pliku MD
$content = @()
$content += "# Struktura projektu: $projectName"
$content += ""
$content += "Data wygenerowania: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
$content += ""
$content += '```'
$content += "$projectName/"
$content += (Get-DirectoryTree -Path $ProjectPath)
$content += '```'
$content += ""
$content += "---"
$content += "*Wygenerowano automatycznie przez snapshot_structure.ps1*"
# Zapisz plik z kodowaniem UTF-8 BOM
$content -join "`r`n" | Out-File -FilePath $outputFile -Encoding UTF8
Write-Host ""
Write-Host "Struktura projektu zapisana do:" -ForegroundColor Cyan
Write-Host $outputFile -ForegroundColor Yellow
Write-Host ""