@canonical/summon 0.30.0 → 0.31.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.
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Hello World Generator (Demo)
3
+ *
4
+ * A simple example generator that demonstrates the core features of Summon,
5
+ * including EJS templates and the withHelpers utility.
6
+ *
7
+ * Use this as a reference when building your own generators.
8
+ */
9
+ import type { GeneratorDefinition } from "@canonical/summon-core";
10
+ interface HelloAnswers {
11
+ name: string;
12
+ description: string;
13
+ greeting: string;
14
+ withReadme: boolean;
15
+ [key: string]: unknown;
16
+ }
17
+ export declare const generator: GeneratorDefinition<HelloAnswers>;
18
+ export default generator;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Web App Generator (Advanced Demo)
3
+ *
4
+ * A comprehensive example generator that demonstrates the full power of Summon,
5
+ * including parallel operations, file I/O, conditionals, error handling,
6
+ * context management, and template rendering.
7
+ *
8
+ * Use this as a reference for building complex generators.
9
+ */
10
+ import type { GeneratorDefinition } from "@canonical/summon-core";
11
+ interface WebAppAnswers {
12
+ name: string;
13
+ description: string;
14
+ framework: "react" | "vanilla";
15
+ styling: "css" | "tailwind" | "none";
16
+ features: string[];
17
+ withTests: boolean;
18
+ withDocs: boolean;
19
+ installDeps: boolean;
20
+ }
21
+ export declare const generator: GeneratorDefinition<WebAppAnswers>;
22
+ export default generator;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Init Generator
3
+ *
4
+ * Scaffolds a new Summon generator with templates and test structure.
5
+ */
6
+ import type { GeneratorDefinition } from "@canonical/summon-core";
7
+ interface Answers {
8
+ /** Generator path (e.g., "my-gen" or "component/vue") */
9
+ generatorPath: string;
10
+ /** Description of the generator */
11
+ description: string;
12
+ /** Output directory for generators */
13
+ outputDir: string;
14
+ }
15
+ export declare const generator: GeneratorDefinition<Answers>;
16
+ export default generator;
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Summon CLI — thin orchestrator.
4
+ *
5
+ * Wires together generator discovery, display, registration, and completion.
6
+ * All domain logic lives in the corresponding modules.
7
+ *
8
+ * @note Impure — CLI entry point.
9
+ */
10
+ export {};
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Shell Autocompletion Support for Summon CLI
3
+ *
4
+ * Uses omelette to provide TAB completion for:
5
+ * - Generator names (navigating the command tree)
6
+ * - Generator arguments (based on prompt definitions)
7
+ * - File/folder paths for path-related prompts
8
+ *
9
+ * Supports Bash, Zsh, and Fish shells.
10
+ */
11
+ import type { GeneratorDefinition, PromptDefinition } from "@canonical/summon-core";
12
+ import omelette from "omelette";
13
+ /** Represents a node in the generator tree (simplified for completion) */
14
+ export interface CompletionNode {
15
+ name: string;
16
+ indexPath?: string;
17
+ children: Map<string, CompletionNode>;
18
+ }
19
+ /**
20
+ * Detect if a prompt expects a file/folder path based on its name or message.
21
+ */
22
+ export declare const isPathPrompt: (prompt: PromptDefinition) => boolean;
23
+ /**
24
+ * Get filesystem path completions for a partial path.
25
+ */
26
+ export declare const getPathCompletions: (partial: string) => string[];
27
+ /**
28
+ * Get completions for generator arguments based on prompt definitions.
29
+ *
30
+ * @param prompts - The prompt definitions for the generator
31
+ * @param line - The current command line
32
+ * @param before - The word before the cursor
33
+ * @param showAll - If true, show all flags even if line doesn't contain --
34
+ */
35
+ export declare const getArgumentCompletions: (prompts: PromptDefinition[], line: string, before: string, showAll?: boolean) => string[];
36
+ /**
37
+ * Generator loader function type - passed in to avoid circular dependencies.
38
+ */
39
+ export type GeneratorLoader = (indexPath: string) => Promise<GeneratorDefinition>;
40
+ /**
41
+ * Initialize shell completion for the summon CLI.
42
+ *
43
+ * This should be called early in the CLI lifecycle, before commander parsing,
44
+ * because omelette needs to intercept completion requests.
45
+ *
46
+ * @param generatorTree - The root of the generator tree
47
+ * @param loadGenerator - Function to load a generator from its path
48
+ * @returns The omelette instance (for setup/cleanup methods)
49
+ */
50
+ export declare const initCompletion: (generatorTree: CompletionNode, loadGenerator: GeneratorLoader) => Promise<omelette.Instance>;
51
+ /**
52
+ * Check if the current invocation is a completion request.
53
+ * This allows us to skip normal CLI processing for completion.
54
+ */
55
+ export declare const isCompletionRequest: () => boolean;
56
+ /**
57
+ * Check if this is a setup or cleanup request.
58
+ */
59
+ export declare const isSetupRequest: () => boolean;
60
+ /**
61
+ * Handle setup/cleanup requests.
62
+ */
63
+ export declare const handleSetupRequest: (complete: omelette.Instance) => void;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * App Component
3
+ *
4
+ * Main CLI application component using React Ink.
5
+ */
6
+ import type { GeneratorDefinition, StampConfig } from "@canonical/summon-core";
7
+ import { type Effect, type Task, type TaskError } from "@canonical/task";
8
+ import { type TimedEffect } from "./ExecutionProgress.js";
9
+ export type AppState = {
10
+ phase: "loading";
11
+ } | {
12
+ phase: "prompting";
13
+ } | {
14
+ phase: "preview";
15
+ effects: Effect[];
16
+ } | {
17
+ phase: "confirming";
18
+ effects: Effect[];
19
+ promptAnswers: Record<string, unknown>;
20
+ } | {
21
+ phase: "executing";
22
+ task: Task<void>;
23
+ } | {
24
+ phase: "complete";
25
+ effects: TimedEffect[];
26
+ duration: number;
27
+ } | {
28
+ phase: "error";
29
+ error: TaskError;
30
+ answers?: Record<string, unknown>;
31
+ };
32
+ export interface AppProps {
33
+ /** The generator to run */
34
+ generator: GeneratorDefinition;
35
+ /** Whether to show a preview before executing */
36
+ preview?: boolean;
37
+ /** Whether to run in dry-run mode only */
38
+ dryRunOnly?: boolean;
39
+ /** Whether to reverse a previously executed generator */
40
+ undo?: boolean;
41
+ /** Whether to show debug output */
42
+ verbose?: boolean;
43
+ /** Pre-filled answers (for non-interactive mode) */
44
+ answers?: Record<string, unknown>;
45
+ /** Stamp configuration for generated files (undefined = no stamps) */
46
+ stamp?: StampConfig;
47
+ }
48
+ export declare const App: ({ generator, preview, dryRunOnly, undo, verbose, answers: prefilledAnswers, stamp, }: AppProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * ExecutionProgress Component
3
+ *
4
+ * Displays the progress of task execution with effect-by-effect feedback.
5
+ */
6
+ import type { StampConfig } from "@canonical/summon-core";
7
+ import { type Effect, type Task, type TaskError } from "@canonical/task";
8
+ import type React from "react";
9
+ /** Effect with timing information for the completion timeline */
10
+ export interface TimedEffect {
11
+ effect: Effect;
12
+ /** Time in ms when this effect completed, relative to execution start */
13
+ timestamp: number;
14
+ }
15
+ export interface ExecutionProgressProps {
16
+ /** The task to execute */
17
+ task: Task<void>;
18
+ /** Whether to run in dry-run mode */
19
+ dryRun?: boolean;
20
+ /** Called when execution completes */
21
+ onComplete: (effects: TimedEffect[], duration: number) => void;
22
+ /** Called when execution fails */
23
+ onError: (error: TaskError) => void;
24
+ /** Stamp configuration for generated files (undefined = no stamps) */
25
+ stamp?: StampConfig;
26
+ }
27
+ export declare const ExecutionProgress: React.FC<ExecutionProgressProps>;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * FileTreePreview Component
3
+ *
4
+ * Displays a list of files that will be created/modified.
5
+ */
6
+ import type { Effect } from "@canonical/task";
7
+ export interface FileTreePreviewProps {
8
+ /** Effects to display */
9
+ effects: Effect[];
10
+ /** Title for the preview */
11
+ title?: string;
12
+ }
13
+ export declare const FileTreePreview: ({ effects, title, }: FileTreePreviewProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * PromptSequence Component
3
+ *
4
+ * Handles interactive prompts for generators using React Ink.
5
+ * Features:
6
+ * - Progress indicator (step X of Y)
7
+ * - Navigate back to previous answers
8
+ * - Show completed answers
9
+ * - Group headers
10
+ */
11
+ import type { PromptDefinition } from "@canonical/summon-core";
12
+ export interface PromptSequenceProps {
13
+ /** List of prompts to display */
14
+ prompts: PromptDefinition[];
15
+ /** Called when all prompts are answered */
16
+ onComplete: (answers: Record<string, unknown>) => void;
17
+ /** Called when user cancels */
18
+ onCancel?: () => void;
19
+ /** Initial answers (for resuming/editing) */
20
+ initialAnswers?: Record<string, unknown>;
21
+ }
22
+ export declare const PromptSequence: ({ prompts, onComplete, onCancel, initialAnswers, }: PromptSequenceProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Spinner Component
3
+ *
4
+ * A simple loading spinner for the CLI.
5
+ */
6
+ export interface SpinnerProps {
7
+ /** Color of the spinner */
8
+ color?: string;
9
+ /** Label to show next to the spinner */
10
+ label?: string;
11
+ }
12
+ export declare const Spinner: ({ color, label }: SpinnerProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * React Ink Components
3
+ *
4
+ * This module exports all React Ink components for the CLI.
5
+ */
6
+ export type { AppProps, AppState } from "./App.js";
7
+ export { App } from "./App.js";
8
+ export type { ExecutionProgressProps } from "./ExecutionProgress.js";
9
+ export { ExecutionProgress } from "./ExecutionProgress.js";
10
+ export type { FileTreePreviewProps } from "./FileTreePreview.js";
11
+ export { FileTreePreview } from "./FileTreePreview.js";
12
+ export type { PromptSequenceProps } from "./PromptSequence.js";
13
+ export { PromptSequence } from "./PromptSequence.js";
14
+ export type { SpinnerProps } from "./Spinner.js";
15
+ export { Spinner } from "./Spinner.js";
@@ -0,0 +1 @@
1
+ export { default as loadGenerator } from "./loadGenerator.js";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Load a generator definition from a file path or the in-memory cache.
3
+ *
4
+ * Cached entries are inserted by {@link discoverGeneratorTree} when it
5
+ * processes barrel exports from summon-* packages.
6
+ */
7
+ import type { GeneratorDefinition } from "@canonical/summon-core";
8
+ /**
9
+ * Load a generator from a path or the cache.
10
+ *
11
+ * @note Impure — performs dynamic import when the generator is not cached.
12
+ */
13
+ export default function loadGenerator(generatorPath: string): Promise<GeneratorDefinition>;
@@ -0,0 +1,2 @@
1
+ export { default as printGeneratorHelp } from "./printGeneratorHelp.js";
2
+ export { default as printNode } from "./printNode.js";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Print detailed help for a generator (meta.help and examples).
3
+ *
4
+ * When `llmMode` is true, outputs structured markdown help via formatLlmHelp.
5
+ *
6
+ * @note Impure — writes to stdout, loads generators via dynamic import.
7
+ */
8
+ import type { GeneratorNode } from "@canonical/summon-core";
9
+ export default function printGeneratorHelp(node: GeneratorNode, pathSegments: string[], llmMode?: boolean): Promise<void>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Print available generators/sub-generators at a tree node.
3
+ *
4
+ * @note Impure — writes to stdout.
5
+ */
6
+ import type { GeneratorNode } from "@canonical/summon-core";
7
+ export default function printNode(node: GeneratorNode, pathSegments: string[]): void;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Build a flat command list from a generator tree.
3
+ *
4
+ * Flattens the tree into a list of {@link CommandEntry} sorted by depth
5
+ * so that parents are registered before children.
6
+ *
7
+ * @note Impure — loads generators via dynamic import.
8
+ */
9
+ import type { GeneratorNode } from "@canonical/summon-core";
10
+ import type { CommandEntry } from "./types.js";
11
+ export default function buildCommandBarrel(node: GeneratorNode, pathSegments?: string[]): Promise<CommandEntry[]>;
@@ -0,0 +1,3 @@
1
+ export { default as buildCommandBarrel } from "./buildCommandBarrel.js";
2
+ export { default as registerFromBarrel } from "./registerFromBarrel.js";
3
+ export type { CommandEntry, OptionInfo } from "./types.js";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Register commands from a command barrel onto a Commander program.
3
+ *
4
+ * Handles option wiring, grouped help, answer extraction, mode expansion
5
+ * (--llm, --format json), and the action handler for each generator command.
6
+ *
7
+ * @note Impure — writes to stdout/stderr, renders Ink components.
8
+ */
9
+ import type { Command } from "commander";
10
+ import type { CommandEntry } from "./types.js";
11
+ /**
12
+ * Register all commands from a command barrel onto a Commander program.
13
+ *
14
+ * @note Impure — mutates the Commander program.
15
+ */
16
+ export default function registerFromBarrel(rootCmd: Command, barrel: CommandEntry[]): void;
@@ -0,0 +1,26 @@
1
+ import type { GeneratorDefinition } from "@canonical/summon-core";
2
+ /**
3
+ * A flattened representation of a command to register.
4
+ * Separates command discovery from registration.
5
+ */
6
+ export interface CommandEntry {
7
+ /** Path segments to this command (e.g., ["component", "react"]) */
8
+ path: string[];
9
+ /** The generator definition if this is a runnable command */
10
+ generator?: GeneratorDefinition;
11
+ /** Description for namespace-only commands */
12
+ description?: string;
13
+ }
14
+ /**
15
+ * Option metadata built from a prompt definition for Commander.
16
+ */
17
+ export interface OptionInfo {
18
+ flags: string;
19
+ description: string;
20
+ defaultValue?: string;
21
+ group?: string;
22
+ /** The original camelCase prompt name */
23
+ promptName: string;
24
+ /** The kebab-case flag name (without --) */
25
+ kebabName: string;
26
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Public UI entry point for summon's interactive Ink experience.
3
+ *
4
+ * Exposes the same `App` the summon binary renders, plus a {@link renderApp}
5
+ * helper that mounts it and resolves when the user finishes, so other CLIs
6
+ * (e.g. pragma's `create`/`setup`) can reuse the exact prompt/preview/execute
7
+ * flow instead of duplicating it.
8
+ *
9
+ * @module
10
+ */
11
+ import { type AppProps } from "../components/App.js";
12
+ export type { AppProps, AppState } from "../components/App.js";
13
+ export { App } from "../components/App.js";
14
+ /**
15
+ * Render the interactive generator UI and resolve when it exits.
16
+ *
17
+ * Mounts summon's Ink `App` (prompt sequence → preview/confirm → execution)
18
+ * and awaits `waitUntilExit`, matching how the summon binary drives a run.
19
+ *
20
+ * @param props - The App props (generator, preview, answers, stamp, …).
21
+ * @returns A promise that resolves once the UI has fully exited.
22
+ * @note Impure — takes over the terminal via Ink and performs the run's effects.
23
+ */
24
+ export declare function renderApp(props: AppProps): Promise<void>;
@@ -0,0 +1,29 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Public UI entry point for summon's interactive Ink experience.
4
+ *
5
+ * Exposes the same `App` the summon binary renders, plus a {@link renderApp}
6
+ * helper that mounts it and resolves when the user finishes, so other CLIs
7
+ * (e.g. pragma's `create`/`setup`) can reuse the exact prompt/preview/execute
8
+ * flow instead of duplicating it.
9
+ *
10
+ * @module
11
+ */
12
+ import { render } from "ink";
13
+ import { App } from "../components/App.js";
14
+ export { App } from "../components/App.js";
15
+ /**
16
+ * Render the interactive generator UI and resolve when it exits.
17
+ *
18
+ * Mounts summon's Ink `App` (prompt sequence → preview/confirm → execution)
19
+ * and awaits `waitUntilExit`, matching how the summon binary drives a run.
20
+ *
21
+ * @param props - The App props (generator, preview, answers, stamp, …).
22
+ * @returns A promise that resolves once the UI has fully exited.
23
+ * @note Impure — takes over the terminal via Ink and performs the run's effects.
24
+ */
25
+ export async function renderApp(props) {
26
+ const { waitUntilExit } = render(_jsx(App, { ...props }));
27
+ await waitUntilExit();
28
+ }
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ui/index.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,GAAG,EAAiB,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAE3C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAAe;IAC7C,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC,KAAC,GAAG,OAAK,KAAK,GAAI,CAAC,CAAC;IACrD,MAAM,aAAa,EAAE,CAAC;AACxB,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,22 @@
1
1
  {
2
2
  "name": "@canonical/summon",
3
3
  "description": "Summon CLI binary: interactive code generator with Ink UI, shell completion, and Commander registration.",
4
- "version": "0.30.0",
4
+ "version": "0.31.0",
5
5
  "type": "module",
6
6
  "module": "dist/src/bin.js",
7
7
  "bin": {
8
8
  "summon": "dist/src/bin.js"
9
9
  },
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/src/bin.d.ts",
13
+ "import": "./dist/src/bin.js"
14
+ },
15
+ "./ui": {
16
+ "types": "./dist/src/ui/index.d.ts",
17
+ "import": "./dist/src/ui/index.js"
18
+ }
19
+ },
10
20
  "files": [
11
21
  "dist"
12
22
  ],
@@ -38,10 +48,10 @@
38
48
  "test:watch": "vitest"
39
49
  },
40
50
  "dependencies": {
41
- "@canonical/cli-core": "^0.30.0",
42
- "@canonical/summon-core": "^0.30.0",
43
- "@canonical/task": "^0.30.0",
44
- "@canonical/utils": "^0.30.0",
51
+ "@canonical/cli-core": "^0.31.0",
52
+ "@canonical/summon-core": "^0.31.0",
53
+ "@canonical/task": "^0.31.0",
54
+ "@canonical/utils": "^0.31.0",
45
55
  "chalk": "^5.6.2",
46
56
  "commander": "^14.0.3",
47
57
  "ink": "^6.8.0",
@@ -53,8 +63,8 @@
53
63
  },
54
64
  "devDependencies": {
55
65
  "@biomejs/biome": "2.4.9",
56
- "@canonical/biome-config": "^0.30.0",
57
- "@canonical/typescript-config": "^0.30.0",
66
+ "@canonical/biome-config": "^0.31.0",
67
+ "@canonical/typescript-config": "^0.31.0",
58
68
  "@types/bun": "^1.3.10",
59
69
  "@types/node": "^24.12.0",
60
70
  "@types/omelette": "^0.4.5",
@@ -63,5 +73,5 @@
63
73
  "typescript": "^5.9.3",
64
74
  "vitest": "^4.0.18"
65
75
  },
66
- "gitHead": "40fe86ac955473536ac14f074812a9821f5b65c0"
76
+ "gitHead": "d4a67ebe42e62b8cf3de77f42f537309ca88d672"
67
77
  }