vovk new
npx vovk-cli new --help
Usage: vovk new|n [options] [components...]
Create new components. "vovk new [...components] [segmentName/]moduleName" to create a new module or "vovk
new segment [segmentName]" to create a new segment
Options:
-o, --overwrite overwrite existing files
--static (new segment only) if the segment is static
--template, --templates <templates...> (new module only) override config template; accepts an array of
strings that correspond to the order of the components
--out, --out-dir <dirname> (new module only) override outDir in template file; relative to the
root of the project
--no-segment-update (new module only) do not update segment files when creating a new
module
--empty (new module only) create an empty module
--dry-run do not write files to disk
--log-level <level> set the log level
-h, --help display help for commandThe vovk new command creates segments and modules (such as controllers, services, or custom modules). It uses the moduleTemplates option from the config and can be extended with your own templates. It combines two workflows in one: vovk new segment [segment_name] and vovk new [module] [module_name_singular]
vovk new segment
Root Segment
npx vovk new segmentIf you run vovk new segment without an argument, it creates a root segment at /src/app/api/[[β¦vovk]]/route.ts (formatted with PrettierΒ ). The segmentName option of initSegment is an empty string and can be omitted. The generated file contains:
import { initSegment } from 'vovk';
const controllers = {};
export type Controllers = typeof controllers;
export const { GET, POST, PATCH, PUT, HEAD, OPTIONS, DELETE } = initSegment({
emitSchema: true,
controllers,
});When you run vovk dev, the segment emits a schema at .vovk-schema/root.json.
The segment exposes an API at /api/β¦.
Root segments can be used alongside nested segments of any depth.
Nested Segment
npx vovk new segment fooRunning vovk new segment foo creates /src/app/api/foo/[[β¦vovk]]/route.ts (formatted with Prettier). The generated file includes:
// ...
export const { GET, POST, PATCH, PUT, HEAD, OPTIONS, DELETE } = initSegment({
segmentName: 'foo',
emitSchema: true,
controllers,
});When you run vovk dev, the segment emits a schema at .vovk-schema/foo.json.
The segment exposes an API at /api/foo/β¦.
vovk new segment foo/bar/baz creates a nested segment at /src/app/api/foo/bar/baz/[[β¦vovk]]/route.ts, available at /api/foo/bar/baz/β¦. Here, segmentName is "foo/bar/baz".
vovk new [module] [name]
npx vovk new controller service foo/uservovk new (with anything other than segment) creates new modules in /src/modules (formatted with Prettier).
Command structure:
npx vovk newβ the command.- Components β the module types to create (
controller,service, or a custom module). - Module name (singular) with optional segment prefix:
foo/usercreates a module in /src/modules/foo/user/ and updates thefoosegment. Omit the segment to target the root:
npx vovk new controller service userWhen you create a controller with vovk new, the script updates the controllers list in the segment file and modifies route.ts using ASTΒ .
Template paths are defined via moduleTemplates in the config:
/** @type {import('vovk-cli').VovkConfig} */
const config = {
moduleTemplates: {
controller: 'vovk-dto/module-templates/controller.ts.ejs',
service: 'vovk-cli/module-templates/type/service.ts.ejs',
state: './my-templates/state.ts.ejs',
dto: './my-templates/dto.ts.ejs',
},
};
export default config;npx vovk new controller state dto user creates UserController.ts, UserService.ts, and UserDto.ts in /src/modules/user and updates the root segment.
Built-in Templates
vovk-cli ships example templates for controllers and services in its module-templates folder. Some validation libraries also provide example controller templates in their respective packages.
vovk init sets up a Vovk.ts project with the corresponding templates defined in the config.
Shortcuts
Controllers and services can be created with shortcuts:
npx vovk n c s userWhich is equivalent to:
npx vovk new controller service userCustom Templates π§
Coming soon.
Roadmap
- π Document custom module templates and available variables.