@canonical/summon 0.29.0 → 0.30.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 (76) hide show
  1. package/dist/generators/example/hello/index.js +104 -0
  2. package/dist/generators/example/hello/index.js.map +1 -0
  3. package/dist/generators/example/webapp/index.js +374 -0
  4. package/dist/generators/example/webapp/index.js.map +1 -0
  5. package/dist/generators/init/index.js +98 -0
  6. package/dist/generators/init/index.js.map +1 -0
  7. package/dist/src/bin.js +153 -0
  8. package/dist/src/bin.js.map +1 -0
  9. package/dist/src/completion.js +375 -0
  10. package/dist/src/completion.js.map +1 -0
  11. package/dist/src/components/App.js +621 -0
  12. package/dist/src/components/App.js.map +1 -0
  13. package/dist/src/components/ExecutionProgress.js +132 -0
  14. package/dist/src/components/ExecutionProgress.js.map +1 -0
  15. package/dist/src/components/FileTreePreview.js +55 -0
  16. package/dist/src/components/FileTreePreview.js.map +1 -0
  17. package/dist/src/components/PromptSequence.js +215 -0
  18. package/dist/src/components/PromptSequence.js.map +1 -0
  19. package/dist/src/components/Spinner.js +20 -0
  20. package/dist/src/components/Spinner.js.map +1 -0
  21. package/{src/components/index.ts → dist/src/components/index.js} +1 -6
  22. package/dist/src/components/index.js.map +1 -0
  23. package/{src/discovery/index.ts → dist/src/discovery/index.js} +1 -0
  24. package/dist/src/discovery/index.js.map +1 -0
  25. package/dist/src/discovery/loadGenerator.js +29 -0
  26. package/dist/src/discovery/loadGenerator.js.map +1 -0
  27. package/{src/display/index.ts → dist/src/display/index.js} +1 -0
  28. package/dist/src/display/index.js.map +1 -0
  29. package/dist/src/display/printGeneratorHelp.js +99 -0
  30. package/dist/src/display/printGeneratorHelp.js.map +1 -0
  31. package/dist/src/display/printNode.js +64 -0
  32. package/dist/src/display/printNode.js.map +1 -0
  33. package/dist/src/registration/buildCommandBarrel.js +45 -0
  34. package/dist/src/registration/buildCommandBarrel.js.map +1 -0
  35. package/{src/registration/index.ts → dist/src/registration/index.js} +1 -1
  36. package/dist/src/registration/index.js.map +1 -0
  37. package/dist/src/registration/registerFromBarrel.js +408 -0
  38. package/dist/src/registration/registerFromBarrel.js.map +1 -0
  39. package/dist/src/registration/types.js +2 -0
  40. package/dist/src/registration/types.js.map +1 -0
  41. package/package.json +13 -15
  42. package/generators/application/react/index.ts +0 -4
  43. package/generators/domain/index.ts +0 -4
  44. package/generators/example/hello/index.ts +0 -126
  45. package/generators/example/webapp/index.ts +0 -511
  46. package/generators/init/index.ts +0 -119
  47. package/generators/route/index.ts +0 -4
  48. package/generators/wrapper/index.ts +0 -4
  49. package/src/bin.tsx +0 -199
  50. package/src/completion.test.ts +0 -202
  51. package/src/completion.ts +0 -492
  52. package/src/components/App.tsx +0 -1053
  53. package/src/components/ExecutionProgress.tsx +0 -209
  54. package/src/components/FileTreePreview.tsx +0 -97
  55. package/src/components/PromptSequence.tsx +0 -483
  56. package/src/components/Spinner.tsx +0 -36
  57. package/src/discovery/loadGenerator.ts +0 -37
  58. package/src/display/printGeneratorHelp.ts +0 -128
  59. package/src/display/printNode.ts +0 -76
  60. package/src/registration/buildCommandBarrel.ts +0 -57
  61. package/src/registration/registerFromBarrel.tsx +0 -548
  62. package/src/registration/types.ts +0 -28
  63. /package/{generators → dist/generators}/example/hello/templates/README.md.ejs +0 -0
  64. /package/{generators → dist/generators}/example/hello/templates/index.ts.ejs +0 -0
  65. /package/{generators → dist/generators}/example/webapp/templates/ARCHITECTURE.md.ejs +0 -0
  66. /package/{generators → dist/generators}/example/webapp/templates/App.tsx.ejs +0 -0
  67. /package/{generators → dist/generators}/example/webapp/templates/README.md.ejs +0 -0
  68. /package/{generators → dist/generators}/example/webapp/templates/app.test.ts.ejs +0 -0
  69. /package/{generators → dist/generators}/example/webapp/templates/app.ts.ejs +0 -0
  70. /package/{generators → dist/generators}/example/webapp/templates/feature.ts.ejs +0 -0
  71. /package/{generators → dist/generators}/example/webapp/templates/index.html.ejs +0 -0
  72. /package/{generators → dist/generators}/example/webapp/templates/main.tsx.ejs +0 -0
  73. /package/{generators → dist/generators}/example/webapp/templates/styles.css.ejs +0 -0
  74. /package/{generators → dist/generators}/init/templates/generator.ts.ejs +0 -0
  75. /package/{generators → dist/generators}/init/templates/template-index.ts.ejs +0 -0
  76. /package/{generators → dist/generators}/init/templates/template-test.ts.ejs +0 -0
