CLI

Code-generation commands for scaffolding models, services, controllers, and exceptions, plus a codegen step for API clients.

Contents
  1. Install
  2. Usage
  3. Global options
  4. resource
  5. model
  6. service
  7. controller
  8. exception
  9. api
  10. Configuration File

Install

Requires a matching version of @ozanarslan/corpus to be installed.

bun add @ozanarslan/corpus-cli

Usage

corpus <command> <name> | [--name, -n] <name>

Every command accepts -h/--help to print its usage and exit.

Global options

FlagAliasDescription
--help-hPrint the command's help text and exit.
--name <name>-nName of the entity to generate. Falls back to the first positional argument if omitted — so corpus model foo and corpus model -n foo are equivalent.
--main <path>-mOverride the entry file path used for wiring imports and instantiation.
--silent-sSuppress info logs.
--output <path>-oOverride the output directory.
--empty-eGenerate a bare file with no default CRUD shape, where supported.

If a file already exists at the target path, the module logs a warning and skips writing rather than overwriting it.

resource

corpus resource <name> | [--name, -n] <name> corpus res <name> | [--name, -n] <name>

Scaffolds a full resource in one pass: model, exception, service, and controller, then wires the service and controller into the entry file.

Options

Behavior

model

corpus model <name> | [--name, -n] <name> corpus mdl <name> | [--name, -n] <name>

Scaffolds a standalone model with a default CRUD-shaped interface or validation schema.

Options

Behavior

service

corpus service <name> | [--name, -n] <name> corpus svc <name> | [--name, -n] <name>

Scaffolds a standalone service with stubbed CRUD methods, and wires it into the entry file.

Options

Behavior

controller

corpus controller <name> | [--name, -n] <name> corpus ctrl <name> | [--name, -n] <name>

Scaffolds a standalone controller with stubbed CRUD routes, and wires it into the entry file.

Options

Behavior

exception

corpus exception <name> | [--name, -n] <name> corpus exc <name> | [--name, -n] <name>

Scaffolds a standalone exception class.

Options

Behavior

api

corpus api

Generates types, model interfaces, and (unless disabled in config) an API client from your app's registered routes.

Requirements

Behavior

  1. Reads the entry file and locates the .listen() call.
  2. If .listen() is called inside a named function, rewrites the file to ensure that function is actually invoked (await fn();).
  3. Replaces the .listen() call with a generator invocation that reads the nearest app's routes and config, then exits.
  4. Transpiles the rewritten file to a temporary .mjs file next to the entry file.
  5. Runs the temp file in a subprocess (inheriting stdio) to execute the generator.
  6. Deletes the temp file afterward, whether or not generation succeeded.

Fails fatally if no .listen() call is found, or if the generator subprocess exits non-zero.

Configuration File

All fields are optional.

// corpus.config.ts
import { defineConfig } from "@ozanarslan/corpus-cli";

export default defineConfig({
	silent: false,
	main: "./src/main.ts",
	output: "./src/corpus.gen.ts",
	pkgPath: "@ozanarslan/corpus",
	casing: "pascal",
	validationLibrary: null,
	apiClient: {
		disabled: false,
		exportAs: "CorpusApi",
		useStaticClass: false,
	},
	ignoreGlobalPrefix: false,
	defaultMethods: {
		get: { propertyKey: "get", address: "GET /" },
		getByParams: { propertyKey: "getByParams", address: "GET /:id" },
		create: { propertyKey: "create", address: "POST /" },
		update: { propertyKey: "update", address: "PUT /:id" },
		remove: { propertyKey: "remove", address: "DELETE /:id" },
	},
	folderStructure: {
		model: "{resource}/{resource}-model.ts",
		service: "{resource}/{resource}-service.ts",
		controller: "{resource}/{resource}-controller.ts",
		route: "{resource}/{resource}-route.ts",
	},
	exportModelsNamespace: true,
	exportArgsNamespace: true,
});