types: Update sync-types.sh to improve header management and file copying logic

This commit is contained in:
Carlos Santos 2025-03-11 16:11:06 +01:00
parent ec8f930407
commit 84e5db7309

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
HEADER_KEY="THIS HEADER IS AUTOGENERATED. DO NOT MODIFY MANUALLY." HEADER_KEY="THIS HEADER IS AUTOGENERATED. DO NOT MODIFY MANUALLY."
HEADER="/** $HEADER_KEY For any changes, please update the '/openvidu-meet/types' directory. */" HEADER="/** $HEADER_KEY For any changes, please update the '/openvidu-meet/types' directory. */"
@ -16,48 +16,35 @@ add_headers() {
done done
} }
remove_headers() { copy_files_with_headers() {
TARGET_DIR="$1"
mkdir -p "$TARGET_DIR"
find "$SOURCE_DIR" -type f -name "*.ts" | while IFS= read -r file; do find "$SOURCE_DIR" -type f -name "*.ts" | while IFS= read -r file; do
if grep -qF "$HEADER_KEY" "$file"; then RELATIVE_PATH="${file#$SOURCE_DIR/}"
awk -v header_key="$HEADER_KEY" ' DEST_FILE="$TARGET_DIR/$RELATIVE_PATH"
BEGIN { skip = 0 }
{ mkdir -p "$(dirname "$DEST_FILE")"
if (skip) {
if ($0 ~ /^$/) { skip = 0 } printf "%s\n\n%s" "$HEADER" "$(cat "$file")" >"$DEST_FILE"
next
}
if ($0 ~ /^\/\*\* .*'"$HEADER_KEY"'.*\*\/$/) {
skip = 1
next
}
print
}
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
fi
done done
} }
if [[ $1 == "ce" ]]; then if [ "$1" = "ce" ]; then
TARGET_DIRS=("$FRONTEND_DIR" "$BACKEND_DIR") TARGET_DIRS="$FRONTEND_DIR $BACKEND_DIR"
elif [[ $1 == "pro" ]]; then elif [ "$1" = "pro" ]; then
TARGET_DIRS=("$TYPES_DIR") TARGET_DIRS="$TYPES_DIR"
else else
echo "No argument provided. Copying to both CE and PRO" echo "No argument provided. Copying to both CE and PRO"
TARGET_DIRS=("$FRONTEND_DIR" "$BACKEND_DIR" "$TYPES_DIR") TARGET_DIRS="$FRONTEND_DIR $BACKEND_DIR $TYPES_DIR"
fi fi
echo "Adding autogenerated comments to files..."
add_headers
echo "Copying files to target directories..." echo "Copying files to target directories..."
for TARGET_DIR in "${TARGET_DIRS[@]}"; do for TARGET_DIR in $TARGET_DIRS; do
mkdir -p "$TARGET_DIR" copy_files_with_headers "$TARGET_DIR"
cp -rT "$SOURCE_DIR" "$TARGET_DIR"
done done
echo "Restoring original files..." # echo "Adding autogenerated comments to files..."
remove_headers # add_headers
echo "Types have been synced successfully." echo "Types have been synced successfully."