UNPKG

@tsed/cli

Version:
79 lines (78 loc) 3.27 kB
import { type PromptQuestion, type ProviderOpts } from "@tsed/cli-core"; import type { JsonSchema } from "@tsed/schema"; import type { GenerateCmdContext } from "../interfaces/index.js"; import type { TemplateRenderReturnType } from "../services/CliTemplatesService.js"; export type DefineTemplateOptions = { id: string; label: string; description?: string; outputDir: string; type?: string; /** * The file name format without the extension. */ fileName?: string; /** * The file extension. Default to `ts` * Don't include the dot (.) in the extension. */ ext?: string | null; /** * If `true` the template will be hidden in the list of available templates * during the generate command. */ hidden?: boolean; /** * If `true` the file name won't be altered (e.g. `MyService` will always be `MyService.ts`) * If `false` the file name will be transformed depending on the project style (e.g. `MyService` could be `my-service.ts`). * @default false */ preserveCase?: boolean; /** * If `true` the directory structure will be preserved when generating the file. */ preserveDirectory?: boolean; /** * Optional Ts.ED Schema describing template-specific arguments (exclude global fields like `type` and `name`). * Can be provided as a JsonSchema builder result (from @tsed/schema DSL) or any object exposing `toJSON()` to JSON Schema. */ schema?: JsonSchema; render(symbolName: string, data: GenerateCmdContext): Promise<string | undefined | TemplateRenderReturnType> | string | undefined | TemplateRenderReturnType; prompts?(data: GenerateCmdContext): PromptQuestion[] | Promise<PromptQuestion[]>; hooks?: ProviderOpts["hooks"]; }; export declare function defineTemplate(opts: DefineTemplateOptions): import("@tsed/cli-core").FactoryTokenProvider<{ id: string; label: string; description?: string; outputDir: string; type?: string; /** * The file name format without the extension. */ fileName?: string; ext: string | null; /** * If `true` the template will be hidden in the list of available templates * during the generate command. */ hidden?: boolean; /** * If `true` the file name won't be altered (e.g. `MyService` will always be `MyService.ts`) * If `false` the file name will be transformed depending on the project style (e.g. `MyService` could be `my-service.ts`). * @default false */ preserveCase?: boolean; /** * If `true` the directory structure will be preserved when generating the file. */ preserveDirectory?: boolean; /** * Optional Ts.ED Schema describing template-specific arguments (exclude global fields like `type` and `name`). * Can be provided as a JsonSchema builder result (from @tsed/schema DSL) or any object exposing `toJSON()` to JSON Schema. */ schema?: JsonSchema; render(symbolName: string, data: GenerateCmdContext): Promise<string | undefined | TemplateRenderReturnType> | string | undefined | TemplateRenderReturnType; prompts?(data: GenerateCmdContext): PromptQuestion[] | Promise<PromptQuestion[]>; hooks?: ProviderOpts["hooks"]; }>;