Refactors typings compilation script

Consolidates typings compilation scripts into a single, reusable script.

This simplifies the management of typings for different modes by using parameters instead of separate files.

It also improves script maintainability and reduces code duplication.
This commit is contained in:
Carlos Santos 2025-10-20 18:25:41 +02:00
parent 56343e8f03
commit 15c35f87cb
4 changed files with 61 additions and 78 deletions

View File

@ -379,7 +379,7 @@ add_common_dev_commands() {
# Typings watcher. It generates the typings-ready.flag file when done for other watchers to wait on. # Typings watcher. It generates the typings-ready.flag file when done for other watchers to wait on.
CMD_NAMES+=("typings-ce") CMD_NAMES+=("typings-ce")
CMD_COLORS+=("bgGreen.black") CMD_COLORS+=("bgGreen.black")
CMD_COMMANDS+=("./scripts/dev/watch-typings-ce.sh") CMD_COMMANDS+=("./scripts/dev/watch-typings.sh ce")
# shared-meet-components watcher # shared-meet-components watcher
CMD_NAMES+=("shared-meet-components") CMD_NAMES+=("shared-meet-components")
@ -426,7 +426,7 @@ add_pro_commands() {
# Typings watcher for PRO edition. It generates the typings-ready.flag file when done for other watchers to wait on. # Typings watcher for PRO edition. It generates the typings-ready.flag file when done for other watchers to wait on.
CMD_NAMES+=("typings-pro") CMD_NAMES+=("typings-pro")
CMD_COLORS+=("bgGreen.black") CMD_COLORS+=("bgGreen.black")
CMD_COMMANDS+=("./scripts/dev/watch-typings-pro.sh") CMD_COMMANDS+=("./scripts/dev/watch-typings.sh pro")
} }
# Helper: Add REST API docs and browser-sync commands # Helper: Add REST API docs and browser-sync commands

View File

@ -1,38 +0,0 @@
#!/bin/bash
# Path to the flag file indicating typings are ready
FLAG_PATH="./meet-ce/typings/dist/typings-ready.flag"
# Remove the flag file if it exists
rm -f $FLAG_PATH
# Create an empty directory for the flag file if it doesn't exist
mkdir -p "$(dirname "$FLAG_PATH")"
echo "Starting typings watch mode..."
echo "Waiting for initial compilation..."
# Run tsc in watch mode
pnpm --filter @openvidu-meet/typings run dev | while read line; do
echo "$line"
# Check for compilation start (remove flag to signal "not ready")
if echo "$line" | grep -q "File change detected. Starting incremental compilation"; then
rm -f $FLAG_PATH
echo "Typings recompiling..."
fi
# Check for successful compilation (create flag to signal "ready")
if echo "$line" | grep -q "Found 0 errors"; then
# Add small delay to ensure all files are written to disk
sleep 0.2
touch $FLAG_PATH
echo "✅ Typings ready!"
fi
# Check for compilation errors
if echo "$line" | grep -q "error TS"; then
rm -f $FLAG_PATH
echo "❌ Typings compilation failed!"
fi
done

View File

@ -1,38 +0,0 @@
#!/bin/bash
# Path to the flag file indicating typings are ready
FLAG_PATH="./meet-pro/typings/dist/typings-ready.flag"
# Remove the flag file if it exists
rm -f $FLAG_PATH
# Create an empty directory for the flag file if it doesn't exist
mkdir -p "$(dirname "$FLAG_PATH")"
echo "Starting typings watch mode..."
echo "Waiting for initial compilation..."
# Run tsc in watch mode
pnpm --filter @openvidu-meet-pro/typings run dev | while read line; do
echo "$line"
# Check for compilation start (remove flag to signal "not ready")
if echo "$line" | grep -q "File change detected. Starting incremental compilation"; then
rm -f $FLAG_PATH
echo "Typings recompiling..."
fi
# Check for successful compilation (create flag to signal "ready")
if echo "$line" | grep -q "Found 0 errors"; then
# Add small delay to ensure all files are written to disk
sleep 0.2
touch $FLAG_PATH
echo "✅ Typings ready!"
fi
# Check for compilation errors
if echo "$line" | grep -q "error TS"; then
rm -f $FLAG_PATH
echo "❌ Typings compilation failed!"
fi
done

59
scripts/dev/watch-typings.sh Executable file
View File

@ -0,0 +1,59 @@
#!/bin/bash
# Usage: watch-typings.sh [mode] [pnpm-filter]
# mode: ce (default) | pro
# pnpm-filter: optional pnpm filter for running the typings package (defaults to @openvidu-meet/typings)
set -u
MODE=${1:-ce}
PNPM_FILTER=${2:-@openvidu-meet/typings}
case "$MODE" in
ce|CE)
FLAG_PATH="./meet-ce/typings/dist/typings-ready.flag"
;;
pro|PRO)
FLAG_PATH="./meet-pro/typings/dist/typings-ready.flag"
;;
*)
echo "Usage: $0 [ce|pro] [pnpm-filter]"
exit 2
;;
esac
# Remove the flag file if it exists
rm -f "$FLAG_PATH"
# Create the directory for the flag file if it doesn't exist
mkdir -p "$(dirname "$FLAG_PATH")"
echo "Starting typings watch mode for mode='$MODE' with pnpm filter='$PNPM_FILTER'..."
echo "Waiting for initial compilation..."
# Run tsc in watch mode via the typings package. We stream the output and look for known patterns.
pnpm --filter "$PNPM_FILTER" run dev | while IFS= read -r line || [ -n "$line" ]; do
echo "$line"
# Check for compilation start (remove flag to signal "not ready")
if echo "$line" | grep -q "File change detected. Starting incremental compilation"; then
rm -f "$FLAG_PATH"
echo "Typings recompiling..."
fi
# Check for successful compilation (create flag to signal "ready")
if echo "$line" | grep -q "Found 0 errors"; then
# Add small delay to ensure all files are written to disk
sleep 0.2
touch "$FLAG_PATH"
echo "✅ Typings ready!"
fi
# Check for compilation errors
if echo "$line" | grep -q "error TS"; then
rm -f "$FLAG_PATH"
echo "❌ Typings compilation failed!"
fi
done
exit 0