@canonical/summon-core 0.18.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE +166 -0
  2. package/package.json +16 -8
  3. package/src/discovery/discoverGeneratorTree.ts +1 -1
  4. package/src/discovery/generatorCache.ts +1 -1
  5. package/src/index.ts +13 -14
  6. package/src/stamp/applyStamp.test.ts +199 -0
  7. package/src/stamp/applyStamp.ts +90 -0
  8. package/src/stamp/index.ts +3 -0
  9. package/src/stamp/runTaskWithStamp.ts +31 -0
  10. package/src/stamp/types.ts +7 -0
  11. package/src/template/TemplatingEngine.ts +17 -0
  12. package/src/template/ejsEngine.ts +21 -0
  13. package/src/template/generateStamp.ts +27 -0
  14. package/src/template/generatorComment.test.ts +81 -0
  15. package/src/template/generatorComment.ts +32 -0
  16. package/src/template/getCommentStyle.ts +59 -0
  17. package/src/template/index.ts +13 -0
  18. package/src/template/prependStamp.ts +16 -0
  19. package/src/template/renderFile.ts +13 -0
  20. package/src/template/renderString.test.ts +107 -0
  21. package/src/template/renderString.ts +13 -0
  22. package/src/template/renderStringAsync.ts +13 -0
  23. package/src/template/tasks/index.ts +3 -0
  24. package/src/template/tasks/template.test.ts +66 -0
  25. package/src/template/tasks/template.ts +22 -0
  26. package/src/template/tasks/templateDir.ts +60 -0
  27. package/src/template/tasks/types.ts +29 -0
  28. package/src/template/templateHelpers.test.ts +227 -0
  29. package/src/template/templateHelpers.ts +35 -0
  30. package/src/template/withHelpers.test.ts +41 -0
  31. package/src/template/withHelpers.ts +10 -0
  32. package/src/testing/integration/template-rendering.test.ts +69 -0
  33. package/src/types/AnyGenerator.ts +9 -0
  34. package/src/types/ForbidReserved.ts +23 -0
  35. package/src/types/GeneratorDefinition.ts +19 -0
  36. package/src/types/GeneratorMeta.ts +29 -0
  37. package/src/types/PromptDefinition.ts +33 -0
  38. package/src/types/ReservedOption.ts +23 -0
  39. package/src/types/StampConfig.ts +6 -0
  40. package/src/types/index.ts +7 -0
  41. package/src/cli-types.ts +0 -59
  42. package/src/stamp.ts +0 -165
  43. package/src/template.test.ts +0 -666
  44. package/src/template.ts +0 -543
  45. package/src/types.ts +0 -97
