FROM node:23-alpine AS base
WORKDIR /app

# INSTALL STAGE
FROM base AS install
COPY package.json pnpm-lock.yaml ./
RUN corepack enable
RUN corepack prepare pnpm@10.8.0 --activate
COPY vite.config.ts svelte.config.js tailwind.config.ts postcss.config.js components.json .npmrc ./
COPY prisma/ ./prisma
COPY static ./static
COPY src ./src
RUN pnpm i

# DEV STAGE
FROM install AS dev
EXPOSE 5173
CMD ["pnpm", "run", "dev", "--host"]

# BUILD STAGE
FROM install AS build
RUN ["pnpm", "run", "build"]
RUN ["pwd"]

# RUN STAGE
FROM base AS prod
COPY --from=build /app/build .
ENV NODE_ENV=production
EXPOSE 3000
CMD ["node", "."]
