microsoft/typespec
Publicmirrored from https://github.com/microsoft/typespecAvailable
packages/compiler/init/init-template.ts
97lines · modecode
| 1 | import { JSONSchemaType } from "ajv"; |
| 2 | import { CadlConfigJsonSchema } from "../config/config-schema.js"; |
| 3 | import { CadlRawConfig } from "../config/types.js"; |
| 4 | |
| 5 | export interface InitTemplateFile { |
| 6 | path: string; |
| 7 | destination: string; |
| 8 | } |
| 9 | |
| 10 | export interface InitTemplateInput { |
| 11 | description: string; |
| 12 | type: "text"; |
| 13 | initialValue: any; |
| 14 | } |
| 15 | |
| 16 | export interface InitTemplate { |
| 17 | /** |
| 18 | * Name of the template |
| 19 | */ |
| 20 | title: string; |
| 21 | |
| 22 | /** |
| 23 | * Description for the template. |
| 24 | */ |
| 25 | description: string; |
| 26 | |
| 27 | /** |
| 28 | * List of libraries to include |
| 29 | */ |
| 30 | libraries: string[]; |
| 31 | |
| 32 | /** |
| 33 | * Config |
| 34 | */ |
| 35 | config?: CadlRawConfig; |
| 36 | |
| 37 | /** |
| 38 | * Custom inputs to prompt to the user |
| 39 | */ |
| 40 | inputs?: Record<string, InitTemplateInput>; |
| 41 | |
| 42 | /** |
| 43 | * A flag to indicate not adding @cadl-lang/compiler package to package.json. |
| 44 | * Other libraries may already brought in the dependency such as Azure template. |
| 45 | */ |
| 46 | skipCompilerPackage?: boolean; |
| 47 | |
| 48 | /** |
| 49 | * List of files to copy. |
| 50 | */ |
| 51 | files?: InitTemplateFile[]; |
| 52 | } |
| 53 | |
| 54 | export const InitTemplateSchema: JSONSchemaType<InitTemplate> = { |
| 55 | type: "object", |
| 56 | additionalProperties: false, |
| 57 | properties: { |
| 58 | title: { type: "string" }, |
| 59 | description: { type: "string" }, |
| 60 | libraries: { type: "array", items: { type: "string" } }, |
| 61 | skipCompilerPackage: { type: "boolean", nullable: true }, |
| 62 | config: { nullable: true, ...CadlConfigJsonSchema }, |
| 63 | inputs: { |
| 64 | type: "object", |
| 65 | nullable: true, |
| 66 | additionalProperties: { |
| 67 | type: "object", |
| 68 | properties: { |
| 69 | description: { type: "string" }, |
| 70 | type: { type: "string", enum: ["text"] }, |
| 71 | initialValue: {} as any, |
| 72 | }, |
| 73 | required: ["description", "type"], |
| 74 | }, |
| 75 | required: [], |
| 76 | }, |
| 77 | files: { |
| 78 | type: "array", |
| 79 | nullable: true, |
| 80 | items: { |
| 81 | type: "object", |
| 82 | properties: { |
| 83 | path: { type: "string" }, |
| 84 | destination: { type: "string" }, |
| 85 | }, |
| 86 | required: ["path", "destination"], |
| 87 | }, |
| 88 | }, |
| 89 | }, |
| 90 | required: ["title", "description"], |
| 91 | }; |
| 92 | |
| 93 | export const InitTemplateDefinitionsSchema: JSONSchemaType<Record<string, InitTemplate>> = { |
| 94 | type: "object", |
| 95 | additionalProperties: InitTemplateSchema, |
| 96 | required: [], |
| 97 | }; |
| 98 | |