94 lines
2.8 KiB
Bash
Executable File
94 lines
2.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
run_powershell_export() {
|
|
local ps_script="$SCRIPT_DIR/export_code.ps1"
|
|
|
|
if command -v pwsh >/dev/null 2>&1; then
|
|
pwsh -NoLogo -NoProfile -ExecutionPolicy Bypass -File "$ps_script" "$@"
|
|
return
|
|
fi
|
|
|
|
if command -v powershell.exe >/dev/null 2>&1; then
|
|
if command -v cygpath >/dev/null 2>&1; then
|
|
powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -File "$(cygpath -w "$ps_script")" "$@"
|
|
else
|
|
powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -File "$ps_script" "$@"
|
|
fi
|
|
return
|
|
fi
|
|
|
|
echo "PowerShell was not found. Run export_code.ps1 manually." >&2
|
|
exit 1
|
|
}
|
|
|
|
case "$(uname -s 2>/dev/null || printf '')" in
|
|
CYGWIN*|MINGW*|MSYS*)
|
|
run_powershell_export "$@"
|
|
exit 0
|
|
;;
|
|
esac
|
|
|
|
if [[ "${OS:-}" == "Windows_NT" ]]; then
|
|
run_powershell_export "$@"
|
|
exit 0
|
|
fi
|
|
|
|
OUTPUT_FILE="${1:-code_export.txt}"
|
|
OUTPUT_PATH="$SCRIPT_DIR/$OUTPUT_FILE"
|
|
|
|
rm -f "$OUTPUT_PATH"
|
|
|
|
find "$SCRIPT_DIR" -type f \
|
|
-not -path "*/\.*" \
|
|
-not -path "*/node_modules/*" \
|
|
-not -path "*/vendor/*" \
|
|
-not -path "*/dist/*" \
|
|
-not -path "*/build/*" \
|
|
-not -path "*/images/*" \
|
|
-not -name "code_export*.txt" \
|
|
-not -name "gitea-token*.txt" \
|
|
-not -name "gitea-token*.txt.sig" \
|
|
-not -name "export_code.sh" \
|
|
-not -name "export_code.ps1" \
|
|
-not -iname "*.jpg" -not -iname "*.jpeg" \
|
|
-not -iname "*.png" -not -iname "*.gif" \
|
|
-not -iname "*.bmp" -not -iname "*.tiff" \
|
|
-not -iname "*.svg" -not -iname "*.ico" \
|
|
-not -iname "*.webp" \
|
|
-not -iname "*.mp4" -not -iname "*.mov" \
|
|
-not -iname "*.avi" -not -iname "*.mkv" \
|
|
-not -iname "*.webm" \
|
|
-not -iname "*.mp3" -not -iname "*.wav" \
|
|
-not -iname "*.ogg" -not -iname "*.flac" \
|
|
-not -iname "*.pdf" \
|
|
-not -iname "*.zip" -not -iname "*.tar" \
|
|
-not -iname "*.gz" -not -iname "*.bz2" \
|
|
-not -iname "*.rar" -not -iname "*.7z" \
|
|
-not -iname "*.doc" -not -iname "*.docx" \
|
|
-not -iname "*.xls" -not -iname "*.xlsx" \
|
|
-not -iname "*.ppt" -not -iname "*.pptx" \
|
|
-not -iname "*.eot" -not -iname "*.ttf" \
|
|
-not -iname "*.woff" -not -iname "*.woff2" \
|
|
| sort | while IFS= read -r file; do
|
|
|
|
rel_path="./${file#"$SCRIPT_DIR"/}"
|
|
|
|
if file --mime-type -b "$file" | grep -qiE '^(image|video|audio|application/octet-stream)'; then
|
|
continue
|
|
fi
|
|
|
|
printf '"%s" : \n' "$rel_path" >> "$OUTPUT_PATH"
|
|
printf '"""\n' >> "$OUTPUT_PATH"
|
|
cat "$file" >> "$OUTPUT_PATH"
|
|
if [[ -n "$(tail -c 1 "$file" 2>/dev/null || true)" ]]; then
|
|
printf '\n' >> "$OUTPUT_PATH"
|
|
fi
|
|
printf '"""\n\n\n' >> "$OUTPUT_PATH"
|
|
done
|
|
|
|
echo "Code export finished. Output saved to $OUTPUT_PATH"
|