#!/bin/sh # Build the project first echo "Building scheduling-remote..." npm run build # Verify the initial build created remoteEntry.js REMOTE_ENTRY_PATH="dist/assets/remoteEntry.js" if [ ! -f "$REMOTE_ENTRY_PATH" ]; then echo "ERROR: Initial build did not create remoteEntry.js!" exit 1 fi echo "Initial build complete. remoteEntry.js exists." # Start build:watch in the background echo "Starting build:watch in background..." npm run build:watch & BUILD_WATCH_PID=$! # Wait a moment for build:watch to start and potentially rebuild echo "Waiting for build:watch to stabilize..." sleep 3 # Verify remoteEntry.js still exists (build:watch might have rebuilt it) MAX_WAIT=30 WAIT_COUNT=0 while [ ! -f "$REMOTE_ENTRY_PATH" ] && [ $WAIT_COUNT -lt $MAX_WAIT ]; do sleep 1 WAIT_COUNT=$((WAIT_COUNT + 1)) if [ $((WAIT_COUNT % 5)) -eq 0 ]; then echo "Waiting for remoteEntry.js after build:watch... (${WAIT_COUNT}s)" fi done if [ ! -f "$REMOTE_ENTRY_PATH" ]; then echo "ERROR: remoteEntry.js was not available after ${MAX_WAIT} seconds!" kill $BUILD_WATCH_PID 2>/dev/null || true exit 1 fi # Wait a bit more to ensure build:watch has finished any initial rebuild echo "Ensuring build:watch has completed initial build..." sleep 2 # Check file size to ensure it's not empty or being written FILE_SIZE=$(stat -f%z "$REMOTE_ENTRY_PATH" 2>/dev/null || stat -c%s "$REMOTE_ENTRY_PATH" 2>/dev/null || echo "0") if [ "$FILE_SIZE" -lt 100 ]; then echo "WARNING: remoteEntry.js seems too small (${FILE_SIZE} bytes), waiting a bit more..." sleep 2 fi echo "remoteEntry.js is ready (${FILE_SIZE} bytes). Starting http-server..." # Start http-server and give it time to fully initialize # Use a simple approach: start server and wait a moment for it to be ready exec npx http-server dist -p 3003 --cors -c-1