services:
    bun-install:
        name: Install Dependencies
        description: Installs project dependencies using bun install
        commands:
            start: |
                echo "Installing dependencies with bun..."
                cd /workspaces/drive
                bun install
                echo "Dependencies installed successfully"
            ready: |
                # Check if node_modules exists and has content
                if [ -d "/workspaces/drive/node_modules" ] && [ "$(ls -A /workspaces/drive/node_modules)" ]; then
                    echo "Dependencies are installed"
                    exit 0
                else
                    echo "Dependencies are not installed"
                    exit 1
                fi
        triggeredBy:
            - postEnvironmentStart
    
    bun-dev:
        name: Bun Development Server
        description: Runs the Bun development server with hot reloading
        commands:
            start: |
                echo "Starting Bun development server..."
                cd /workspaces/drive
                bun run dev
            ready: |
                # Check if the development server is responding
                curl -f http://localhost:3001 > /dev/null 2>&1
                if [ $? -eq 0 ]; then
                    echo "Bun development server is ready"
                    exit 0
                else
                    echo "Bun development server is not ready"
                    exit 1
                fi
            stop: |
                echo "Stopping Bun development server..."
                pkill -f "bun.*dev"
        triggeredBy:
            - postEnvironmentStart
    
    convex-dev:
        name: Convex Development Server
        description: Runs the Convex development server for backend functions
        commands:
            start: |
                echo "Starting Convex development server..."
                cd /workspaces/drive
                bunx convex dev
            ready: |
                # Check if Convex dev server is running by looking for the process
                pgrep -f "convex.*dev" > /dev/null 2>&1
                if [ $? -eq 0 ]; then
                    echo "Convex development server is ready"
                    exit 0
                else
                    echo "Convex development server is not ready"
                    exit 1
                fi
            stop: |
                echo "Stopping Convex development server..."
                pkill -f "convex.*dev"
        triggeredBy:
            - postEnvironmentStart
