diff --git a/app/server/cli/index.ts b/app/server/cli/index.ts index 128631e6..9a4be586 100644 --- a/app/server/cli/index.ts +++ b/app/server/cli/index.ts @@ -8,13 +8,29 @@ program.addCommand(resetPasswordCommand); export async function runCLI(argv: string[]): Promise { const args = argv.slice(2); - const hasCommand = args.length > 0 && !args[0].startsWith("-"); + const isCLIMode = process.env.ZEROBYTE_CLI === "1"; - if (!hasCommand) { + if (args.length === 0) { + if (isCLIMode) { + program.help(); + return true; + } return false; } - await program.parseAsync(argv); + if (!isCLIMode && args[0].startsWith("-")) { + return false; + } + + await program.parseAsync(argv).catch((err) => { + if (err.message.includes("SIGINT")) { + process.exit(0); + } + + console.error(err.message); + process.exit(1); + }); + return true; } diff --git a/app/server/index.ts b/app/server/index.ts index 5d1be823..205180e0 100644 --- a/app/server/index.ts +++ b/app/server/index.ts @@ -8,6 +8,12 @@ import { REQUIRED_MIGRATIONS } from "./core/constants"; import { validateRequiredMigrations } from "./modules/lifecycle/checkpoint"; import { createApp } from "./app"; import { config } from "./core/config"; +import { runCLI } from "./cli"; + +const cliRun = await runCLI(Bun.argv); +if (cliRun) { + process.exit(0); +} const app = createApp(); diff --git a/package.json b/package.json index 2edcbfeb..4b6861b1 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "build": "react-router build", "dev": "bunx --bun vite", "start": "bun ./dist/server/index.js", - "cli": "bun run app/server/cli/main.ts", + "cli:dev": "bun run app/server/cli/main.ts", + "cli": "ZEROBYTE_CLI=1 bun ./dist/server/index.js", "tsc": "react-router typegen && tsc", "lint": "biome check .", "lint:ci": "biome ci . --changed --error-on-warnings --no-errors-on-unmatched",