diff --git a/Dockerfile b/Dockerfile index 360a1e7..d35cb41 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,11 +7,17 @@ WORKDIR /app COPY package.json bun.lock ./ RUN bun install --frozen-lockfile --production -FROM oven/bun:1-alpine AS runner +FROM oven/bun:1-alpine AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules -COPY tsconfig.json ./ +COPY package.json tsconfig.json ./ COPY src ./src +RUN bun run build + +FROM oven/bun:1-alpine AS runner +WORKDIR /app +COPY --from=builder /app/dist ./dist + USER bun -CMD ["bun", "src/index.ts"] +CMD ["bun", "dist/index.js"] diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..8e9b4ec --- /dev/null +++ b/deploy.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -euo pipefail +cd "$(dirname "$0")" + +fly secrets import --stage < .env.production +fly deploy diff --git a/package.json b/package.json index 089d407..face7ca 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "@types/node": "^25.9.5" }, "scripts": { - "dev": "bun run src/index.ts" + "dev": "bun run src/index.ts", + "build": "bun build ./src/index.ts $(find src/cmd/registry -name \"*.ts\") --target bun --minify --splitting --root src --outdir ./dist" }, "peerDependencies": { "typescript": "^5.9.3" diff --git a/src/services/command.ts b/src/services/command.ts index c96f7b2..465af4b 100644 --- a/src/services/command.ts +++ b/src/services/command.ts @@ -1,15 +1,17 @@ import type { Message } from "discord.js"; import { readdir } from "fs/promises"; +import { dirname } from "path"; import type { Command } from "../models"; const CMD_PREFIX = "."; +const CMD_REGISTRY_DIR = `${dirname(Bun.main)}/cmd/registry`; export default abstract class CommandService { private static registry: Record = {} static async init() { const commands = await Promise.all( - (await readdir(`${import.meta.dir}/../cmd/registry`)).map(async file => (await import(`../cmd/registry/${file}`)).default satisfies Command) + (await readdir(CMD_REGISTRY_DIR)).map(async file => (await import(`${CMD_REGISTRY_DIR}/${file}`)).default satisfies Command) ); for (const command of commands) CommandService.registry[command.name] = command;