@canonical/summon 0.17.1 → 0.20.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.
- package/generators/example/hello/index.ts +3 -9
- package/generators/example/webapp/index.ts +7 -5
- package/generators/init/index.ts +3 -8
- package/generators/init/templates/generator.ts.ejs +3 -9
- package/package.json +24 -27
- package/src/bin.tsx +199 -0
- package/src/completion.ts +4 -1
- package/src/components/App.tsx +108 -15
- package/src/components/ExecutionProgress.tsx +8 -4
- package/src/components/FileTreePreview.tsx +1 -1
- package/src/components/PromptSequence.tsx +1 -1
- package/src/discovery/loadGenerator.ts +37 -0
- package/src/display/index.ts +2 -0
- package/src/display/printGeneratorHelp.ts +133 -0
- package/src/display/printNode.ts +76 -0
- package/src/registration/buildCommandBarrel.ts +57 -0
- package/src/registration/index.ts +3 -0
- package/src/registration/registerFromBarrel.tsx +548 -0
- package/src/registration/types.ts +28 -0
- package/README.md +0 -446
- package/src/__tests__/combinators.test.ts +0 -895
- package/src/__tests__/dry-run.test.ts +0 -927
- package/src/__tests__/effect.test.ts +0 -816
- package/src/__tests__/interpreter.test.ts +0 -673
- package/src/__tests__/primitives.test.ts +0 -970
- package/src/__tests__/task.test.ts +0 -929
- package/src/__tests__/template.test.ts +0 -666
- package/src/cli-format.ts +0 -236
- package/src/cli-types.ts +0 -53
- package/src/cli.tsx +0 -1366
- package/src/combinators.ts +0 -294
- package/src/dry-run.ts +0 -434
- package/src/effect.ts +0 -224
- package/src/index.ts +0 -266
- package/src/interpreter.ts +0 -463
- package/src/primitives.ts +0 -442
- package/src/task.ts +0 -245
- package/src/template.ts +0 -537
- package/src/types.ts +0 -453
package/src/cli-format.ts
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI Formatting Utilities
|
|
3
|
-
*
|
|
4
|
-
* Shared formatting functions for CLI output (both interactive and batch modes).
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import chalk from "chalk";
|
|
8
|
-
import type { Effect } from "./types.js";
|
|
9
|
-
|
|
10
|
-
// Fixed width for action label column
|
|
11
|
-
const ACTION_LABEL_WIDTH = 14;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Filter effects to only show user-relevant ones (not internal effects).
|
|
15
|
-
* @param effect - The effect to check
|
|
16
|
-
* @param verbose - If true, include debug logs
|
|
17
|
-
*/
|
|
18
|
-
export const isVisibleEffect = (effect: Effect, verbose = false): boolean => {
|
|
19
|
-
switch (effect._tag) {
|
|
20
|
-
case "WriteFile":
|
|
21
|
-
case "AppendFile":
|
|
22
|
-
case "MakeDir":
|
|
23
|
-
case "CopyFile":
|
|
24
|
-
case "CopyDirectory":
|
|
25
|
-
case "DeleteFile":
|
|
26
|
-
case "DeleteDirectory":
|
|
27
|
-
case "Exec":
|
|
28
|
-
return true;
|
|
29
|
-
case "Log":
|
|
30
|
-
// Filter out debug logs unless verbose is enabled
|
|
31
|
-
if (effect.level === "debug") {
|
|
32
|
-
return verbose;
|
|
33
|
-
}
|
|
34
|
-
return true;
|
|
35
|
-
// Internal effects are not shown
|
|
36
|
-
case "ReadFile":
|
|
37
|
-
case "Exists":
|
|
38
|
-
case "Glob":
|
|
39
|
-
case "ReadContext":
|
|
40
|
-
case "WriteContext":
|
|
41
|
-
case "Prompt":
|
|
42
|
-
case "Parallel":
|
|
43
|
-
case "Race":
|
|
44
|
-
return false;
|
|
45
|
-
default:
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Get human-readable action label for an effect.
|
|
52
|
-
*/
|
|
53
|
-
export const getActionLabel = (effect: Effect): string => {
|
|
54
|
-
switch (effect._tag) {
|
|
55
|
-
case "WriteFile":
|
|
56
|
-
return "Create file";
|
|
57
|
-
case "AppendFile":
|
|
58
|
-
return "Append to";
|
|
59
|
-
case "MakeDir":
|
|
60
|
-
return "Create dir";
|
|
61
|
-
case "CopyFile":
|
|
62
|
-
return "Copy file";
|
|
63
|
-
case "CopyDirectory":
|
|
64
|
-
return "Copy dir";
|
|
65
|
-
case "DeleteFile":
|
|
66
|
-
return "Delete file";
|
|
67
|
-
case "DeleteDirectory":
|
|
68
|
-
return "Delete dir";
|
|
69
|
-
case "Exec":
|
|
70
|
-
return "Execute";
|
|
71
|
-
case "Log":
|
|
72
|
-
switch (effect.level) {
|
|
73
|
-
case "debug":
|
|
74
|
-
return "Debug";
|
|
75
|
-
case "info":
|
|
76
|
-
return "Info";
|
|
77
|
-
case "warn":
|
|
78
|
-
return "Warning";
|
|
79
|
-
case "error":
|
|
80
|
-
return "Error";
|
|
81
|
-
default:
|
|
82
|
-
return "Log";
|
|
83
|
-
}
|
|
84
|
-
default:
|
|
85
|
-
return effect._tag;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Get color for action label based on effect type.
|
|
91
|
-
*/
|
|
92
|
-
export const getActionColor = (
|
|
93
|
-
effect: Effect,
|
|
94
|
-
): "green" | "red" | "yellow" | "cyan" | "blue" | "magenta" | undefined => {
|
|
95
|
-
switch (effect._tag) {
|
|
96
|
-
case "WriteFile":
|
|
97
|
-
case "MakeDir":
|
|
98
|
-
return "green";
|
|
99
|
-
case "AppendFile":
|
|
100
|
-
return "magenta";
|
|
101
|
-
case "DeleteFile":
|
|
102
|
-
case "DeleteDirectory":
|
|
103
|
-
return "red";
|
|
104
|
-
case "CopyFile":
|
|
105
|
-
case "CopyDirectory":
|
|
106
|
-
return "cyan";
|
|
107
|
-
case "Exec":
|
|
108
|
-
return "yellow";
|
|
109
|
-
case "Log":
|
|
110
|
-
switch (effect.level) {
|
|
111
|
-
case "error":
|
|
112
|
-
return "red";
|
|
113
|
-
case "warn":
|
|
114
|
-
return "yellow";
|
|
115
|
-
case "debug":
|
|
116
|
-
return undefined; // dim by default
|
|
117
|
-
default:
|
|
118
|
-
return "blue";
|
|
119
|
-
}
|
|
120
|
-
default:
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Get the payload (description) for an effect.
|
|
127
|
-
*/
|
|
128
|
-
export const getEffectPayload = (effect: Effect): string => {
|
|
129
|
-
switch (effect._tag) {
|
|
130
|
-
case "WriteFile":
|
|
131
|
-
return effect.path;
|
|
132
|
-
case "AppendFile":
|
|
133
|
-
return effect.path;
|
|
134
|
-
case "MakeDir":
|
|
135
|
-
return effect.path;
|
|
136
|
-
case "CopyFile":
|
|
137
|
-
return `${effect.source} → ${effect.dest}`;
|
|
138
|
-
case "CopyDirectory":
|
|
139
|
-
return `${effect.source}/ → ${effect.dest}/`;
|
|
140
|
-
case "DeleteFile":
|
|
141
|
-
case "DeleteDirectory":
|
|
142
|
-
return effect.path;
|
|
143
|
-
case "Exec":
|
|
144
|
-
return `${effect.command} ${effect.args.join(" ")}`;
|
|
145
|
-
case "Log":
|
|
146
|
-
return effect.message;
|
|
147
|
-
default:
|
|
148
|
-
return effect._tag;
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Format a single effect as a CLI line (for non-interactive output).
|
|
154
|
-
*/
|
|
155
|
-
export const formatEffectLine = (effect: Effect, isLast: boolean): string => {
|
|
156
|
-
const connector = isLast ? "└─" : "├─";
|
|
157
|
-
const actionLabel = getActionLabel(effect);
|
|
158
|
-
const color = getActionColor(effect);
|
|
159
|
-
const payload = getEffectPayload(effect);
|
|
160
|
-
|
|
161
|
-
const colorFn = color ? chalk[color] : (s: string) => s;
|
|
162
|
-
const paddedLabel = actionLabel.padEnd(ACTION_LABEL_WIDTH);
|
|
163
|
-
|
|
164
|
-
return `${chalk.dim(connector)} ${colorFn(paddedLabel)}${payload}`;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Maximum number of lines to show in content preview.
|
|
169
|
-
*/
|
|
170
|
-
const MAX_PREVIEW_LINES = 50;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Maximum width for content lines (will truncate).
|
|
174
|
-
*/
|
|
175
|
-
const MAX_LINE_WIDTH = 120;
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Format file content for preview display.
|
|
179
|
-
* Shows line numbers and truncates long content.
|
|
180
|
-
*
|
|
181
|
-
* @param content - The file content to format
|
|
182
|
-
* @param maxLines - Maximum number of lines to show (default: MAX_PREVIEW_LINES)
|
|
183
|
-
*/
|
|
184
|
-
export const formatContentPreview = (
|
|
185
|
-
content: string,
|
|
186
|
-
maxLines: number = MAX_PREVIEW_LINES,
|
|
187
|
-
): string => {
|
|
188
|
-
const lines = content.split("\n");
|
|
189
|
-
const totalLines = lines.length;
|
|
190
|
-
const showLines = lines.slice(0, maxLines);
|
|
191
|
-
const lineNumWidth = String(Math.min(totalLines, maxLines)).length;
|
|
192
|
-
|
|
193
|
-
const formatted = showLines.map((line, i) => {
|
|
194
|
-
const lineNum = String(i + 1).padStart(lineNumWidth, " ");
|
|
195
|
-
const truncatedLine =
|
|
196
|
-
line.length > MAX_LINE_WIDTH
|
|
197
|
-
? `${line.slice(0, MAX_LINE_WIDTH - 3)}...`
|
|
198
|
-
: line;
|
|
199
|
-
return `${chalk.dim(`${lineNum} │`)} ${truncatedLine}`;
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
if (totalLines > maxLines) {
|
|
203
|
-
formatted.push(
|
|
204
|
-
chalk.dim(` ... (${totalLines - maxLines} more lines omitted)`),
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return formatted.join("\n");
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Format an effect with its content (for verbose dry-run mode).
|
|
213
|
-
* This is useful for LLM agents that need to see generated file contents.
|
|
214
|
-
*
|
|
215
|
-
* @param effect - The effect to format
|
|
216
|
-
* @param isLast - Whether this is the last effect in the list
|
|
217
|
-
*/
|
|
218
|
-
export const formatEffectWithContent = (
|
|
219
|
-
effect: Effect,
|
|
220
|
-
isLast: boolean,
|
|
221
|
-
): string => {
|
|
222
|
-
const baseLine = formatEffectLine(effect, isLast);
|
|
223
|
-
|
|
224
|
-
// Only show content for WriteFile and AppendFile effects
|
|
225
|
-
if (effect._tag === "WriteFile" || effect._tag === "AppendFile") {
|
|
226
|
-
const indent = isLast ? " " : "│ ";
|
|
227
|
-
const contentPreview = formatContentPreview(effect.content);
|
|
228
|
-
const indentedContent = contentPreview
|
|
229
|
-
.split("\n")
|
|
230
|
-
.map((line) => `${chalk.dim(indent)}${line}`)
|
|
231
|
-
.join("\n");
|
|
232
|
-
return `${baseLine}\n${indentedContent}`;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return baseLine;
|
|
236
|
-
};
|
package/src/cli-types.ts
DELETED
|
@@ -1,53 +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
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Type helper that produces a compile-time error if T contains any reserved option names.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```typescript
|
|
40
|
-
* interface BadAnswers {
|
|
41
|
-
* name: string;
|
|
42
|
-
* help: string; // Reserved!
|
|
43
|
-
* }
|
|
44
|
-
*
|
|
45
|
-
* // This will error: Type 'string' is not assignable to type '["Error: 'help' is a reserved option name"]'
|
|
46
|
-
* const generator: GeneratorDefinition<ForbidReserved<BadAnswers>> = { ... };
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export type ForbidReserved<T> = {
|
|
50
|
-
[K in keyof T]: K extends ReservedOption
|
|
51
|
-
? [`Error: '${K & string}' is a reserved option name`]
|
|
52
|
-
: T[K];
|
|
53
|
-
};
|