microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
33d83ea24ba2f6df7d485c85eddc310754a0f5d6

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/compiler/init/init-template.ts

97lines · modecode

1import { JSONSchemaType } from "ajv";
2import { CadlConfigJsonSchema } from "../config/config-schema.js";
3import { CadlRawConfig } from "../config/types.js";
4
5export interface InitTemplateFile {
6 path: string;
7 destination: string;
8}
9
10export interface InitTemplateInput {
11 description: string;
12 type: "text";
13 initialValue: any;
14}
15
16export 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
54export 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
93export const InitTemplateDefinitionsSchema: JSONSchemaType<Record<string, InitTemplate>> = {
94 type: "object",
95 additionalProperties: InitTemplateSchema,
96 required: [],
97};
98