version: "3"

tasks:
  # Development task to start the local development server
  dev:
    desc: "Start the development server with hot module replacement"
    cmds:
      - npm run dev

  # Production build task
  build:
    desc: "Build the production version of the project"
    cmds:
      # Build the project using Vite's build command
      - npm run build

  # Deployment task for production server (worker-9)
  deploy:
    desc: "Deploy frontend to production server via SSH"
    cmds:
      - |
        echo "🚀 Deploying MapleFile Frontend to Production..."
        echo ""
        echo "⚠️  This task requires manual deployment on worker-9"
        echo ""
        echo "SSH to worker-9 and run:"
        echo "  ssh dockeradmin@<worker-9-ip>"
        echo "  ~/deploy-frontend.sh"
        echo ""
        echo "Or use the deployment script directly:"
        echo "  cd /var/www/monorepo"
        echo "  git pull origin main"
        echo "  cd web/maplefile-frontend"
        echo "  npm install"
        echo "  npm run build"
        echo ""
        echo "See: cloud/infrastructure/production/setup/11_maplefile_frontend.md"
        echo ""

  # Remote deployment helper (requires SSH access to worker-9)
  deploy-remote:
    desc: "Deploy to production server via SSH (requires worker-9 access)"
    cmds:
      - |
        if [ -z "$WORKER9_IP" ]; then
          echo "❌ Error: WORKER9_IP environment variable not set"
          echo "Usage: WORKER9_IP=<ip-address> task deploy-remote"
          exit 1
        fi
        echo "🚀 Deploying to worker-9 ($WORKER9_IP)..."
        ssh dockeradmin@$WORKER9_IP "cd /var/www/monorepo && git pull origin main && cd web/maplefile-frontend && npm install && npm run build"
        echo "✅ Deployment complete!"

  # Optional: Lint and type-check task
  lint:
    desc: "Run ESLint and TypeScript type checking"
    cmds:
      - npm run lint
      - npm run typecheck

  # Optional: Run tests
  test:
    desc: "Run project tests"
    cmds:
      - npm run test

  undelast:
    desc: Undue last commit which was not pushed. Special thanks to https://www.nobledesktop.com/learn/git/undo-changes.
    cmds:
      - git reset --soft HEAD~
