CLI Reference
Complete reference for tsgonest build and dev commands, flags, and exit codes.
tsgonest provides two subcommands: build for production compilation and dev for watch-mode development. If no subcommand is given, build is assumed.
tsgonest build
Compiles TypeScript via tsgo, generates companion files, writes the manifest, and produces the OpenAPI document.
tsgonest build [flags]Flags
| Flag | Alias | Description | Default |
|---|---|---|---|
--project <path> | -p | Path to tsconfig.json | tsconfig.json |
--config <path> | Path to tsgonest.config.json | auto-detect ./tsgonest.config.json | |
--clean | Delete the output directory before building | false | |
--assets | Copy non-TypeScript assets to the output directory | false | |
--no-check | Skip type checking (emit only) | false | |
--dump-metadata | Dump type metadata JSON to stdout and exit | false | |
--version | Print version and exit | ||
--help | Print usage and exit |
Pipeline
When you run tsgonest build, the following steps execute in order:
- Resolve config — Load
tsgonest.config.jsonfrom--configor auto-detect in the working directory. - Parse tsconfig — Read
tsconfig.json(or the path given by--project) using tsgo's native JSONC parser. - Create program — Build a tsgo program (incremental if configured in tsconfig).
- Type-check — Gather diagnostics. If errors exist and
--no-checkis not set, exit with code 1. - Emit JavaScript — Write compiled JS to the output directory.
- Check cache — If the post-processing cache is valid (source files unchanged), skip steps 7-9.
- Generate companions — Walk the AST, extract type metadata, generate
*.tsgonest.jsand*.tsgonest.d.tsfiles. - Write manifest — Generate
__tsgonest_manifest.jsonwith companion and route mappings. - Generate OpenAPI — Static analysis of NestJS controllers produces
openapi.json. - Copy assets — If
--assetsis set, copy non-TS files to the output directory.
Examples
# Default build (uses tsconfig.json + auto-detected config)
tsgonest build
# Custom tsconfig
tsgonest build --project tsconfig.build.json
# Clean build
tsgonest build --clean
# Skip type checking for faster builds
tsgonest build --no-check
# Explicit config path
tsgonest build --config configs/tsgonest.config.json -p tsconfig.build.json
# Dump type metadata for debugging
tsgonest build --dump-metadataExit codes
| Code | Meaning |
|---|---|
0 | Success — no errors |
1 | TypeScript errors found, but JS was still emitted |
2 | Fatal error — JS was not emitted |
tsgonest dev
Watch-mode development server. Watches source files, rebuilds on changes, and restarts your Node.js process.
tsgonest dev [flags] [-- node-args...]Flags
| Flag | Description | Default |
|---|---|---|
--project <path> | Path to tsconfig.json | tsconfig.json |
--config <path> | Path to tsgonest.config.json | auto-detect |
--entry <file> | Entry point TypeScript file | auto-detect from config or src/main.ts |
--exec <command> | Custom command to run instead of node | node |
--env-file <path> | Load environment variables from file (repeatable) | |
--debug | Enable Node.js inspector (--inspect) | false |
--preserveWatchOutput | Don't clear the terminal on rebuild | false |
--no-source-maps | Disable source map generation | false |
Behavior
- Initial build — Runs a full
tsgonest buildon startup. - Start process — Launches
node dist/<entry>.js(or the custom--execcommand). - Watch — Monitors
src/(orsourceRootfrom config) for file changes. - Rebuild — On file change, clears the terminal, runs an incremental build, and restarts the process.
- Manual restart — Type
rs+ Enter to trigger a manual rebuild and restart (whenmanualRestartis enabled in config).
Passthrough arguments
Arguments after -- are passed directly to the Node.js process:
# Pass --inspect-brk to Node.js
tsgonest dev -- --inspect-brk
# Pass environment variables
tsgonest dev -- --max-old-space-size=4096Examples
# Basic watch mode
tsgonest dev
# With custom entry point
tsgonest dev --entry src/main.ts
# With environment file
tsgonest dev --env-file .env --env-file .env.local
# With Node.js debugger
tsgonest dev --debug
# With custom build config
tsgonest dev --project tsconfig.build.json --config tsgonest.config.json
# Don't clear terminal on rebuild
tsgonest dev --preserveWatchOutputImplicit build
If you run tsgonest without a subcommand but with flags that start with -, it is treated as tsgonest build:
# These are equivalent:
tsgonest build --project tsconfig.build.json
tsgonest --project tsconfig.build.jsonVersion
tsgonest --version
# tsgonest v0.1.1