Files
xSaherelmWorkspace/ContextGenerator.ps1
T
2026-08-11 22:10:12 +03:30

49 lines
1.4 KiB
PowerShell

param(
[Parameter(Position = 0)]
[string]$Path
)
$timestamp = Get-Date -Format 'yyyyMMdd_HHmmss'
$outputFile = ".\Documents\GeneratedContext\xDashboard-$timestamp.txt"
if ([string]::IsNullOrWhiteSpace($Path)) {
# If no path is provided, use current path
$searchPath = (Get-Location).Path
$outputFile = ".\Documents\GeneratedContext\xDashboard-$timestamp.txt"
}
else {
if (-not (Test-Path -LiteralPath $Path -PathType Container)) {
throw "Path '$Path' is not a directory."
}
# Resolve path
$searchPath = (Resolve-Path -LiteralPath $Path).Path
# Get last folder of the path
$lastFolder = Split-Path -Path $searchPath -Leaf
# Make folder name safe for file name
$safeLastFolder = $lastFolder -replace '[\\/:*?"<>|]', '_'
$outputFile = ".\Documents\GeneratedContext\xDashboard-$safeLastFolder-$timestamp.txt"
}
Get-ChildItem -LiteralPath $searchPath -Recurse -File |
Where-Object {
$_.Name -eq 'Dockerfile' -or
$_.Name -eq 'docker-compose.yaml' -or
$_.Extension -eq '.cs' -or
$_.Extension -eq '.ts' -or
$_.Extension -eq '.html' -or
$_.Extension -eq '.scss'
} |
Where-Object {
$_.FullName -notmatch '[\\/](bin|obj|dist|node_modules)([\\/]|$)'
} |
ForEach-Object {
"`n### FILE: $($_.FullName)`n"
Get-Content -LiteralPath $_.FullName
} |
Out-File -FilePath $outputFile -Encoding utf8
Write-Host "Context generated: $outputFile"