From 85d40b15707216d61a4b53bb1bf42277714ca1f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Thu, 20 Feb 2025 13:46:18 +0100 Subject: [PATCH] phpsg.sh: mkdir in file processing. --- phpsg.sh | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/phpsg.sh b/phpsg.sh index 3bbb026..41c0c92 100755 --- a/phpsg.sh +++ b/phpsg.sh @@ -65,33 +65,36 @@ done export OUTPUT_DIR export SOURCE_DIR -while IFS= read -r -d '' dir -do - OUT_DIR="${OUTPUT_DIR}/${dir:((${#SOURCE_DIR} + 1))}" - if ! [ -d "$OUT_DIR" ] - then - mkdir -p "$OUT_DIR" - fi -done < <(find "$SOURCE_DIR" -type d -print0) - function process_file() { - file="$1" + local file="$1" + local DEST_FILE + local DEST_DIR if [[ $file = *.php ]] then DEST_FILE="${OUTPUT_DIR}/${file:((${#SOURCE_DIR} + 1)):-4}" + DEST_DIR="$(dirname "$DEST_FILE")" if ! [ "$file" -nt "$DEST_FILE" ] then return fi + if ! [ -d "$DEST_DIR" ] + then + mkdir -p "$DEST_DIR" + fi echo -n "Generating $DEST_FILE ... " php "$file" > "$DEST_FILE" echo "done" else DEST_FILE="${OUTPUT_DIR}/${file:((${#SOURCE_DIR} + 1))}" + DEST_DIR="$(dirname "$DEST_FILE")" if ! [ "$file" -nt "$DEST_FILE" ] then return fi + if ! [ -d "$DEST_DIR" ] + then + mkdir -p "$DEST_DIR" + fi echo -n "Copying target $DEST_FILE ... " cp "$file" "$DEST_FILE" echo "done"