@canonical/summon-core 0.31.0 → 0.33.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/esm/execute/GeneratorResult.js +13 -0
- package/dist/esm/execute/GeneratorResult.js.map +1 -0
- package/dist/esm/execute/collectAnswers.js +92 -0
- package/dist/esm/execute/collectAnswers.js.map +1 -0
- package/dist/esm/execute/execute.js +73 -0
- package/dist/esm/execute/execute.js.map +1 -0
- package/dist/esm/execute/index.js +4 -0
- package/dist/esm/execute/index.js.map +1 -0
- package/dist/esm/execute/validateAnswers.js +47 -0
- package/dist/esm/execute/validateAnswers.js.map +1 -0
- package/dist/esm/format/effects.js +581 -0
- package/dist/esm/format/effects.js.map +1 -0
- package/dist/esm/format/index.js +2 -0
- package/dist/esm/format/index.js.map +1 -0
- package/dist/esm/index.js +8 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/prompt/answerPromptWithDefaults.js +26 -0
- package/dist/esm/prompt/answerPromptWithDefaults.js.map +1 -0
- package/dist/esm/prompt/autoPrompt.js +50 -0
- package/dist/esm/prompt/autoPrompt.js.map +1 -0
- package/dist/esm/prompt/index.js +12 -0
- package/dist/esm/prompt/index.js.map +1 -0
- package/dist/esm/prompt/ink/Spinner.js +18 -0
- package/dist/esm/prompt/ink/Spinner.js.map +1 -0
- package/dist/esm/prompt/ink/Wizard.js +116 -0
- package/dist/esm/prompt/ink/Wizard.js.map +1 -0
- package/dist/esm/prompt/ink/answerValidation.js +32 -0
- package/dist/esm/prompt/ink/answerValidation.js.map +1 -0
- package/dist/esm/prompt/ink/mount.js +41 -0
- package/dist/esm/prompt/ink/mount.js.map +1 -0
- package/dist/esm/prompt/ink/progressWindow.js +143 -0
- package/dist/esm/prompt/ink/progressWindow.js.map +1 -0
- package/dist/esm/prompt/ink/prompts.js +219 -0
- package/dist/esm/prompt/ink/prompts.js.map +1 -0
- package/dist/esm/prompt/ink/selectChoices.js +28 -0
- package/dist/esm/prompt/ink/selectChoices.js.map +1 -0
- package/dist/esm/prompt/ink/session.js +176 -0
- package/dist/esm/prompt/ink/session.js.map +1 -0
- package/dist/esm/prompt/inkPrompt.js +55 -0
- package/dist/esm/prompt/inkPrompt.js.map +1 -0
- package/dist/esm/prompt/mcpPrompt.js +29 -0
- package/dist/esm/prompt/mcpPrompt.js.map +1 -0
- package/dist/esm/prompt/types.js +12 -0
- package/dist/esm/prompt/types.js.map +1 -0
- package/dist/esm/run/index.js +2 -0
- package/dist/esm/run/index.js.map +1 -0
- package/dist/esm/run/runGeneratorTask.js +63 -0
- package/dist/esm/run/runGeneratorTask.js.map +1 -0
- package/dist/esm/stamp/createGeneratorStamp.js +19 -0
- package/dist/esm/stamp/createGeneratorStamp.js.map +1 -0
- package/dist/esm/stamp/createStampOnEffectStart.js +23 -0
- package/dist/esm/stamp/createStampOnEffectStart.js.map +1 -0
- package/dist/esm/stamp/index.js +2 -0
- package/dist/esm/stamp/index.js.map +1 -1
- package/dist/types/execute/GeneratorResult.d.ts +23 -0
- package/dist/types/execute/GeneratorResult.d.ts.map +1 -0
- package/dist/types/execute/collectAnswers.d.ts +52 -0
- package/dist/types/execute/collectAnswers.d.ts.map +1 -0
- package/dist/types/execute/execute.d.ts +57 -0
- package/dist/types/execute/execute.d.ts.map +1 -0
- package/dist/types/execute/index.d.ts +6 -0
- package/dist/types/execute/index.d.ts.map +1 -0
- package/dist/types/execute/validateAnswers.d.ts +23 -0
- package/dist/types/execute/validateAnswers.d.ts.map +1 -0
- package/dist/types/format/effects.d.ts +86 -0
- package/dist/types/format/effects.d.ts.map +1 -0
- package/dist/types/format/index.d.ts +2 -0
- package/dist/types/format/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +8 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/prompt/answerPromptWithDefaults.d.ts +17 -0
- package/dist/types/prompt/answerPromptWithDefaults.d.ts.map +1 -0
- package/dist/types/prompt/autoPrompt.d.ts +35 -0
- package/dist/types/prompt/autoPrompt.d.ts.map +1 -0
- package/dist/types/prompt/index.d.ts +14 -0
- package/dist/types/prompt/index.d.ts.map +1 -0
- package/dist/types/prompt/ink/Spinner.d.ts +11 -0
- package/dist/types/prompt/ink/Spinner.d.ts.map +1 -0
- package/dist/types/prompt/ink/Wizard.d.ts +14 -0
- package/dist/types/prompt/ink/Wizard.d.ts.map +1 -0
- package/dist/types/prompt/ink/answerValidation.d.ts +31 -0
- package/dist/types/prompt/ink/answerValidation.d.ts.map +1 -0
- package/dist/types/prompt/ink/mount.d.ts +31 -0
- package/dist/types/prompt/ink/mount.d.ts.map +1 -0
- package/dist/types/prompt/ink/progressWindow.d.ts +48 -0
- package/dist/types/prompt/ink/progressWindow.d.ts.map +1 -0
- package/dist/types/prompt/ink/prompts.d.ts +35 -0
- package/dist/types/prompt/ink/prompts.d.ts.map +1 -0
- package/dist/types/prompt/ink/selectChoices.d.ts +42 -0
- package/dist/types/prompt/ink/selectChoices.d.ts.map +1 -0
- package/dist/types/prompt/ink/session.d.ts +103 -0
- package/dist/types/prompt/ink/session.d.ts.map +1 -0
- package/dist/types/prompt/inkPrompt.d.ts +64 -0
- package/dist/types/prompt/inkPrompt.d.ts.map +1 -0
- package/dist/types/prompt/mcpPrompt.d.ts +20 -0
- package/dist/types/prompt/mcpPrompt.d.ts.map +1 -0
- package/dist/types/prompt/types.d.ts +23 -0
- package/dist/types/prompt/types.d.ts.map +1 -0
- package/dist/types/run/index.d.ts +3 -0
- package/dist/types/run/index.d.ts.map +1 -0
- package/dist/types/run/runGeneratorTask.d.ts +51 -0
- package/dist/types/run/runGeneratorTask.d.ts.map +1 -0
- package/dist/types/stamp/createGeneratorStamp.d.ts +16 -0
- package/dist/types/stamp/createGeneratorStamp.d.ts.map +1 -0
- package/dist/types/stamp/createStampOnEffectStart.d.ts +17 -0
- package/dist/types/stamp/createStampOnEffectStart.d.ts.map +1 -0
- package/dist/types/stamp/index.d.ts +2 -0
- package/dist/types/stamp/index.d.ts.map +1 -1
- package/package.json +17 -10
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The value {@link execute} produces.
|
|
3
|
+
*
|
|
4
|
+
* `execute` returns a `Task<GeneratorResult>`; the runner interprets it. The
|
|
5
|
+
* result carries what a front-end needs to render an outcome summary — the
|
|
6
|
+
* generator identity, the resolved answers, and a preview of the effects the
|
|
7
|
+
* generation performed (paths, and best-effort content for embedded-template
|
|
8
|
+
* generators). Progress does NOT ride a bespoke event channel: it rides the
|
|
9
|
+
* runner's `onEffectStart`/`onEffectComplete`/`onLog` callbacks and the task
|
|
10
|
+
* alphabet's own `TaskEvent` — summon-core invents no parallel event system.
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=GeneratorResult.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GeneratorResult.js","sourceRoot":"","sources":["../../../src/execute/GeneratorResult.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bridge from form-first generators to the dialog-first prompting model:
|
|
3
|
+
* turn a static prompt-definition list into a Task that asks each question as
|
|
4
|
+
* an interleaved `Prompt` effect through the executor's `promptHandler` seam.
|
|
5
|
+
*
|
|
6
|
+
* One builder makes every existing generator answerable by any front-end
|
|
7
|
+
* handler — Ink, MCP params, or defaults — without touching the generator:
|
|
8
|
+
* prompts already answered (CLI flags / MCP args) are skipped, `when`
|
|
9
|
+
* conditions are evaluated against the answers collected so far, and each
|
|
10
|
+
* remaining definition maps onto the task alphabet's `PromptQuestion`.
|
|
11
|
+
*
|
|
12
|
+
* Moved into summon-core (from the v1 cli-core `promptForAnswers`) as the
|
|
13
|
+
* answer-collection phase of {@link execute}.
|
|
14
|
+
*/
|
|
15
|
+
import { $, gen, prompt, } from "@canonical/task";
|
|
16
|
+
/** Map one definition onto the task alphabet's question for its type. */
|
|
17
|
+
function toQuestion(definition) {
|
|
18
|
+
const { name, message } = definition;
|
|
19
|
+
switch (definition.type) {
|
|
20
|
+
case "confirm":
|
|
21
|
+
return {
|
|
22
|
+
type: "confirm",
|
|
23
|
+
name,
|
|
24
|
+
message,
|
|
25
|
+
default: typeof definition.default === "boolean"
|
|
26
|
+
? definition.default
|
|
27
|
+
: undefined,
|
|
28
|
+
};
|
|
29
|
+
case "select":
|
|
30
|
+
return {
|
|
31
|
+
type: "select",
|
|
32
|
+
name,
|
|
33
|
+
message,
|
|
34
|
+
choices: [...(definition.choices ?? [])],
|
|
35
|
+
default: definition.default === undefined
|
|
36
|
+
? undefined
|
|
37
|
+
: String(definition.default),
|
|
38
|
+
};
|
|
39
|
+
case "multiselect":
|
|
40
|
+
return {
|
|
41
|
+
type: "multiselect",
|
|
42
|
+
name,
|
|
43
|
+
message,
|
|
44
|
+
choices: [...(definition.choices ?? [])],
|
|
45
|
+
default: Array.isArray(definition.default)
|
|
46
|
+
? definition.default.map(String)
|
|
47
|
+
: definition.default === undefined
|
|
48
|
+
? undefined
|
|
49
|
+
: [String(definition.default)],
|
|
50
|
+
};
|
|
51
|
+
default:
|
|
52
|
+
return {
|
|
53
|
+
type: "text",
|
|
54
|
+
name,
|
|
55
|
+
message,
|
|
56
|
+
default: definition.default === undefined
|
|
57
|
+
? undefined
|
|
58
|
+
: String(definition.default),
|
|
59
|
+
// A `(value: unknown) => …` validator accepts a `string`, so it
|
|
60
|
+
// satisfies the task alphabet's `(value: string) => …` slot directly.
|
|
61
|
+
validate: definition.validate,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Build a Task that collects answers for the given prompt definitions by
|
|
67
|
+
* asking each unanswered, applicable one as a `Prompt` effect.
|
|
68
|
+
*
|
|
69
|
+
* The returned task is single-use (it is `gen`-based): build a fresh one per
|
|
70
|
+
* run. Prompts whose `name` is already present in `partialAnswers` are not
|
|
71
|
+
* asked; `when` predicates observe flags and earlier answers alike.
|
|
72
|
+
*
|
|
73
|
+
* @param prompts - The prompt definitions, in asking order.
|
|
74
|
+
* @param partialAnswers - Answers already provided (e.g. CLI flags / MCP args).
|
|
75
|
+
* @returns A task yielding the complete answers record.
|
|
76
|
+
*/
|
|
77
|
+
export default function collectAnswers(prompts, partialAnswers = {}) {
|
|
78
|
+
return gen(function* () {
|
|
79
|
+
const answers = { ...partialAnswers };
|
|
80
|
+
for (const definition of prompts) {
|
|
81
|
+
if (definition.name in answers) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (definition.when && definition.when(answers) !== true) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
answers[definition.name] = yield* $(prompt(toQuestion(definition)));
|
|
88
|
+
}
|
|
89
|
+
return answers;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=collectAnswers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectAnswers.js","sourceRoot":"","sources":["../../../src/execute/collectAnswers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,CAAC,EACD,GAAG,EAEH,MAAM,GAEP,MAAM,iBAAiB,CAAC;AA0BzB,yEAAyE;AACzE,SAAS,UAAU,CAAC,UAA4B;IAC9C,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;IACrC,QAAQ,UAAU,CAAC,IAAI,EAAE,CAAC;QACxB,KAAK,SAAS;YACZ,OAAO;gBACL,IAAI,EAAE,SAAS;gBACf,IAAI;gBACJ,OAAO;gBACP,OAAO,EACL,OAAO,UAAU,CAAC,OAAO,KAAK,SAAS;oBACrC,CAAC,CAAC,UAAU,CAAC,OAAO;oBACpB,CAAC,CAAC,SAAS;aAChB,CAAC;QACJ,KAAK,QAAQ;YACX,OAAO;gBACL,IAAI,EAAE,QAAQ;gBACd,IAAI;gBACJ,OAAO;gBACP,OAAO,EAAE,CAAC,GAAG,CAAC,UAAU,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CAAC;YACD,IAAI,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;gBACzD,SAAS;YACX,CAAC;YACD,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACtE,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The summon↔pragma seam: turn a generator + a prompt strategy into a
|
|
3
|
+
* `Task<GeneratorResult>` — WITHOUT running it.
|
|
4
|
+
*
|
|
5
|
+
* This one function is the whole seam. Both binaries build the same task here
|
|
6
|
+
* and interpret it their own way: pragma's `create` verb forwards the prompt
|
|
7
|
+
* strategy through `runtime.exec.promptHandler` and lets the kernel interpret
|
|
8
|
+
* it under the node / dry-run / undo interpreters; the summon bin runs it via
|
|
9
|
+
* `runGeneratorTask({ promptHandler })`. Same package + same handler ⇒
|
|
10
|
+
* byte-identical files.
|
|
11
|
+
*
|
|
12
|
+
* Because `execute` returns a task and does NOT run it, `--dry-run` and
|
|
13
|
+
* `--undo` keep working unchanged through the kernel's existing interpreters
|
|
14
|
+
* (which mock `Prompt` effects to their defaults). The task's shape is:
|
|
15
|
+
*
|
|
16
|
+
* collectAnswers → validate → confirm gate → generate → result
|
|
17
|
+
*
|
|
18
|
+
* The confirm gate is an ordinary `confirm` Prompt effect ({@link CONFIRM_ANSWER_KEY}):
|
|
19
|
+
* the non-interactive strategies resolve it to its default (`true`) and the
|
|
20
|
+
* dry-run interpreter mocks it to `true`, so it is a no-op there; the Ink
|
|
21
|
+
* strategy recognises the key and renders the preview + "Proceed?" gate. It is
|
|
22
|
+
* the single signal that answer collection is complete — which a streaming
|
|
23
|
+
* per-question handler otherwise cannot know.
|
|
24
|
+
*/
|
|
25
|
+
import { $, dryRun, fail, gen, prompt } from "@canonical/task";
|
|
26
|
+
import collectAnswers, {} from "./collectAnswers.js";
|
|
27
|
+
import validateAnswers from "./validateAnswers.js";
|
|
28
|
+
/** The reserved answer key of the confirm gate the Ink strategy recognises. */
|
|
29
|
+
export const CONFIRM_ANSWER_KEY = "__summon_proceed__";
|
|
30
|
+
/** Task-error code for an answer that fails its prompt's own constraints. */
|
|
31
|
+
export const GENERATOR_INVALID_ANSWER = "GENERATOR_INVALID_ANSWER";
|
|
32
|
+
/** Task-error code for a run cancelled at the interactive confirm gate. */
|
|
33
|
+
export const GENERATOR_CANCELLED = "GENERATOR_CANCELLED";
|
|
34
|
+
/**
|
|
35
|
+
* Build the seam task for one generator run.
|
|
36
|
+
*
|
|
37
|
+
* @param generator - The generator to run.
|
|
38
|
+
* @param ctx - The prompt strategy, provided answers, and optional abort signal.
|
|
39
|
+
* @returns A task that collects+validates answers, gates on confirmation, then
|
|
40
|
+
* performs the generation and yields a {@link GeneratorResult}.
|
|
41
|
+
*/
|
|
42
|
+
export default function execute(generator, ctx) {
|
|
43
|
+
return gen(function* () {
|
|
44
|
+
// 1. Collect answers — asks each unprovided, applicable prompt as a Prompt
|
|
45
|
+
// effect through the runner's injected handler (ctx.prompt).
|
|
46
|
+
const answers = yield* $(collectAnswers(generator.prompts, ctx.params));
|
|
47
|
+
// 2. Validate — reject the same bad input (unknown enum, failing validator)
|
|
48
|
+
// a wizard would, so flag/MCP-arg runs are held to the same constraints.
|
|
49
|
+
const invalid = validateAnswers(generator.prompts, answers);
|
|
50
|
+
if (invalid !== null) {
|
|
51
|
+
yield* $(fail({ code: GENERATOR_INVALID_ANSWER, message: invalid }));
|
|
52
|
+
}
|
|
53
|
+
// 3. Confirm gate — see the module doc. Auto/MCP/dry-run resolve to `true`.
|
|
54
|
+
const proceed = yield* $(prompt({
|
|
55
|
+
type: "confirm",
|
|
56
|
+
name: CONFIRM_ANSWER_KEY,
|
|
57
|
+
message: "Proceed?",
|
|
58
|
+
default: true,
|
|
59
|
+
}));
|
|
60
|
+
if (proceed === false) {
|
|
61
|
+
yield* $(fail({ code: GENERATOR_CANCELLED, message: "Cancelled." }));
|
|
62
|
+
}
|
|
63
|
+
// 4. Build once, preview its effects (pure), then perform them. On the
|
|
64
|
+
// dry-run interpreter step 4's `generate` effects ARE the plan; on the
|
|
65
|
+
// node interpreter they write for real. The preview gives the outcome
|
|
66
|
+
// summary its file list without re-running side effects.
|
|
67
|
+
const built = generator.generate(answers);
|
|
68
|
+
const effects = dryRun(built).effects;
|
|
69
|
+
yield* $(built);
|
|
70
|
+
return { generator, answers, effects };
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=execute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/execute/execute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAa,MAAM,iBAAiB,CAAC;AAG1E,OAAO,cAAc,EAAE,EAAyB,MAAM,qBAAqB,CAAC;AAE5E,OAAO,eAAe,MAAM,sBAAsB,CAAC;AAEnD,+EAA+E;AAC/E,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAC;AAEvD,6EAA6E;AAC7E,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAC;AAEnE,2EAA2E;AAC3E,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAgBzD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,SAA8B,EAC9B,GAAmB;IAEnB,OAAO,GAAG,CAAC,QAAQ,CAAC;QAClB,2EAA2E;QAC3E,gEAAgE;QAChE,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CACtB,cAAc,CACZ,SAAS,CAAC,OAAsC,EAChD,GAAG,CAAC,MAAM,CACX,CACF,CAAC;QAEF,4EAA4E;QAC5E,4EAA4E;QAC5E,MAAM,OAAO,GAAG,eAAe,CAAC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5D,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,wBAAwB,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;QACvE,CAAC;QAED,4EAA4E;QAC5E,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CACtB,MAAM,CAAC;YACL,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,kBAAkB;YACxB,OAAO,EAAE,UAAU;YACnB,OAAO,EAAE,IAAI;SACd,CAAC,CACH,CAAC;QACF,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;YACtB,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC;QACvE,CAAC;QAED,uEAAuE;QACvE,0EAA0E;QAC1E,yEAAyE;QACzE,4DAA4D;QAC5D,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC1C,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;QACtC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAEhB,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as collectAnswers } from "./collectAnswers.js";
|
|
2
|
+
export { CONFIRM_ANSWER_KEY, default as execute, GENERATOR_CANCELLED, GENERATOR_INVALID_ANSWER, } from "./execute.js";
|
|
3
|
+
export { default as validateAnswers } from "./validateAnswers.js";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/execute/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EACL,kBAAkB,EAClB,OAAO,IAAI,OAAO,EAElB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate resolved generator answers against each prompt's own constraints.
|
|
3
|
+
*
|
|
4
|
+
* `select` answers must be one of the declared choices, and any `validate`
|
|
5
|
+
* function must accept the value. Returns the first failure message, or `null`
|
|
6
|
+
* when every applicable answer is valid.
|
|
7
|
+
*
|
|
8
|
+
* Reuses the exact `validate` the interactive prompt already runs, so a
|
|
9
|
+
* flag-driven or MCP-arg run (non-interactive) rejects the same bad input a
|
|
10
|
+
* wizard would — e.g. an empty component path or an unknown package type. This
|
|
11
|
+
* is the moved v1 `executeGenerator.findInvalidAnswer`, now run inside
|
|
12
|
+
* {@link execute} so both interactive and non-interactive paths share it.
|
|
13
|
+
*/
|
|
14
|
+
/** Convert a camelCase prompt name to its kebab-case CLI flag form. */
|
|
15
|
+
const toKebab = (name) => name.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
16
|
+
/**
|
|
17
|
+
* Find the first answer that violates its prompt's constraints.
|
|
18
|
+
*
|
|
19
|
+
* @param prompts - The generator's prompt definitions.
|
|
20
|
+
* @param answers - The resolved answers to validate.
|
|
21
|
+
* @returns A human-readable message for the first invalid answer, or `null`.
|
|
22
|
+
*/
|
|
23
|
+
export default function validateAnswers(prompts, answers) {
|
|
24
|
+
for (const prompt of prompts) {
|
|
25
|
+
if (prompt.when && prompt.when(answers) !== true)
|
|
26
|
+
continue;
|
|
27
|
+
if (!(prompt.name in answers))
|
|
28
|
+
continue;
|
|
29
|
+
const value = answers[prompt.name];
|
|
30
|
+
if (prompt.type === "select" &&
|
|
31
|
+
prompt.choices &&
|
|
32
|
+
prompt.choices.length > 0 &&
|
|
33
|
+
!prompt.choices.some((choice) => choice.value === value)) {
|
|
34
|
+
const valid = prompt.choices.map((choice) => choice.value).join(", ");
|
|
35
|
+
return `Invalid --${toKebab(prompt.name)} "${String(value)}". Valid values: ${valid}.`;
|
|
36
|
+
}
|
|
37
|
+
if (prompt.validate) {
|
|
38
|
+
const verdict = prompt.validate(value);
|
|
39
|
+
if (verdict !== true) {
|
|
40
|
+
const detail = typeof verdict === "string" ? verdict : "invalid value";
|
|
41
|
+
return `Invalid --${toKebab(prompt.name)}: ${detail}`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=validateAnswers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateAnswers.js","sourceRoot":"","sources":["../../../src/execute/validateAnswers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,uEAAuE;AACvE,MAAM,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,CACvC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,OAAoC,EACpC,OAAgC;IAEhC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI;YAAE,SAAS;QAC3D,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,OA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