Files
bunext/src/commands/index.ts
T
tbenandClaude Opus 5.5 b410b92f9f Make the dist directory configurable
Set it with `dist_dir` in bunext.config.ts or `--dist-dir` on any CLI
command (precedence: --dist-dir > BUNEXT_DIST_DIR > dist_dir > .bunext).
setupDistDir() resolves it in the CLI's preAction hook and at the start
of bunextInit(), so custom servers get the config value too.

- Read dist-derived paths from grabDirNames() inside functions instead of
  at import time; a guard test enforces this.
- Derive the client asset URL prefix from the dist dir instead of
  hard-coding /.bunext.
- Make the dev watcher ignore rules and probe follow the dist dir.
- Validate the dir: inside the project root, outside src/, public/ and
  node_modules/, URL-safe characters only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-09 03:55:54 +01:00

58 lines
1.3 KiB
TypeScript
Executable File

#!/usr/bin/env bun
import { program } from "commander";
import start from "./start";
import dev from "./dev";
import build from "./build";
import sitemap from "./sitemap";
import { log } from "../utils/log";
import setupDistDir from "../functions/setup-dist-dir";
/**
* # Describe Program
*/
program
.name(`bunext`)
.description(`A React Next JS replacement built with bun JS`)
.version(`1.0.43`);
/**
* # Declare Commands
*/
program.addCommand(dev());
program.addCommand(start());
program.addCommand(build());
program.addCommand(sitemap());
/**
* # Resolve the Dist Directory
* Before any command runs, from `--dist-dir` or the config. Child server
* processes inherit it through `BUNEXT_DIST_DIR`.
*/
program.hook("preAction", async (_program, action_command) => {
try {
await setupDistDir({ dist_dir: action_command.opts().distDir });
} catch (error: any) {
log.error(error?.message || String(error));
process.exit(1);
}
});
/**
* # Handle Unavailable Commands
*/
program.on("command:*", () => {
log.error(
"Invalid command: %s\nSee --help for a list of available commands." +
" " +
program.args.join(" "),
);
process.exit(1);
});
/**
* # Parse Arguments
*/
await program.parseAsync(Bun.argv);