@canonical/summon 0.20.0 → 0.22.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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.
|
|
4
|
+
"version": "0.22.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "src/bin.tsx",
|
|
7
7
|
"bin": {
|
|
@@ -36,9 +36,10 @@
|
|
|
36
36
|
"test:watch": "vitest"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@canonical/cli-core": "^0.
|
|
40
|
-
"@canonical/summon-core": "^0.
|
|
41
|
-
"@canonical/task": "^0.
|
|
39
|
+
"@canonical/cli-core": "^0.22.0",
|
|
40
|
+
"@canonical/summon-core": "^0.22.0",
|
|
41
|
+
"@canonical/task": "^0.22.0",
|
|
42
|
+
"@canonical/utils": "^0.22.0",
|
|
42
43
|
"chalk": "^5.6.2",
|
|
43
44
|
"commander": "^14.0.3",
|
|
44
45
|
"ink": "^6.8.0",
|
|
@@ -49,9 +50,9 @@
|
|
|
49
50
|
"react": "^19.2.4"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"@biomejs/biome": "2.4.
|
|
53
|
-
"@canonical/biome-config": "^0.
|
|
54
|
-
"@canonical/typescript-config": "^0.
|
|
53
|
+
"@biomejs/biome": "2.4.9",
|
|
54
|
+
"@canonical/biome-config": "^0.22.0",
|
|
55
|
+
"@canonical/typescript-config": "^0.22.0",
|
|
55
56
|
"@types/bun": "^1.3.10",
|
|
56
57
|
"@types/node": "^24.12.0",
|
|
57
58
|
"@types/omelette": "^0.4.5",
|
|
@@ -60,5 +61,5 @@
|
|
|
60
61
|
"typescript": "^5.9.3",
|
|
61
62
|
"vitest": "^4.0.18"
|
|
62
63
|
},
|
|
63
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "99e187cf46d8bd7f3933705322fa4ab2d4a711e7"
|
|
64
65
|
}
|
package/src/bin.tsx
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
isCompletionRequest,
|
|
24
24
|
isSetupRequest,
|
|
25
25
|
} from "./completion.js";
|
|
26
|
-
import loadGenerator from "./discovery/
|
|
26
|
+
import { loadGenerator } from "./discovery/index.js";
|
|
27
27
|
import { printGeneratorHelp, printNode } from "./display/index.js";
|
|
28
28
|
import {
|
|
29
29
|
buildCommandBarrel,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for shell autocompletion utilities
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { PromptDefinition } from "@canonical/summon-core";
|
|
6
|
+
import { describe, expect, it } from "vitest";
|
|
7
|
+
import { getArgumentCompletions, isPathPrompt } from "./completion.js";
|
|
8
|
+
|
|
9
|
+
// =============================================================================
|
|
10
|
+
// isPathPrompt
|
|
11
|
+
// =============================================================================
|
|
12
|
+
|
|
13
|
+
describe("isPathPrompt", () => {
|
|
14
|
+
it("detects path in prompt name", () => {
|
|
15
|
+
expect(
|
|
16
|
+
isPathPrompt({ name: "componentPath", type: "text", message: "Enter:" }),
|
|
17
|
+
).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("detects dir in prompt name", () => {
|
|
21
|
+
expect(
|
|
22
|
+
isPathPrompt({ name: "outputDir", type: "text", message: "Enter:" }),
|
|
23
|
+
).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("detects directory in prompt name", () => {
|
|
27
|
+
expect(
|
|
28
|
+
isPathPrompt({
|
|
29
|
+
name: "outputDirectory",
|
|
30
|
+
type: "text",
|
|
31
|
+
message: "Enter:",
|
|
32
|
+
}),
|
|
33
|
+
).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("detects file in prompt name", () => {
|
|
37
|
+
expect(
|
|
38
|
+
isPathPrompt({ name: "configFile", type: "text", message: "Enter:" }),
|
|
39
|
+
).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("detects folder in prompt message", () => {
|
|
43
|
+
expect(
|
|
44
|
+
isPathPrompt({
|
|
45
|
+
name: "output",
|
|
46
|
+
type: "text",
|
|
47
|
+
message: "Choose output folder:",
|
|
48
|
+
}),
|
|
49
|
+
).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("detects location in prompt message", () => {
|
|
53
|
+
expect(
|
|
54
|
+
isPathPrompt({
|
|
55
|
+
name: "output",
|
|
56
|
+
type: "text",
|
|
57
|
+
message: "File location:",
|
|
58
|
+
}),
|
|
59
|
+
).toBe(true);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("returns false for non-path prompts", () => {
|
|
63
|
+
expect(
|
|
64
|
+
isPathPrompt({ name: "name", type: "text", message: "Package name:" }),
|
|
65
|
+
).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("returns false for confirm prompts", () => {
|
|
69
|
+
expect(
|
|
70
|
+
isPathPrompt({
|
|
71
|
+
name: "withStyles",
|
|
72
|
+
type: "confirm",
|
|
73
|
+
message: "Include styles?",
|
|
74
|
+
}),
|
|
75
|
+
).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("is case-insensitive", () => {
|
|
79
|
+
expect(
|
|
80
|
+
isPathPrompt({ name: "MyPath", type: "text", message: "Enter:" }),
|
|
81
|
+
).toBe(true);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// =============================================================================
|
|
86
|
+
// getArgumentCompletions
|
|
87
|
+
// =============================================================================
|
|
88
|
+
|
|
89
|
+
describe("getArgumentCompletions", () => {
|
|
90
|
+
const prompts: PromptDefinition[] = [
|
|
91
|
+
{ name: "componentPath", type: "text", message: "Component path:" },
|
|
92
|
+
{
|
|
93
|
+
name: "withStyles",
|
|
94
|
+
type: "confirm",
|
|
95
|
+
message: "Include styles?",
|
|
96
|
+
default: true,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: "withStories",
|
|
100
|
+
type: "confirm",
|
|
101
|
+
message: "Include stories?",
|
|
102
|
+
default: true,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "type",
|
|
106
|
+
type: "select",
|
|
107
|
+
message: "Package type:",
|
|
108
|
+
choices: [
|
|
109
|
+
{ value: "library", label: "Library" },
|
|
110
|
+
{ value: "tool-ts", label: "Tool" },
|
|
111
|
+
{ value: "css", label: "CSS" },
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
it("returns flag completions when completing a flag name", () => {
|
|
117
|
+
const completions = getArgumentCompletions(
|
|
118
|
+
prompts,
|
|
119
|
+
"summon test --comp",
|
|
120
|
+
"--comp",
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
expect(completions).toContain("--component-path");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("shows --no-X for confirm prompts with default true", () => {
|
|
127
|
+
const completions = getArgumentCompletions(
|
|
128
|
+
prompts,
|
|
129
|
+
"summon test --no-",
|
|
130
|
+
"--no-",
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
expect(completions).toContain("--no-with-styles");
|
|
134
|
+
expect(completions).toContain("--no-with-stories");
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("returns select choices when completing a flag value", () => {
|
|
138
|
+
const completions = getArgumentCompletions(
|
|
139
|
+
prompts,
|
|
140
|
+
"summon test --type=",
|
|
141
|
+
"",
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
expect(completions).toContain("library");
|
|
145
|
+
expect(completions).toContain("tool-ts");
|
|
146
|
+
expect(completions).toContain("css");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("filters select choices by partial value", () => {
|
|
150
|
+
const completions = getArgumentCompletions(
|
|
151
|
+
prompts,
|
|
152
|
+
"summon test --type=lib",
|
|
153
|
+
"",
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
expect(completions).toContain("library");
|
|
157
|
+
expect(completions).not.toContain("tool-ts");
|
|
158
|
+
expect(completions).not.toContain("css");
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("includes built-in flags", () => {
|
|
162
|
+
const completions = getArgumentCompletions(
|
|
163
|
+
prompts,
|
|
164
|
+
"summon test --dry",
|
|
165
|
+
"--dry",
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
expect(completions).toContain("--dry-run");
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("shows all flags when showAll is true", () => {
|
|
172
|
+
const completions = getArgumentCompletions(
|
|
173
|
+
prompts,
|
|
174
|
+
"summon test",
|
|
175
|
+
"",
|
|
176
|
+
true,
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
expect(completions).toContain("--component-path");
|
|
180
|
+
expect(completions).toContain("--dry-run");
|
|
181
|
+
expect(completions).toContain("--help");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("returns empty array when no matches", () => {
|
|
185
|
+
const completions = getArgumentCompletions(
|
|
186
|
+
prompts,
|
|
187
|
+
"summon test --zzz",
|
|
188
|
+
"--zzz",
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
expect(completions).toHaveLength(0);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("includes --yes and --verbose in built-in flags", () => {
|
|
195
|
+
const completions = getArgumentCompletions([], "summon test --", "--");
|
|
196
|
+
|
|
197
|
+
expect(completions).toContain("--yes");
|
|
198
|
+
expect(completions).toContain("--verbose");
|
|
199
|
+
expect(completions).toContain("--llm");
|
|
200
|
+
expect(completions).toContain("--help");
|
|
201
|
+
});
|
|
202
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as loadGenerator } from "./loadGenerator.js";
|
|
@@ -8,16 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
import { formatGeneratorLlmHelp } from "@canonical/cli-core";
|
|
10
10
|
import type { GeneratorNode } from "@canonical/summon-core";
|
|
11
|
+
import { toKebabCase } from "@canonical/utils";
|
|
11
12
|
import chalk from "chalk";
|
|
12
|
-
import loadGenerator from "../discovery/
|
|
13
|
+
import { loadGenerator } from "../discovery/index.js";
|
|
13
14
|
import printNode from "./printNode.js";
|
|
14
15
|
|
|
15
|
-
/**
|
|
16
|
-
* Convert camelCase to kebab-case.
|
|
17
|
-
*/
|
|
18
|
-
const toKebabCase = (str: string): string =>
|
|
19
|
-
str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
20
|
-
|
|
21
16
|
export default async function printGeneratorHelp(
|
|
22
17
|
node: GeneratorNode,
|
|
23
18
|
pathSegments: string[],
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import type { GeneratorNode } from "@canonical/summon-core";
|
|
11
11
|
import chalk from "chalk";
|
|
12
|
-
import loadGenerator from "../discovery/
|
|
12
|
+
import { loadGenerator } from "../discovery/index.js";
|
|
13
13
|
import type { CommandEntry } from "./types.js";
|
|
14
14
|
|
|
15
15
|
export default async function buildCommandBarrel(
|