Update Context Generator to Add Suppot for Dest Folder Recieving ...
This commit is contained in:
+40
-4
@@ -1,9 +1,45 @@
|
||||
Get-ChildItem -Recurse -File -Include Dockerfile,docker-compose.yaml,*.cs |
|
||||
param(
|
||||
[Parameter(Position = 0)]
|
||||
[string]$Path
|
||||
)
|
||||
|
||||
$timestamp = Get-Date -Format 'yyyyMMdd_HHmmss'
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($Path)) {
|
||||
# If no path is provided, use current path
|
||||
$searchPath = (Get-Location).Path
|
||||
$outputFile = ".\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 = ".\xDashboard-$safeLastFolder-$timestamp.txt"
|
||||
}
|
||||
|
||||
Get-ChildItem -LiteralPath $searchPath -Recurse -File |
|
||||
Where-Object {
|
||||
$_.DirectoryName -notmatch '\\(bin|obj)(\\|$)'
|
||||
$_.Name -eq 'Dockerfile' -or
|
||||
$_.Name -eq 'docker-compose.yaml' -or
|
||||
$_.Extension -eq '.cs'
|
||||
} |
|
||||
Where-Object {
|
||||
$_.FullName -notmatch '[\\/](bin|obj)([\\/]|$)'
|
||||
} |
|
||||
ForEach-Object {
|
||||
"`n### FILE: $($_.FullName)`n"
|
||||
Get-Content $_.FullName
|
||||
Get-Content -LiteralPath $_.FullName
|
||||
} |
|
||||
Out-File ".\xDashboard-$(Get-Date -Format 'yyyyMMdd_HHmmss').txt" -Encoding utf8
|
||||
Out-File -FilePath $outputFile -Encoding utf8
|
||||
|
||||
Write-Host "Context generated: $outputFile"
|
||||
+35
-5
@@ -2,10 +2,40 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
timestamp="$(date +%Y%m%d_%H%M%S)"
|
||||
output_file="./xDashboard-${timestamp}.txt"
|
||||
# ---------------------------------------------------------
|
||||
# Usage:
|
||||
# ./context-generator.sh
|
||||
# ./context-generator.sh /path/to/project
|
||||
# ---------------------------------------------------------
|
||||
|
||||
find . -type f \( \
|
||||
SOURCE_PATH="${1:-}"
|
||||
|
||||
if [[ -z "$SOURCE_PATH" ]]; then
|
||||
# If no path is provided, use current path
|
||||
SEARCH_PATH="."
|
||||
OUTPUT_PREFIX="xDashboard"
|
||||
else
|
||||
if [[ ! -d "$SOURCE_PATH" ]]; then
|
||||
echo "Error: path '$SOURCE_PATH' is not a directory." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Resolve absolute path
|
||||
SEARCH_PATH="$(cd "$SOURCE_PATH" && pwd)"
|
||||
|
||||
# Get last folder of the path
|
||||
LAST_FOLDER="$(basename "$SEARCH_PATH")"
|
||||
|
||||
# Optional: make folder name safe for file name
|
||||
SAFE_LAST_FOLDER="$(printf '%s' "$LAST_FOLDER" | tr -c '[:alnum:]._-' '_')"
|
||||
|
||||
OUTPUT_PREFIX="xDashboard-${SAFE_LAST_FOLDER}"
|
||||
fi
|
||||
|
||||
TIMESTAMP="$(date +%Y%m%d_%H%M%S)"
|
||||
OUTPUT_FILE="./${OUTPUT_PREFIX}-${TIMESTAMP}.txt"
|
||||
|
||||
find "$SEARCH_PATH" -type f \( \
|
||||
-name "Dockerfile" \
|
||||
-o -name "docker-compose.yaml" \
|
||||
-o -name "*.cs" \
|
||||
@@ -16,6 +46,6 @@ find . -type f \( \
|
||||
while IFS= read -r -d '' file; do
|
||||
printf '\n### FILE: %s\n\n' "$file"
|
||||
cat "$file"
|
||||
done > "$output_file"
|
||||
done > "$OUTPUT_FILE"
|
||||
|
||||
# echo "Context generated: $output_file"
|
||||
echo "Context generated: $OUTPUT_FILE"
|
||||
Reference in New Issue
Block a user