102 lines
3.1 KiB
Bash
Executable File
102 lines
3.1 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
|
|
|
|
# Nastavitev imena izhodne datoteke
|
|
OUTPUT_FILE="${1:-code_export.txt}"
|
|
|
|
# Odstrani izhodno datoteko, če že obstaja, da začnemo s čisto datoteko
|
|
if [ -f "$OUTPUT_FILE" ]; then
|
|
rm "$OUTPUT_FILE"
|
|
fi
|
|
|
|
# Poišči vse datoteke, razen skritih datotek in določenih map (npr. node_modules).
|
|
# Dodane so izjeme za slike, videoposnetke, PDF-je, arhive in druge binarne datoteke
|
|
# neposredno v ukaz 'find' za boljšo zmogljivost.
|
|
find . -type f \
|
|
-not -path "*/\.*" \
|
|
-not -path "*node_modules*" \
|
|
-not -path "*vendor*" \
|
|
-not -path "*dist*" \
|
|
-not -path "*build*" \
|
|
-not -path "*/images/*" \
|
|
-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 read -r file; do
|
|
|
|
# Preskoči samo izhodno datoteko in to skripto
|
|
if [[ "$file" == "./$OUTPUT_FILE" || "$file" == "./export_code.sh" || "$file" == "./export_code.ps1" ]]; then
|
|
continue
|
|
fi
|
|
|
|
# Dodatna varnostna preverba: preskoči slikovne datoteke po MIME tipu
|
|
if file --mime-type -b "$file" | grep -qiE '^(image)/'; then
|
|
continue
|
|
fi
|
|
|
|
# Dodaj ime datoteke in njeno vsebino v izhodno datoteko
|
|
echo "\"$file\" : " >> "$OUTPUT_FILE"
|
|
echo "\"\"\"" >> "$OUTPUT_FILE"
|
|
cat "$file" >> "$OUTPUT_FILE"
|
|
echo "\"\"\"" >> "$OUTPUT_FILE"
|
|
echo "" >> "$OUTPUT_FILE"
|
|
echo "" >> "$OUTPUT_FILE"
|
|
done
|
|
|
|
echo "Izvoz kode končan. Vsebina je shranjena v datoteko $OUTPUT_FILE"
|