From 84e5db7309d0a6ddafa20f755660d72a82c154fd Mon Sep 17 00:00:00 2001 From: Carlos Santos <4a.santos@gmail.com> Date: Tue, 11 Mar 2025 16:11:06 +0100 Subject: [PATCH] types: Update sync-types.sh to improve header management and file copying logic --- types/sync-types.sh | 55 +++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/types/sync-types.sh b/types/sync-types.sh index 40c56a1..3164cd2 100755 --- a/types/sync-types.sh +++ b/types/sync-types.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh HEADER_KEY="THIS HEADER IS AUTOGENERATED. DO NOT MODIFY MANUALLY." HEADER="/** $HEADER_KEY For any changes, please update the '/openvidu-meet/types' directory. */" @@ -11,53 +11,40 @@ TYPES_DIR="../../openvidu-meet-pro/types/src/ce" add_headers() { find "$SOURCE_DIR" -type f -name "*.ts" | while IFS= read -r file; do if ! grep -qF "$HEADER_KEY" "$file"; then - printf "%s\n\n%s" "$HEADER" "$(cat "$file")" > "${file}.tmp" && mv "${file}.tmp" "$file" + printf "%s\n\n%s" "$HEADER" "$(cat "$file")" >"${file}.tmp" && mv "${file}.tmp" "$file" fi 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 - if grep -qF "$HEADER_KEY" "$file"; then - awk -v header_key="$HEADER_KEY" ' - BEGIN { skip = 0 } - { - if (skip) { - if ($0 ~ /^$/) { skip = 0 } - next - } - if ($0 ~ /^\/\*\* .*'"$HEADER_KEY"'.*\*\/$/) { - skip = 1 - next - } - print - } - ' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file" - fi + RELATIVE_PATH="${file#$SOURCE_DIR/}" + DEST_FILE="$TARGET_DIR/$RELATIVE_PATH" + + mkdir -p "$(dirname "$DEST_FILE")" + + printf "%s\n\n%s" "$HEADER" "$(cat "$file")" >"$DEST_FILE" done } -if [[ $1 == "ce" ]]; then - TARGET_DIRS=("$FRONTEND_DIR" "$BACKEND_DIR") -elif [[ $1 == "pro" ]]; then - TARGET_DIRS=("$TYPES_DIR") +if [ "$1" = "ce" ]; then + TARGET_DIRS="$FRONTEND_DIR $BACKEND_DIR" +elif [ "$1" = "pro" ]; then + TARGET_DIRS="$TYPES_DIR" else 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 - -echo "Adding autogenerated comments to files..." -add_headers - - echo "Copying files to target directories..." -for TARGET_DIR in "${TARGET_DIRS[@]}"; do - mkdir -p "$TARGET_DIR" - cp -rT "$SOURCE_DIR" "$TARGET_DIR" +for TARGET_DIR in $TARGET_DIRS; do + copy_files_with_headers "$TARGET_DIR" done -echo "Restoring original files..." -remove_headers +# echo "Adding autogenerated comments to files..." +# add_headers echo "Types have been synced successfully."