-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdump-project.ps1
More file actions
109 lines (88 loc) · 2.57 KB
/
Copy pathdump-project.ps1
File metadata and controls
109 lines (88 loc) · 2.57 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
# dump-project.ps1
# Run from project root:
# powershell -ExecutionPolicy Bypass -File .\dump-project.ps1
$ErrorActionPreference = "Stop"
$Root = (Get-Location).Path
$OutputFile = Join-Path $Root "_project_dump.txt"
if (Test-Path -LiteralPath $OutputFile) {
Remove-Item -LiteralPath $OutputFile -Force
}
$ExcludeDirs = @(
".git",
"node_modules",
".next",
"dist",
"build",
".vercel",
"coverage"
)
$BinaryExtensions = @(
".png", ".jpg", ".jpeg", ".gif", ".webp", ".ico",
".mp4", ".mov", ".avi", ".mkv",
".mp3", ".wav",
".pdf", ".zip", ".rar", ".7z",
".exe", ".dll", ".bin",
".woff", ".woff2", ".ttf", ".otf"
)
$header = @"
PROJECT DUMP
ROOT: $Root
DATE: $(Get-Date -Format "yyyy-MM-dd HH:mm:ss")
============================================================
"@
[System.IO.File]::WriteAllText($OutputFile, $header, [System.Text.Encoding]::UTF8)
$Files = Get-ChildItem -LiteralPath $Root -Recurse -File -Force | Where-Object {
$fullPath = $_.FullName
if ($fullPath -eq $OutputFile) {
return $false
}
if (-not $fullPath.StartsWith($Root, [System.StringComparison]::OrdinalIgnoreCase)) {
return $false
}
foreach ($dir in $ExcludeDirs) {
if ($fullPath -like "*\$dir\*") {
return $false
}
}
return $true
}
foreach ($File in $Files) {
$relativePath = $File.FullName.Substring($Root.Length).TrimStart("\", "/")
$extension = $File.Extension.ToLowerInvariant()
$fileHeader = @"
============================================================
FILE PATH:
$relativePath
FULL PATH:
$($File.FullName)
SIZE:
$($File.Length) bytes
============================================================
"@
[System.IO.File]::AppendAllText($OutputFile, $fileHeader, [System.Text.Encoding]::UTF8)
if ($BinaryExtensions -contains $extension) {
[System.IO.File]::AppendAllText(
$OutputFile,
"[BINARY FILE SKIPPED]" + [Environment]::NewLine,
[System.Text.Encoding]::UTF8
)
continue
}
try {
$content = [System.IO.File]::ReadAllText($File.FullName, [System.Text.Encoding]::UTF8)
[System.IO.File]::AppendAllText(
$OutputFile,
$content + [Environment]::NewLine,
[System.Text.Encoding]::UTF8
)
}
catch {
[System.IO.File]::AppendAllText(
$OutputFile,
"[READ ERROR: " + $_.Exception.Message + "]" + [Environment]::NewLine,
[System.Text.Encoding]::UTF8
)
}
}
Write-Host "Done. File created:"
Write-Host $OutputFile