@@ -0,0 +1,227 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import templateHelpers from "./templateHelpers.js";
3
+
4
+ describe("templateHelpers", () => {
5
+ describe("camelCase", () => {
6
+ it("converts hyphenated strings", () => {
7
+ expect(templateHelpers.camelCase("my-component")).toBe("myComponent");
8
+ });
9
+ it("converts underscored strings", () => {
10
+ expect(templateHelpers.camelCase("my_component")).toBe("myComponent");
11
+ });
12
+ it("converts space-separated strings", () => {
13
+ expect(templateHelpers.camelCase("my component")).toBe("myComponent");
14
+ });
15
+ it("converts PascalCase to camelCase", () => {
16
+ expect(templateHelpers.camelCase("MyComponent")).toBe("myComponent");
17
+ });
18
+ it("handles multiple separators", () => {
19
+ expect(templateHelpers.camelCase("my-component_name")).toBe(
20
+ "myComponentName",
21
+ );
22
+ });
23
+ it("handles single word", () => {
24
+ expect(templateHelpers.camelCase("component")).toBe("component");
25
+ });
26
+ it("handles empty string", () => {
27
+ expect(templateHelpers.camelCase("")).toBe("");
28
+ });
29
+ it("handles consecutive separators", () => {
30
+ expect(templateHelpers.camelCase("my--component")).toBe("myComponent");
31
+ });
32
+ });
33
+
34
+ describe("pascalCase", () => {
35
+ it("converts hyphenated strings", () => {
36
+ expect(templateHelpers.pascalCase("my-component")).toBe("MyComponent");
37
+ });
38
+ it("converts underscored strings", () => {
39
+ expect(templateHelpers.pascalCase("my_component")).toBe("MyComponent");
40
+ });
41
+ it("converts space-separated strings", () => {
42
+ expect(templateHelpers.pascalCase("my component")).toBe("MyComponent");
43
+ });
44
+ it("preserves PascalCase", () => {
45
+ expect(templateHelpers.pascalCase("MyComponent")).toBe("MyComponent");
46
+ });
47
+ it("handles single word", () => {
48
+ expect(templateHelpers.pascalCase("component")).toBe("Component");
49
+ });
50
+ it("handles empty string", () => {
51
+ expect(templateHelpers.pascalCase("")).toBe("");
52
+ });
53
+ });
54
+
55
+ describe("kebabCase", () => {
56
+ it("converts camelCase", () => {
57
+ expect(templateHelpers.kebabCase("myComponent")).toBe("my-component");
58
+ });
59
+ it("converts PascalCase", () => {
60
+ expect(templateHelpers.kebabCase("MyComponent")).toBe("my-component");
61
+ });
62
+ it("converts underscored strings", () => {
63
+ expect(templateHelpers.kebabCase("my_component")).toBe("my-component");
64
+ });
65
+ it("converts space-separated strings", () => {
66
+ expect(templateHelpers.kebabCase("my component")).toBe("my-component");
67
+ });
68
+ it("preserves kebab-case", () => {
69
+ expect(templateHelpers.kebabCase("my-component")).toBe("my-component");
70
+ });
71
+ it("handles single word", () => {
72
+ expect(templateHelpers.kebabCase("Component")).toBe("component");
73
+ });
74
+ it("handles empty string", () => {
75
+ expect(templateHelpers.kebabCase("")).toBe("");
76
+ });
77
+ it("handles consecutive uppercase", () => {
78
+ expect(templateHelpers.kebabCase("XMLParser")).toBe("xml-parser");
79
+ });
80
+ it("handles mixed case with boundaries", () => {
81
+ expect(templateHelpers.kebabCase("parseXMLDocument")).toBe(
82
+ "parse-xml-document",
83
+ );
84
+ });
85
+ it("splits on each lowercase to uppercase transition", () => {
86
+ expect(templateHelpers.kebabCase("parseXmlDocument")).toBe(
87
+ "parse-xml-document",
88
+ );
89
+ });
90
+ });
91
+
92
+ describe("snakeCase", () => {
93
+ it("converts camelCase", () => {
94
+ expect(templateHelpers.snakeCase("myComponent")).toBe("my_component");
95
+ });
96
+ it("converts PascalCase", () => {
97
+ expect(templateHelpers.snakeCase("MyComponent")).toBe("my_component");
98
+ });
99
+ it("converts hyphenated strings", () => {
100
+ expect(templateHelpers.snakeCase("my-component")).toBe("my_component");
101
+ });
102
+ it("converts space-separated strings", () => {
103
+ expect(templateHelpers.snakeCase("my component")).toBe("my_component");
104
+ });
105
+ it("preserves snake_case", () => {
106
+ expect(templateHelpers.snakeCase("my_component")).toBe("my_component");
107
+ });
108
+ it("handles single word", () => {
109
+ expect(templateHelpers.snakeCase("Component")).toBe("component");
110
+ });
111
+ it("handles empty string", () => {
112
+ expect(templateHelpers.snakeCase("")).toBe("");
113
+ });
114
+ });
115
+
116
+ describe("constantCase", () => {
117
+ it("converts camelCase", () => {
118
+ expect(templateHelpers.constantCase("myComponent")).toBe("MY_COMPONENT");
119
+ });
120
+ it("converts PascalCase", () => {
121
+ expect(templateHelpers.constantCase("MyComponent")).toBe("MY_COMPONENT");
122
+ });
123
+ it("converts hyphenated strings", () => {
124
+ expect(templateHelpers.constantCase("my-component")).toBe("MY_COMPONENT");
125
+ });
126
+ it("converts space-separated strings", () => {
127
+ expect(templateHelpers.constantCase("my component")).toBe("MY_COMPONENT");
128
+ });
129
+ it("handles single word", () => {
130
+ expect(templateHelpers.constantCase("component")).toBe("COMPONENT");
131
+ });
132
+ it("handles empty string", () => {
133
+ expect(templateHelpers.constantCase("")).toBe("");
134
+ });
135
+ });
136
+
137
+ describe("capitalize", () => {
138
+ it("capitalizes first letter", () => {
139
+ expect(templateHelpers.capitalize("hello")).toBe("Hello");
140
+ });
141
+ it("preserves rest of string", () => {
142
+ expect(templateHelpers.capitalize("hELLO")).toBe("HELLO");
143
+ });
144
+ it("handles single character", () => {
145
+ expect(templateHelpers.capitalize("h")).toBe("H");
146
+ });
147
+ it("handles empty string", () => {
148
+ expect(templateHelpers.capitalize("")).toBe("");
149
+ });
150
+ it("handles already capitalized", () => {
151
+ expect(templateHelpers.capitalize("Hello")).toBe("Hello");
152
+ });
153
+ });
154
+
155
+ describe("isoDate", () => {
156
+ it("returns ISO date string", () => {
157
+ expect(templateHelpers.isoDate()).toMatch(
158
+ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/,
159
+ );
160
+ });
161
+ });
162
+
163
+ describe("year", () => {
164
+ it("returns current year", () => {
165
+ expect(templateHelpers.year()).toBe(new Date().getFullYear());
166
+ });
167
+ });
168
+
169
+ describe("indent", () => {
170
+ it("indents single line", () => {
171
+ expect(templateHelpers.indent("hello", 2)).toBe(" hello");
172
+ });
173
+ it("indents multiple lines", () => {
174
+ expect(templateHelpers.indent("line1\nline2\nline3", 2)).toBe(
175
+ " line1\n line2\n line3",
176
+ );
177
+ });
178
+ it("handles zero indent", () => {
179
+ expect(templateHelpers.indent("hello", 0)).toBe("hello");
180
+ });
181
+ it("handles large indent", () => {
182
+ expect(templateHelpers.indent("hello", 10)).toBe(" hello");
183
+ });
184
+ it("handles empty string", () => {
185
+ expect(templateHelpers.indent("", 2)).toBe(" ");
186
+ });
187
+ it("handles empty lines", () => {
188
+ expect(templateHelpers.indent("a\n\nb", 2)).toBe(" a\n \n b");
189
+ });
190
+ });
191
+
192
+ describe("join", () => {
193
+ it("joins array with default separator", () => {
194
+ expect(templateHelpers.join(["a", "b", "c"])).toBe("a, b, c");
195
+ });
196
+ it("joins array with custom separator", () => {
197
+ expect(templateHelpers.join(["a", "b", "c"], " | ")).toBe("a | b | c");
198
+ });
199
+ it("handles empty array", () => {
200
+ expect(templateHelpers.join([])).toBe("");
201
+ });
202
+ it("handles single item", () => {
203
+ expect(templateHelpers.join(["single"])).toBe("single");
204
+ });
205
+ it("converts non-string items", () => {
206
+ expect(templateHelpers.join([1, 2, 3])).toBe("1, 2, 3");
207
+ });
208
+ it("handles mixed types", () => {
209
+ expect(templateHelpers.join([1, "two", true])).toBe("1, two, true");
210
+ });
211
+ });
212
+
213
+ describe("pluralize", () => {
214
+ it("returns singular for count of 1", () => {
215
+ expect(templateHelpers.pluralize("item", 1)).toBe("item");
216
+ });
217
+ it("returns plural for count of 0", () => {
218
+ expect(templateHelpers.pluralize("item", 0)).toBe("items");
219
+ });
220
+ it("returns plural for count > 1", () => {
221
+ expect(templateHelpers.pluralize("item", 5)).toBe("items");
222
+ });
223
+ it("handles negative counts", () => {
224
+ expect(templateHelpers.pluralize("item", -1)).toBe("items");
225
+ });
226
+ });
227
+ });
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Common template helpers that can be passed to templates.
3
+ */
4
+
5
+ import {
6
+ capitalize,
7
+ indent,
8
+ join,
9
+ toCamelCase,
10
+ toConstantCase,
11
+ toKebabCase,
12
+ toPascalCase,
13
+ toSnakeCase,
14
+ } from "@canonical/utils";
15
+
16
+ const templateHelpers = {
17
+ camelCase: toCamelCase,
18
+ pascalCase: toPascalCase,
19
+ kebabCase: toKebabCase,
20
+ snakeCase: toSnakeCase,
21
+ constantCase: toConstantCase,
22
+ capitalize,
23
+ indent,
24
+ join,
25
+
26
+ isoDate: (): string => new Date().toISOString(),
27
+
28
+ year: (): number => new Date().getFullYear(),
29
+
30
+ pluralize: (word: string, count: number): string => {
31
+ return count === 1 ? word : `${word}s`;
32
+ },
33
+ };
34
+
35
+ export default templateHelpers;
@@ -0,0 +1,41 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import renderString from "./renderString.js";
3
+ import templateHelpers from "./templateHelpers.js";
4
+ import withHelpers from "./withHelpers.js";
5
+
6
+ describe("withHelpers", () => {
7
+ it("includes all template helpers", () => {
8
+ const vars = withHelpers({ name: "test" });
9
+
10
+ expect(vars.camelCase).toBe(templateHelpers.camelCase);
11
+ expect(vars.pascalCase).toBe(templateHelpers.pascalCase);
12
+ expect(vars.kebabCase).toBe(templateHelpers.kebabCase);
13
+ expect(vars.snakeCase).toBe(templateHelpers.snakeCase);
14
+ expect(vars.constantCase).toBe(templateHelpers.constantCase);
15
+ expect(vars.capitalize).toBe(templateHelpers.capitalize);
16
+ expect(vars.indent).toBe(templateHelpers.indent);
17
+ expect(vars.join).toBe(templateHelpers.join);
18
+ expect(vars.pluralize).toBe(templateHelpers.pluralize);
19
+ });
20
+
21
+ it("preserves user variables", () => {
22
+ const vars = withHelpers({ name: "MyComponent", version: "1.0.0" });
23
+
24
+ expect(vars.name).toBe("MyComponent");
25
+ expect(vars.version).toBe("1.0.0");
26
+ });
27
+
28
+ it("user variables override helpers", () => {
29
+ const customCapitalize = (s: string) => `CUSTOM: ${s}`;
30
+ const vars = withHelpers({ capitalize: customCapitalize });
31
+
32
+ expect(vars.capitalize).toBe(customCapitalize);
33
+ });
34
+
35
+ it("works with renderString", () => {
36
+ const vars = withHelpers({ name: "my-component" });
37
+ const result = renderString("<%= pascalCase(name) %>", vars);
38
+
39
+ expect(result).toBe("MyComponent");
40
+ });
41
+ });
@@ -0,0 +1,10 @@
1
+ import templateHelpers from "./templateHelpers.js";
2
+
3
+ /**
4
+ * Create a vars object with helpers included.
5
+ */
6
+ export default function withHelpers(
7
+ vars: Record<string, unknown>,
8
+ ): Record<string, unknown> {
9
+ return { ...templateHelpers, ...vars };
10
+ }
@@ -0,0 +1,69 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import renderString from "../../template/renderString.js";
3
+ import withHelpers from "../../template/withHelpers.js";
4
+
5
+ describe("template rendering integration", () => {
6
+ it("can use helpers in templates", () => {
7
+ const vars = withHelpers({
8
+ componentName: "my-button",
9
+ properties: ["label", "onClick", "disabled"],
10
+ });
11
+
12
+ const tpl = `
13
+ export const <%= pascalCase(componentName) %> = () => {
14
+ // Props: <%= join(properties) %>
15
+ };
16
+ `;
17
+
18
+ const result = renderString(tpl, vars);
19
+
20
+ expect(result).toContain("export const MyButton = () => {");
21
+ expect(result).toContain("// Props: label, onClick, disabled");
22
+ });
23
+
24
+ it("can generate TypeScript interfaces", () => {
25
+ const vars = withHelpers({
26
+ interfaceName: "button-props",
27
+ properties: [
28
+ { name: "label", type: "string" },
29
+ { name: "onClick", type: "() => void" },
30
+ { name: "disabled", type: "boolean" },
31
+ ],
32
+ });
33
+
34
+ const tpl = `
35
+ interface <%= pascalCase(interfaceName) %> {
36
+ <% properties.forEach(prop => { %>
37
+ <%= prop.name %>: <%- prop.type %>;
38
+ <% }) %>
39
+ }
40
+ `;
41
+
42
+ const result = renderString(tpl, vars);
43
+
44
+ expect(result).toContain("interface ButtonProps {");
45
+ expect(result).toContain("label: string;");
46
+ expect(result).toContain("onClick: () => void;");
47
+ expect(result).toContain("disabled: boolean;");
48
+ });
49
+
50
+ it("can generate import statements", () => {
51
+ const vars = withHelpers({
52
+ imports: [
53
+ { from: "react", names: ["useState", "useEffect"] },
54
+ { from: "./types", names: ["Props"] },
55
+ ],
56
+ });
57
+
58
+ const tpl = `
59
+ <% imports.forEach(imp => { %>
60
+ import { <%= join(imp.names) %> } from '<%= imp.from %>';
61
+ <% }) %>
62
+ `;
63
+
64
+ const result = renderString(tpl, vars);
65
+
66
+ expect(result).toContain("import { useState, useEffect } from 'react';");
67
+ expect(result).toContain("import { Props } from './types';");
68
+ });
69
+ });
@@ -0,0 +1,9 @@
1
+ import type GeneratorDefinition from "./GeneratorDefinition.js";
2
+
3
+ /**
4
+ * A generator definition without type parameters, used in barrels/collections.
5
+ */
6
+ // biome-ignore lint/suspicious/noExplicitAny: Required for contravariant generator collections
7
+ type AnyGenerator = GeneratorDefinition<any>;
8
+
9
+ export default AnyGenerator;
@@ -0,0 +1,23 @@
1
+ import type ReservedOption from "./ReservedOption.js";
2
+
3
+ /**
4
+ * Type helper that produces a compile-time error if T contains any reserved option names.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * interface BadAnswers {
9
+ * name: string;
10
+ * help: string; // Reserved!
11
+ * }
12
+ *
13
+ * // This will error: Type 'string' is not assignable to type '["Error: 'help' is a reserved option name"]'
14
+ * const generator: GeneratorDefinition<ForbidReserved<BadAnswers>> = { ... };
15
+ * ```
16
+ */
17
+ type ForbidReserved<T> = {
18
+ [K in keyof T]: K extends ReservedOption
19
+ ? [`Error: '${K & string}' is a reserved option name`]
20
+ : T[K];
21
+ };
22
+
23
+ export default ForbidReserved;
@@ -0,0 +1,19 @@
1
+ import type { Task } from "@canonical/task";
2
+ import type GeneratorMeta from "./GeneratorMeta.js";
3
+ import type PromptDefinition from "./PromptDefinition.js";
4
+
5
+ /**
6
+ * The complete definition of a generator.
7
+ *
8
+ * @typeParam TAnswers - Type of the answers object passed to generate
9
+ */
10
+ export default interface GeneratorDefinition<
11
+ TAnswers = Record<string, unknown>,
12
+ > {
13
+ /** Generator metadata for CLI display */
14
+ meta: GeneratorMeta;
15
+ /** Prompts to collect answers from user */
16
+ prompts: PromptDefinition[];
17
+ /** Pure function that returns a Task describing the generation */
18
+ generate: (answers: TAnswers) => Task<void>;
19
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Metadata for a generator, displayed in CLI help and discovery.
3
+ */
4
+ export default interface GeneratorMeta {
5
+ /** Generator name, used in CLI path (e.g., "component/react") */
6
+ name: string;
7
+ /**
8
+ * Name used in generated file stamp comments.
9
+ * Use this when the stamp should differ from the CLI command path
10
+ * (e.g., "@canonical/summon-component:react" vs "component/react").
11
+ */
12
+ displayName: string;
13
+ /** One-line description shown in generator listings */
14
+ description: string;
15
+ /** Semantic version of the generator */
16
+ version: string;
17
+ /** Author name or email */
18
+ author?: string;
19
+ /**
20
+ * Extended help text shown when calling `summon <topic>` (without subgenerator)
21
+ * and in --help. Use this for detailed explanation and examples.
22
+ * Supports markdown-like formatting.
23
+ */
24
+ help?: string;
25
+ /**
26
+ * Usage examples shown in help. Each example should show a common invocation.
27
+ */
28
+ examples?: string[];
29
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Definition of a prompt in a generator.
3
+ *
4
+ * Each prompt becomes a CLI flag. The prompt name is converted to kebab-case
5
+ * for the flag (e.g., `componentPath` → `--component-path`).
6
+ */
7
+ export default interface PromptDefinition {
8
+ /** Unique identifier, used as answer key and CLI flag name */
9
+ name: string;
10
+ /** Question text displayed to the user */
11
+ message: string;
12
+ /** Type of input */
13
+ type: "text" | "confirm" | "select" | "multiselect";
14
+ /** Default value if user provides no input */
15
+ default?: unknown;
16
+ /** Choices for select/multiselect prompts */
17
+ choices?: Array<{ label: string; value: string }>;
18
+ /** Conditional function - prompt is skipped if this returns false */
19
+ when?: (answers: Record<string, unknown>) => boolean;
20
+ /** Validation function, returns true or error message */
21
+ validate?: (value: unknown) => boolean | string;
22
+ /**
23
+ * Group name for organizing options in --help output.
24
+ * Options without a group appear under "Options".
25
+ */
26
+ group?: string;
27
+ /**
28
+ * If true, this prompt can be provided as a positional argument.
29
+ * Only one prompt per generator should be positional.
30
+ * Only text prompts can be positional.
31
+ */
32
+ positional?: boolean;
33
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Reserved option names for CLI global options.
3
+ * Generator prompts MUST NOT use these names.
4
+ */
5
+ type ReservedOption =
6
+ | "help"
7
+ | "version"
8
+ | "dryRun"
9
+ | "dry-run"
10
+ | "yes"
11
+ | "output"
12
+ | "preview"
13
+ | "generators"
14
+ | "run"
15
+ | "init"
16
+ | "llm"
17
+ | "format"
18
+ | "showFiles"
19
+ | "show-files"
20
+ | "verbose"
21
+ | "generatedStamp";
22
+
23
+ export default ReservedOption;
@@ -0,0 +1,6 @@
1
+ export default interface StampConfig {
2
+ /** Generator name (e.g., "@canonical/summon-package") */
3
+ generator: string;
4
+ /** Generator version (e.g., "0.1.0") */
5
+ version: string;
6
+ }
@@ -0,0 +1,7 @@
1
+ export type { default as AnyGenerator } from "./AnyGenerator.js";
2
+ export type { default as ForbidReserved } from "./ForbidReserved.js";
3
+ export type { default as GeneratorDefinition } from "./GeneratorDefinition.js";
4
+ export type { default as GeneratorMeta } from "./GeneratorMeta.js";
5
+ export type { default as PromptDefinition } from "./PromptDefinition.js";
6
+ export type { default as ReservedOption } from "./ReservedOption.js";
7
+ export type { default as StampConfig } from "./StampConfig.js";
package/src/cli-types.ts DELETED
@@ -1,59 +0,0 @@
1
- /**
2
- * CLI Type Definitions
3
- *
4
- * Types for generator authors to validate their prompt names at compile-time.
5
- */
6
-
7
- /**
8
- * Reserved option names for CLI global options.
9
- * Generator prompts MUST NOT use these names.
10
- *
11
- * Use the `ForbidReserved` type to enforce at compile-time:
12
- * @example
13
- * ```typescript
14
- * interface MyAnswers {
15
- * name: string; // OK
16
- * help: string; // Will cause type error
17
- * }
18
- *
19
- * // This will produce a compile-time error if any key is reserved
20
- * type ValidatedAnswers = ForbidReserved<MyAnswers>;
21
- * ```
22
- */
23
- export type ReservedOption =
24
- | "help"
25
- | "version"
26
- | "dryRun"
27
- | "dry-run"
28
- | "yes"
29
- | "output"
30
- | "preview"
31
- | "generators"
32
- | "run"
33
- | "init"
34
- | "llm"
35
- | "format"
36
- | "showFiles"
37
- | "show-files"
38
- | "verbose"
39
- | "generatedStamp";
40
-
41
- /**
42
- * Type helper that produces a compile-time error if T contains any reserved option names.
43
- *
44
- * @example
45
- * ```typescript
46
- * interface BadAnswers {
47
- * name: string;
48
- * help: string; // Reserved!
49
- * }
50
- *
51
- * // This will error: Type 'string' is not assignable to type '["Error: 'help' is a reserved option name"]'
52
- * const generator: GeneratorDefinition<ForbidReserved<BadAnswers>> = { ... };
53
- * ```
54
- */
55
- export type ForbidReserved<T> = {
56
- [K in keyof T]: K extends ReservedOption
57
- ? [`Error: '${K & string}' is a reserved option name`]
58
- : T[K];
59
- };