@@ -1,209 +0,0 @@
1
- /**
2
- * ExecutionProgress Component
3
- *
4
- * Displays the progress of task execution with effect-by-effect feedback.
5
- */
6
-
7
- import { runTaskWithStamp, type StampConfig } from "@canonical/summon-core";
8
- import {
9
- describeEffect,
10
- type Effect,
11
- type Task,
12
- type TaskError,
13
- } from "@canonical/task";
14
- import { Box, Text } from "ink";
15
- import type React from "react";
16
- import { useEffect, useState } from "react";
17
- import { Spinner } from "./Spinner.js";
18
-
19
- /** Effect with timing information for the completion timeline */
20
- export interface TimedEffect {
21
- effect: Effect;
22
- /** Time in ms when this effect completed, relative to execution start */
23
- timestamp: number;
24
- }
25
-
26
- export interface ExecutionProgressProps {
27
- /** The task to execute */
28
- task: Task<void>;
29
- /** Whether to run in dry-run mode */
30
- dryRun?: boolean;
31
- /** Called when execution completes */
32
- onComplete: (effects: TimedEffect[], duration: number) => void;
33
- /** Called when execution fails */
34
- onError: (error: TaskError) => void;
35
- /** Stamp configuration for generated files (undefined = no stamps) */
36
- stamp?: StampConfig;
37
- }
38
-
39
- interface CompletedEffect {
40
- id: number;
41
- effect: Effect;
42
- duration: number;
43
- timestamp: number;
44
- }
45
-
46
- interface LogMessage {
47
- id: number;
48
- level: "debug" | "info" | "warn" | "error";
49
- message: string;
50
- }
51
-
52
- /** Effects that should be hidden from the progress display (internal/noisy) */
53
- const isInternalEffect = (effect: Effect): boolean => {
54
- // Hide internal coordination effects
55
- if (
56
- effect._tag === "Log" ||
57
- effect._tag === "Exists" ||
58
- effect._tag === "ReadContext" ||
59
- effect._tag === "WriteContext" ||
60
- effect._tag === "Parallel" ||
61
- effect._tag === "Race"
62
- ) {
63
- return true;
64
- }
65
- // Hide template file reads (internal implementation detail)
66
- if (effect._tag === "ReadFile" && effect.path.includes("/templates/")) {
67
- return true;
68
- }
69
- return false;
70
- };
71
-
72
- export const ExecutionProgress: React.FC<ExecutionProgressProps> = ({
73
- task,
74
- dryRun: _dryRun = false,
75
- onComplete,
76
- onError,
77
- stamp,
78
- }) => {
79
- const [currentEffect, setCurrentEffect] = useState<Effect | null>(null);
80
- const [completedEffects, setCompletedEffects] = useState<CompletedEffect[]>(
81
- [],
82
- );
83
- const [logMessages, setLogMessages] = useState<LogMessage[]>([]);
84
- const [isRunning, setIsRunning] = useState(true);
85
-
86
- useEffect(() => {
87
- const collectedEffects: TimedEffect[] = [];
88
- const startTime = performance.now();
89
- let effectId = 0;
90
- let logId = 0;
91
- // Track seen directory paths to deduplicate MakeDir effects in live progress
92
- const seenDirPaths = new Set<string>();
93
-
94
- const executeWithProgress = async () => {
95
- try {
96
- await runTaskWithStamp(task, {
97
- stamp,
98
- onEffectStart: (effect) => {
99
- // Skip showing duplicate MakeDir in spinner
100
- if (effect._tag === "MakeDir" && seenDirPaths.has(effect.path)) {
101
- return;
102
- }
103
- setCurrentEffect(effect);
104
- },
105
- onEffectComplete: (effect, duration) => {
106
- const id = effectId++;
107
- const timestamp = performance.now() - startTime;
108
- collectedEffects.push({ effect, timestamp });
109
- // Skip duplicate MakeDir effects in live display
110
- if (effect._tag === "MakeDir") {
111
- if (seenDirPaths.has(effect.path)) {
112
- setCurrentEffect(null);
113
- return;
114
- }
115
- seenDirPaths.add(effect.path);
116
- }
117
- setCompletedEffects((prev) => [
118
- ...prev,
119
- { id, effect, duration, timestamp },
120
- ]);
121
- setCurrentEffect(null);
122
- },
123
- onLog: (level, message) => {
124
- const id = logId++;
125
- setLogMessages((prev) => [...prev, { id, level, message }]);
126
- },
127
- });
128
-
129
- const duration = performance.now() - startTime;
130
- onComplete(collectedEffects, duration);
131
- } catch (err) {
132
- const taskError: TaskError =
133
- err instanceof Error
134
- ? {
135
- code: "EXECUTION_ERROR",
136
- message: err.message,
137
- stack: err.stack,
138
- }
139
- : {
140
- code: "UNKNOWN_ERROR",
141
- message: String(err),
142
- };
143
- onError(taskError);
144
- } finally {
145
- setIsRunning(false);
146
- }
147
- };
148
-
149
- executeWithProgress();
150
- }, [task, onComplete, onError, stamp]);
151
-
152
- const logColor = (level: LogMessage["level"]) => {
153
- switch (level) {
154
- case "debug":
155
- return "gray";
156
- case "info":
157
- return "blue";
158
- case "warn":
159
- return "yellow";
160
- case "error":
161
- return "red";
162
- }
163
- };
164
-
165
- const logIcon = (level: LogMessage["level"]) => {
166
- switch (level) {
167
- case "debug":
168
- return "·";
169
- case "info":
170
- return "›";
171
- case "warn":
172
- return "⚠";
173
- case "error":
174
- return "✗";
175
- }
176
- };
177
-
178
- return (
179
- <Box flexDirection="column">
180
- {/* Show log messages */}
181
- {logMessages.map((log) => (
182
- <Text key={`log-${log.id}`}>
183
- <Text color={logColor(log.level)}>{logIcon(log.level)}</Text>{" "}
184
- <Text>{log.message}</Text>
185
- </Text>
186
- ))}
187
- {/* Show completed file effects (excluding internal/noisy effects) */}
188
- {completedEffects
189
- .filter((item) => !isInternalEffect(item.effect))
190
- .map((item) => (
191
- <Text key={`effect-${item.id}`}>
192
- <Text color="green">✓</Text> {describeEffect(item.effect)}{" "}
193
- <Text dimColor>({item.duration.toFixed(0)}ms)</Text>
194
- </Text>
195
- ))}
196
- {currentEffect && !isInternalEffect(currentEffect) && (
197
- <Box>
198
- <Spinner color="blue" />
199
- <Text> {describeEffect(currentEffect)}</Text>
200
- </Box>
201
- )}
202
- {isRunning && !currentEffect && (
203
- <Box>
204
- <Spinner color="blue" label="Executing..." />
205
- </Box>
206
- )}
207
- </Box>
208
- );
209
- };
@@ -1,97 +0,0 @@
1
- /**
2
- * FileTreePreview Component
3
- *
4
- * Displays a list of files that will be created/modified.
5
- */
6
-
7
- import type { Effect } from "@canonical/task";
8
- import { Box, Text } from "ink";
9
-
10
- export interface FileTreePreviewProps {
11
- /** Effects to display */
12
- effects: Effect[];
13
- /** Title for the preview */
14
- title?: string;
15
- }
16
-
17
- const formatBytes = (bytes: number): string => {
18
- if (bytes < 1024) return `${bytes} B`;
19
- if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
20
- return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
21
- };
22
-
23
- const getEffectInfo = (
24
- effect: Effect,
25
- ): { path: string; action: string; size?: number } | null => {
26
- switch (effect._tag) {
27
- case "WriteFile":
28
- return {
29
- path: effect.path,
30
- action: "create",
31
- size: effect.content.length,
32
- };
33
- case "MakeDir":
34
- return { path: effect.path, action: "mkdir" };
35
- case "CopyFile":
36
- return { path: effect.dest, action: "copy" };
37
- case "DeleteFile":
38
- return { path: effect.path, action: "delete" };
39
- case "DeleteDirectory":
40
- return { path: effect.path, action: "rmdir" };
41
- default:
42
- return null;
43
- }
44
- };
45
-
46
- export const FileTreePreview = ({
47
- effects,
48
- title = "Files to be created:",
49
- }: FileTreePreviewProps) => {
50
- // Deduplicate effects by path (keep first occurrence, which preserves WriteFile over MakeDir)
51
- const seen = new Set<string>();
52
- const fileEffects = effects
53
- .map(getEffectInfo)
54
- .filter((info): info is NonNullable<typeof info> => {
55
- if (info === null) return false;
56
- if (seen.has(info.path)) return false;
57
- seen.add(info.path);
58
- return true;
59
- })
60
- .sort((a, b) => a.path.localeCompare(b.path));
61
-
62
- if (fileEffects.length === 0) {
63
- return (
64
- <Box>
65
- <Text dimColor>No files will be created.</Text>
66
- </Box>
67
- );
68
- }
69
-
70
- return (
71
- <Box flexDirection="column">
72
- <Text bold color="cyan">
73
- {title}
74
- </Text>
75
- <Box marginLeft={1} flexDirection="column">
76
- {fileEffects.map((info) => {
77
- const actionColor =
78
- info.action === "delete" || info.action === "rmdir"
79
- ? "red"
80
- : "green";
81
- const actionIcon =
82
- info.action === "delete" || info.action === "rmdir" ? "-" : "+";
83
-
84
- return (
85
- <Box key={info.path}>
86
- <Text color={actionColor}>{actionIcon} </Text>
87
- <Text>{info.path}</Text>
88
- {info.size !== undefined && (
89
- <Text dimColor> ({formatBytes(info.size)})</Text>
90
- )}
91
- </Box>
92
- );
93
- })}
94
- </Box>
95
- </Box>
96
- );
97
- };