@canonical/summon 0.29.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.
- package/dist/generators/example/hello/index.d.ts +18 -0
- package/dist/generators/example/hello/index.js +104 -0
- package/dist/generators/example/hello/index.js.map +1 -0
- package/dist/generators/example/webapp/index.d.ts +22 -0
- package/dist/generators/example/webapp/index.js +374 -0
- package/dist/generators/example/webapp/index.js.map +1 -0
- package/dist/generators/init/index.d.ts +16 -0
- package/dist/generators/init/index.js +98 -0
- package/dist/generators/init/index.js.map +1 -0
- package/dist/src/bin.d.ts +10 -0
- package/dist/src/bin.js +153 -0
- package/dist/src/bin.js.map +1 -0
- package/dist/src/completion.d.ts +63 -0
- package/dist/src/completion.js +375 -0
- package/dist/src/completion.js.map +1 -0
- package/dist/src/components/App.d.ts +48 -0
- package/dist/src/components/App.js +621 -0
- package/dist/src/components/App.js.map +1 -0
- package/dist/src/components/ExecutionProgress.d.ts +27 -0
- package/dist/src/components/ExecutionProgress.js +132 -0
- package/dist/src/components/ExecutionProgress.js.map +1 -0
- package/dist/src/components/FileTreePreview.d.ts +13 -0
- package/dist/src/components/FileTreePreview.js +55 -0
- package/dist/src/components/FileTreePreview.js.map +1 -0
- package/dist/src/components/PromptSequence.d.ts +22 -0
- package/dist/src/components/PromptSequence.js +215 -0
- package/dist/src/components/PromptSequence.js.map +1 -0
- package/dist/src/components/Spinner.d.ts +12 -0
- package/dist/src/components/Spinner.js +20 -0
- package/dist/src/components/Spinner.js.map +1 -0
- package/{src/components/index.ts → dist/src/components/index.d.ts} +0 -1
- package/dist/src/components/index.js +11 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/discovery/index.js +2 -0
- package/dist/src/discovery/index.js.map +1 -0
- package/dist/src/discovery/loadGenerator.d.ts +13 -0
- package/dist/src/discovery/loadGenerator.js +29 -0
- package/dist/src/discovery/loadGenerator.js.map +1 -0
- package/dist/src/display/index.js +3 -0
- package/dist/src/display/index.js.map +1 -0
- package/dist/src/display/printGeneratorHelp.d.ts +9 -0
- package/dist/src/display/printGeneratorHelp.js +99 -0
- package/dist/src/display/printGeneratorHelp.js.map +1 -0
- package/dist/src/display/printNode.d.ts +7 -0
- package/dist/src/display/printNode.js +64 -0
- package/dist/src/display/printNode.js.map +1 -0
- package/dist/src/registration/buildCommandBarrel.d.ts +11 -0
- package/dist/src/registration/buildCommandBarrel.js +45 -0
- package/dist/src/registration/buildCommandBarrel.js.map +1 -0
- package/dist/src/registration/index.js +3 -0
- package/dist/src/registration/index.js.map +1 -0
- package/dist/src/registration/registerFromBarrel.d.ts +16 -0
- package/dist/src/registration/registerFromBarrel.js +408 -0
- package/dist/src/registration/registerFromBarrel.js.map +1 -0
- package/dist/src/registration/types.d.ts +26 -0
- package/dist/src/registration/types.js +2 -0
- package/dist/src/registration/types.js.map +1 -0
- package/dist/src/ui/index.d.ts +24 -0
- package/dist/src/ui/index.js +29 -0
- package/dist/src/ui/index.js.map +1 -0
- package/package.json +23 -15
- package/generators/application/react/index.ts +0 -4
- package/generators/domain/index.ts +0 -4
- package/generators/example/hello/index.ts +0 -126
- package/generators/example/webapp/index.ts +0 -511
- package/generators/init/index.ts +0 -119
- package/generators/route/index.ts +0 -4
- package/generators/wrapper/index.ts +0 -4
- package/src/bin.tsx +0 -199
- package/src/completion.test.ts +0 -202
- package/src/completion.ts +0 -492
- package/src/components/App.tsx +0 -1053
- package/src/components/ExecutionProgress.tsx +0 -209
- package/src/components/FileTreePreview.tsx +0 -97
- package/src/components/PromptSequence.tsx +0 -483
- package/src/components/Spinner.tsx +0 -36
- package/src/discovery/loadGenerator.ts +0 -37
- package/src/display/printGeneratorHelp.ts +0 -128
- package/src/display/printNode.ts +0 -76
- package/src/registration/buildCommandBarrel.ts +0 -57
- package/src/registration/registerFromBarrel.tsx +0 -548
- package/src/registration/types.ts +0 -28
- /package/{generators → dist/generators}/example/hello/templates/README.md.ejs +0 -0
- /package/{generators → dist/generators}/example/hello/templates/index.ts.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/ARCHITECTURE.md.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/App.tsx.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/README.md.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/app.test.ts.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/app.ts.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/feature.ts.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/index.html.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/main.tsx.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/styles.css.ejs +0 -0
- /package/{generators → dist/generators}/init/templates/generator.ts.ejs +0 -0
- /package/{generators → dist/generators}/init/templates/template-index.ts.ejs +0 -0
- /package/{generators → dist/generators}/init/templates/template-test.ts.ejs +0 -0
- /package/{src/discovery/index.ts → dist/src/discovery/index.d.ts} +0 -0
- /package/{src/display/index.ts → dist/src/display/index.d.ts} +0 -0
- /package/{src/registration/index.ts → dist/src/registration/index.d.ts} +0 -0
package/generators/init/index.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Init Generator
|
|
3
|
-
*
|
|
4
|
-
* Scaffolds a new Summon generator with templates and test structure.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as path from "node:path";
|
|
8
|
-
import { fileURLToPath } from "node:url";
|
|
9
|
-
import type { GeneratorDefinition } from "@canonical/summon-core";
|
|
10
|
-
import { template, withHelpers } from "@canonical/summon-core";
|
|
11
|
-
import { info, mkdir, sequence_ } from "@canonical/task";
|
|
12
|
-
|
|
13
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
-
|
|
15
|
-
interface Answers {
|
|
16
|
-
/** Generator path (e.g., "my-gen" or "component/vue") */
|
|
17
|
-
generatorPath: string;
|
|
18
|
-
/** Description of the generator */
|
|
19
|
-
description: string;
|
|
20
|
-
/** Output directory for generators */
|
|
21
|
-
outputDir: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const generator: GeneratorDefinition<Answers> = {
|
|
25
|
-
meta: {
|
|
26
|
-
name: "init",
|
|
27
|
-
description: "Create a new Summon generator",
|
|
28
|
-
version: "0.1.0",
|
|
29
|
-
help: `Scaffold a new generator with templates and tests.
|
|
30
|
-
|
|
31
|
-
The generator path supports nested structures:
|
|
32
|
-
summon init --generator-path=my-gen # Creates generators/my-gen/
|
|
33
|
-
summon init --generator-path=component/vue # Creates generators/component/vue/
|
|
34
|
-
|
|
35
|
-
GENERATED FILES:
|
|
36
|
-
generators/<path>/
|
|
37
|
-
├── index.ts # Generator definition
|
|
38
|
-
└── templates/
|
|
39
|
-
├── index.ts.ejs # Main file template
|
|
40
|
-
└── index.test.ts.ejs # Test file template`,
|
|
41
|
-
examples: [
|
|
42
|
-
"summon init",
|
|
43
|
-
"summon init --generator-path=my-gen",
|
|
44
|
-
"summon init --generator-path=component/vue",
|
|
45
|
-
"summon init --generator-path=api/rest --output-dir=./custom-generators",
|
|
46
|
-
"summon init --generator-path=util --dry-run",
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
prompts: [
|
|
51
|
-
{
|
|
52
|
-
name: "generatorPath",
|
|
53
|
-
type: "text",
|
|
54
|
-
message: "Generator path (e.g., my-gen or component/vue):",
|
|
55
|
-
default: "my-generator",
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
name: "description",
|
|
59
|
-
type: "text",
|
|
60
|
-
message: "Description:",
|
|
61
|
-
default: "A custom generator",
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
name: "outputDir",
|
|
65
|
-
type: "text",
|
|
66
|
-
message: "Output directory:",
|
|
67
|
-
default: "./generators",
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
|
|
71
|
-
generate: (answers) => {
|
|
72
|
-
// Parse the generator path into segments
|
|
73
|
-
const normalizedPath = answers.generatorPath.replace(/\s+/g, "/");
|
|
74
|
-
const segments = normalizedPath.split("/").filter(Boolean);
|
|
75
|
-
const name = segments[segments.length - 1];
|
|
76
|
-
const generatorDir = path.join(answers.outputDir, ...segments);
|
|
77
|
-
const templatesDir = path.join(generatorDir, "templates");
|
|
78
|
-
|
|
79
|
-
const vars = withHelpers({
|
|
80
|
-
name,
|
|
81
|
-
description: answers.description,
|
|
82
|
-
generatorPath: normalizedPath,
|
|
83
|
-
commandPath: segments.join(" "),
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
return sequence_([
|
|
87
|
-
info(`Creating generator: ${name}`),
|
|
88
|
-
|
|
89
|
-
// Create directories
|
|
90
|
-
mkdir(generatorDir),
|
|
91
|
-
mkdir(templatesDir),
|
|
92
|
-
|
|
93
|
-
// Create generator index.ts
|
|
94
|
-
template({
|
|
95
|
-
source: path.join(__dirname, "templates", "generator.ts.ejs"),
|
|
96
|
-
dest: path.join(generatorDir, "index.ts"),
|
|
97
|
-
vars,
|
|
98
|
-
}),
|
|
99
|
-
|
|
100
|
-
// Create template files
|
|
101
|
-
template({
|
|
102
|
-
source: path.join(__dirname, "templates", "template-index.ts.ejs"),
|
|
103
|
-
dest: path.join(templatesDir, "index.ts.ejs"),
|
|
104
|
-
vars,
|
|
105
|
-
}),
|
|
106
|
-
|
|
107
|
-
template({
|
|
108
|
-
source: path.join(__dirname, "templates", "template-test.ts.ejs"),
|
|
109
|
-
dest: path.join(templatesDir, "index.test.ts.ejs"),
|
|
110
|
-
vars,
|
|
111
|
-
}),
|
|
112
|
-
|
|
113
|
-
info(`Created generator at ${generatorDir}`),
|
|
114
|
-
info(`Run with: summon ${segments.join(" ")}`),
|
|
115
|
-
]);
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export default generator;
|
package/src/bin.tsx
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Summon CLI — thin orchestrator.
|
|
5
|
-
*
|
|
6
|
-
* Wires together generator discovery, display, registration, and completion.
|
|
7
|
-
* All domain logic lives in the corresponding modules.
|
|
8
|
-
*
|
|
9
|
-
* @note Impure — CLI entry point.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import * as path from "node:path";
|
|
13
|
-
import {
|
|
14
|
-
discoverGeneratorTree,
|
|
15
|
-
type GeneratorNode,
|
|
16
|
-
} from "@canonical/summon-core";
|
|
17
|
-
import chalk from "chalk";
|
|
18
|
-
import { Command } from "commander";
|
|
19
|
-
import {
|
|
20
|
-
type CompletionNode,
|
|
21
|
-
handleSetupRequest,
|
|
22
|
-
initCompletion,
|
|
23
|
-
isCompletionRequest,
|
|
24
|
-
isSetupRequest,
|
|
25
|
-
} from "./completion.js";
|
|
26
|
-
import { loadGenerator } from "./discovery/index.js";
|
|
27
|
-
import { printGeneratorHelp, printNode } from "./display/index.js";
|
|
28
|
-
import {
|
|
29
|
-
buildCommandBarrel,
|
|
30
|
-
registerFromBarrel,
|
|
31
|
-
} from "./registration/index.js";
|
|
32
|
-
|
|
33
|
-
// =============================================================================
|
|
34
|
-
// Helpers
|
|
35
|
-
// =============================================================================
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Navigate the generator tree by path segments.
|
|
39
|
-
* Returns [node, remainingSegments] where node is as deep as we could go.
|
|
40
|
-
*/
|
|
41
|
-
const navigateTree = (
|
|
42
|
-
root: GeneratorNode,
|
|
43
|
-
segments: string[],
|
|
44
|
-
): [GeneratorNode, string[]] => {
|
|
45
|
-
let current = root;
|
|
46
|
-
let i = 0;
|
|
47
|
-
|
|
48
|
-
for (; i < segments.length; i++) {
|
|
49
|
-
const child = current.children.get(segments[i]);
|
|
50
|
-
if (!child) break;
|
|
51
|
-
current = child;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return [current, segments.slice(i)];
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Convert GeneratorNode to CompletionNode for the completion module.
|
|
59
|
-
*/
|
|
60
|
-
const toCompletionNode = (node: GeneratorNode): CompletionNode => ({
|
|
61
|
-
name: node.name,
|
|
62
|
-
indexPath: node.indexPath,
|
|
63
|
-
children: new Map(
|
|
64
|
-
[...node.children.entries()].map(([name, child]) => [
|
|
65
|
-
name,
|
|
66
|
-
toCompletionNode(child),
|
|
67
|
-
]),
|
|
68
|
-
),
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Register all generator commands from the tree.
|
|
73
|
-
* Uses the barrel pattern: build flat list → sort by depth → register in order.
|
|
74
|
-
*/
|
|
75
|
-
const registerGeneratorCommands = async (
|
|
76
|
-
parentCmd: Command,
|
|
77
|
-
node: GeneratorNode,
|
|
78
|
-
): Promise<void> => {
|
|
79
|
-
const barrel = await buildCommandBarrel(node);
|
|
80
|
-
registerFromBarrel(parentCmd, barrel);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// =============================================================================
|
|
84
|
-
// Main
|
|
85
|
-
// =============================================================================
|
|
86
|
-
|
|
87
|
-
const program = new Command();
|
|
88
|
-
|
|
89
|
-
const main = async () => {
|
|
90
|
-
// Get generators path from args early (before full parse)
|
|
91
|
-
const generatorsIdx = process.argv.indexOf("--generators");
|
|
92
|
-
const gIdx = process.argv.indexOf("-g");
|
|
93
|
-
const generatorsPath =
|
|
94
|
-
generatorsIdx !== -1
|
|
95
|
-
? process.argv[generatorsIdx + 1]
|
|
96
|
-
: gIdx !== -1
|
|
97
|
-
? process.argv[gIdx + 1]
|
|
98
|
-
: undefined;
|
|
99
|
-
|
|
100
|
-
// Discover generators (needed for both completion and normal CLI)
|
|
101
|
-
const builtinDir = path.join(__dirname, "..", "generators");
|
|
102
|
-
const root = await discoverGeneratorTree(
|
|
103
|
-
generatorsPath ? { explicitPath: generatorsPath } : { builtinDir },
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
// Initialize shell completion (must happen before commander parsing)
|
|
107
|
-
if (isCompletionRequest() || isSetupRequest()) {
|
|
108
|
-
const completionTree = toCompletionNode(root);
|
|
109
|
-
const complete = await initCompletion(completionTree, loadGenerator);
|
|
110
|
-
|
|
111
|
-
// Handle setup/cleanup requests
|
|
112
|
-
if (isSetupRequest()) {
|
|
113
|
-
handleSetupRequest(complete);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// For completion requests, omelette handles everything via init()
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
program
|
|
122
|
-
.name("summon")
|
|
123
|
-
.description("A monadic task-centric code generator framework")
|
|
124
|
-
.version("0.1.0")
|
|
125
|
-
.option(
|
|
126
|
-
"-g, --generators <path>",
|
|
127
|
-
"Load generators ONLY from this path (for testing)",
|
|
128
|
-
)
|
|
129
|
-
.option("--setup-completion", "Install shell autocompletion")
|
|
130
|
-
.option("--cleanup-completion", "Remove shell autocompletion");
|
|
131
|
-
|
|
132
|
-
// If no arguments, show available topics
|
|
133
|
-
if (process.argv.length === 2) {
|
|
134
|
-
printNode(root, []);
|
|
135
|
-
console.log(
|
|
136
|
-
chalk.dim(
|
|
137
|
-
"Tip: Run 'summon --setup-completion' to enable TAB completion\n",
|
|
138
|
-
),
|
|
139
|
-
);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Intercept --help --llm (or --help -l) for structured markdown help
|
|
144
|
-
const hasHelp =
|
|
145
|
-
process.argv.includes("--help") || process.argv.includes("-h");
|
|
146
|
-
const hasLlm =
|
|
147
|
-
process.argv.includes("--llm") ||
|
|
148
|
-
process.argv.includes("-l") ||
|
|
149
|
-
process.env.SUMMON_LLM === "1";
|
|
150
|
-
if (hasHelp && hasLlm) {
|
|
151
|
-
// Extract command path segments (skip flags and flag arguments)
|
|
152
|
-
const skipFlags = new Set([
|
|
153
|
-
"--help",
|
|
154
|
-
"-h",
|
|
155
|
-
"--llm",
|
|
156
|
-
"-l",
|
|
157
|
-
"--generators",
|
|
158
|
-
"-g",
|
|
159
|
-
"--format",
|
|
160
|
-
]);
|
|
161
|
-
const args = process.argv.slice(2);
|
|
162
|
-
const segments: string[] = [];
|
|
163
|
-
let skipNext = false;
|
|
164
|
-
for (const arg of args) {
|
|
165
|
-
if (skipNext) {
|
|
166
|
-
skipNext = false;
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
if (skipFlags.has(arg)) {
|
|
170
|
-
if (arg === "--generators" || arg === "-g" || arg === "--format")
|
|
171
|
-
skipNext = true;
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
if (arg.startsWith("-")) continue;
|
|
175
|
-
segments.push(arg);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (segments.length > 0) {
|
|
179
|
-
const [node] = navigateTree(root, segments);
|
|
180
|
-
if (node.indexPath) {
|
|
181
|
-
await printGeneratorHelp(node, segments, true);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
// Fall through to normal help if we can't find the generator
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// Register generator commands dynamically
|
|
189
|
-
await registerGeneratorCommands(program, root);
|
|
190
|
-
|
|
191
|
-
// Parse and execute
|
|
192
|
-
program.parse();
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
// Run main
|
|
196
|
-
main().catch((err) => {
|
|
197
|
-
console.error(chalk.red("Error:"), err.message);
|
|
198
|
-
process.exit(1);
|
|
199
|
-
});
|
package/src/completion.test.ts
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
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
|
-
});
|