grimoire-wizard 0.3.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/LICENSE +21 -0
- package/README.md +1399 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +2485 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +354 -0
- package/dist/index.js +1922 -0
- package/dist/index.js.map +1 -0
- package/examples/all-features.yaml +54 -0
- package/examples/base.yaml +28 -0
- package/examples/basic.yaml +61 -0
- package/examples/conditional.yaml +126 -0
- package/examples/demo.yaml +112 -0
- package/examples/ebay-mcp-setup.yaml +171 -0
- package/examples/extended.yaml +34 -0
- package/examples/themed.yaml +92 -0
- package/examples/with-checks.yaml +34 -0
- package/package.json +73 -0
- package/schema/grimoire.schema.json +964 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
type Condition = {
|
|
2
|
+
field: string;
|
|
3
|
+
equals: unknown;
|
|
4
|
+
} | {
|
|
5
|
+
field: string;
|
|
6
|
+
notEquals: unknown;
|
|
7
|
+
} | {
|
|
8
|
+
field: string;
|
|
9
|
+
includes: unknown;
|
|
10
|
+
} | {
|
|
11
|
+
field: string;
|
|
12
|
+
notIncludes: unknown;
|
|
13
|
+
} | {
|
|
14
|
+
field: string;
|
|
15
|
+
greaterThan: number;
|
|
16
|
+
} | {
|
|
17
|
+
field: string;
|
|
18
|
+
lessThan: number;
|
|
19
|
+
} | {
|
|
20
|
+
field: string;
|
|
21
|
+
isEmpty: true;
|
|
22
|
+
} | {
|
|
23
|
+
field: string;
|
|
24
|
+
isNotEmpty: true;
|
|
25
|
+
} | {
|
|
26
|
+
all: Condition[];
|
|
27
|
+
} | {
|
|
28
|
+
any: Condition[];
|
|
29
|
+
} | {
|
|
30
|
+
not: Condition;
|
|
31
|
+
};
|
|
32
|
+
type ValidationRule = {
|
|
33
|
+
rule: 'required';
|
|
34
|
+
message?: string;
|
|
35
|
+
} | {
|
|
36
|
+
rule: 'minLength';
|
|
37
|
+
value: number;
|
|
38
|
+
message?: string;
|
|
39
|
+
} | {
|
|
40
|
+
rule: 'maxLength';
|
|
41
|
+
value: number;
|
|
42
|
+
message?: string;
|
|
43
|
+
} | {
|
|
44
|
+
rule: 'pattern';
|
|
45
|
+
value: string;
|
|
46
|
+
message?: string;
|
|
47
|
+
} | {
|
|
48
|
+
rule: 'min';
|
|
49
|
+
value: number;
|
|
50
|
+
message?: string;
|
|
51
|
+
} | {
|
|
52
|
+
rule: 'max';
|
|
53
|
+
value: number;
|
|
54
|
+
message?: string;
|
|
55
|
+
};
|
|
56
|
+
interface SelectOption {
|
|
57
|
+
value: string;
|
|
58
|
+
label: string;
|
|
59
|
+
hint?: string;
|
|
60
|
+
disabled?: boolean | string;
|
|
61
|
+
}
|
|
62
|
+
interface SeparatorOption {
|
|
63
|
+
separator: string;
|
|
64
|
+
}
|
|
65
|
+
type SelectChoice = SelectOption | SeparatorOption;
|
|
66
|
+
interface BaseStepConfig {
|
|
67
|
+
id: string;
|
|
68
|
+
type: string;
|
|
69
|
+
message: string;
|
|
70
|
+
description?: string;
|
|
71
|
+
next?: string;
|
|
72
|
+
when?: Condition;
|
|
73
|
+
keepValuesOnPrevious?: boolean;
|
|
74
|
+
required?: boolean;
|
|
75
|
+
group?: string;
|
|
76
|
+
}
|
|
77
|
+
interface TextStepConfig extends BaseStepConfig {
|
|
78
|
+
type: 'text';
|
|
79
|
+
placeholder?: string;
|
|
80
|
+
default?: string;
|
|
81
|
+
validate?: ValidationRule[];
|
|
82
|
+
}
|
|
83
|
+
interface SelectStepConfig extends BaseStepConfig {
|
|
84
|
+
type: 'select';
|
|
85
|
+
options: SelectChoice[];
|
|
86
|
+
optionsFrom?: string;
|
|
87
|
+
default?: string;
|
|
88
|
+
routes?: Record<string, string>;
|
|
89
|
+
pageSize?: number;
|
|
90
|
+
loop?: boolean;
|
|
91
|
+
}
|
|
92
|
+
interface MultiSelectStepConfig extends BaseStepConfig {
|
|
93
|
+
type: 'multiselect';
|
|
94
|
+
options: SelectChoice[];
|
|
95
|
+
optionsFrom?: string;
|
|
96
|
+
default?: string[];
|
|
97
|
+
min?: number;
|
|
98
|
+
max?: number;
|
|
99
|
+
pageSize?: number;
|
|
100
|
+
loop?: boolean;
|
|
101
|
+
}
|
|
102
|
+
interface ConfirmStepConfig extends BaseStepConfig {
|
|
103
|
+
type: 'confirm';
|
|
104
|
+
default?: boolean;
|
|
105
|
+
}
|
|
106
|
+
interface PasswordStepConfig extends BaseStepConfig {
|
|
107
|
+
type: 'password';
|
|
108
|
+
validate?: ValidationRule[];
|
|
109
|
+
}
|
|
110
|
+
interface NumberStepConfig extends BaseStepConfig {
|
|
111
|
+
type: 'number';
|
|
112
|
+
default?: number;
|
|
113
|
+
min?: number;
|
|
114
|
+
max?: number;
|
|
115
|
+
step?: number;
|
|
116
|
+
}
|
|
117
|
+
interface SearchStepConfig extends BaseStepConfig {
|
|
118
|
+
type: 'search';
|
|
119
|
+
options: SelectChoice[];
|
|
120
|
+
optionsFrom?: string;
|
|
121
|
+
default?: string;
|
|
122
|
+
placeholder?: string;
|
|
123
|
+
pageSize?: number;
|
|
124
|
+
loop?: boolean;
|
|
125
|
+
}
|
|
126
|
+
interface EditorStepConfig extends BaseStepConfig {
|
|
127
|
+
type: 'editor';
|
|
128
|
+
default?: string;
|
|
129
|
+
validate?: ValidationRule[];
|
|
130
|
+
}
|
|
131
|
+
interface PathStepConfig extends BaseStepConfig {
|
|
132
|
+
type: 'path';
|
|
133
|
+
default?: string;
|
|
134
|
+
placeholder?: string;
|
|
135
|
+
validate?: ValidationRule[];
|
|
136
|
+
}
|
|
137
|
+
interface ToggleStepConfig extends BaseStepConfig {
|
|
138
|
+
type: 'toggle';
|
|
139
|
+
default?: boolean;
|
|
140
|
+
active?: string;
|
|
141
|
+
inactive?: string;
|
|
142
|
+
}
|
|
143
|
+
interface MessageStepConfig extends BaseStepConfig {
|
|
144
|
+
type: 'message';
|
|
145
|
+
}
|
|
146
|
+
type StepConfig = TextStepConfig | SelectStepConfig | MultiSelectStepConfig | ConfirmStepConfig | PasswordStepConfig | NumberStepConfig | SearchStepConfig | EditorStepConfig | PathStepConfig | ToggleStepConfig | MessageStepConfig;
|
|
147
|
+
interface ThemeConfig {
|
|
148
|
+
tokens?: {
|
|
149
|
+
primary?: string;
|
|
150
|
+
success?: string;
|
|
151
|
+
error?: string;
|
|
152
|
+
warning?: string;
|
|
153
|
+
info?: string;
|
|
154
|
+
muted?: string;
|
|
155
|
+
accent?: string;
|
|
156
|
+
};
|
|
157
|
+
icons?: {
|
|
158
|
+
step?: string;
|
|
159
|
+
stepDone?: string;
|
|
160
|
+
stepPending?: string;
|
|
161
|
+
pointer?: string;
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
interface PreFlightCheck {
|
|
165
|
+
name: string;
|
|
166
|
+
run: string;
|
|
167
|
+
message: string;
|
|
168
|
+
}
|
|
169
|
+
interface ActionConfig {
|
|
170
|
+
name?: string;
|
|
171
|
+
run: string;
|
|
172
|
+
when?: Condition;
|
|
173
|
+
}
|
|
174
|
+
interface WizardConfig {
|
|
175
|
+
meta: {
|
|
176
|
+
name: string;
|
|
177
|
+
version?: string;
|
|
178
|
+
description?: string;
|
|
179
|
+
};
|
|
180
|
+
theme?: ThemeConfig;
|
|
181
|
+
steps: StepConfig[];
|
|
182
|
+
output?: {
|
|
183
|
+
format: 'json' | 'env' | 'yaml';
|
|
184
|
+
path?: string;
|
|
185
|
+
};
|
|
186
|
+
extends?: string;
|
|
187
|
+
checks?: PreFlightCheck[];
|
|
188
|
+
actions?: ActionConfig[];
|
|
189
|
+
}
|
|
190
|
+
interface WizardState {
|
|
191
|
+
currentStepId: string;
|
|
192
|
+
answers: Record<string, unknown>;
|
|
193
|
+
history: string[];
|
|
194
|
+
status: 'running' | 'done' | 'cancelled';
|
|
195
|
+
errors: Record<string, string>;
|
|
196
|
+
}
|
|
197
|
+
type WizardTransition = {
|
|
198
|
+
type: 'NEXT';
|
|
199
|
+
value: unknown;
|
|
200
|
+
} | {
|
|
201
|
+
type: 'BACK';
|
|
202
|
+
} | {
|
|
203
|
+
type: 'JUMP';
|
|
204
|
+
stepId: string;
|
|
205
|
+
} | {
|
|
206
|
+
type: 'CANCEL';
|
|
207
|
+
};
|
|
208
|
+
interface ResolvedTheme {
|
|
209
|
+
primary: (text: string) => string;
|
|
210
|
+
success: (text: string) => string;
|
|
211
|
+
error: (text: string) => string;
|
|
212
|
+
warning: (text: string) => string;
|
|
213
|
+
info: (text: string) => string;
|
|
214
|
+
muted: (text: string) => string;
|
|
215
|
+
accent: (text: string) => string;
|
|
216
|
+
bold: (text: string) => string;
|
|
217
|
+
icons: Required<NonNullable<ThemeConfig['icons']>>;
|
|
218
|
+
}
|
|
219
|
+
interface WizardRenderer {
|
|
220
|
+
renderText(step: TextStepConfig, state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
221
|
+
renderSelect(step: SelectStepConfig, state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
222
|
+
renderMultiSelect(step: MultiSelectStepConfig, state: WizardState, theme: ResolvedTheme): Promise<string[]>;
|
|
223
|
+
renderConfirm(step: ConfirmStepConfig, state: WizardState, theme: ResolvedTheme): Promise<boolean>;
|
|
224
|
+
renderPassword(step: PasswordStepConfig, state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
225
|
+
renderNumber(step: NumberStepConfig, state: WizardState, theme: ResolvedTheme): Promise<number>;
|
|
226
|
+
renderSearch(step: SearchStepConfig, state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
227
|
+
renderEditor(step: EditorStepConfig, state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
228
|
+
renderPath(step: PathStepConfig, state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
229
|
+
renderToggle(step: ToggleStepConfig, state: WizardState, theme: ResolvedTheme): Promise<boolean>;
|
|
230
|
+
renderMessage(step: MessageStepConfig, state: WizardState, theme: ResolvedTheme): void;
|
|
231
|
+
renderStepHeader(stepIndex: number, totalVisible: number, message: string, theme: ResolvedTheme, description?: string): void;
|
|
232
|
+
renderGroupHeader(group: string, theme: ResolvedTheme): void;
|
|
233
|
+
renderSummary(answers: Record<string, unknown>, steps: StepConfig[], theme: ResolvedTheme): void;
|
|
234
|
+
clear(): void;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
declare function parseWizardConfig(raw: unknown): WizardConfig;
|
|
238
|
+
|
|
239
|
+
declare function loadWizardConfig(filePath: string): Promise<WizardConfig>;
|
|
240
|
+
declare function parseWizardYAML(yamlString: string): WizardConfig;
|
|
241
|
+
|
|
242
|
+
declare function evaluateCondition(condition: Condition, answers: Record<string, unknown>): boolean;
|
|
243
|
+
declare function isStepVisible(step: StepConfig, answers: Record<string, unknown>): boolean;
|
|
244
|
+
|
|
245
|
+
declare function createWizardState(config: WizardConfig): WizardState;
|
|
246
|
+
declare function validateStepAnswer(step: StepConfig, value: unknown): string | null;
|
|
247
|
+
declare function resolveNextStep(config: WizardConfig, currentStep: StepConfig, answer: unknown, answers: Record<string, unknown>): string;
|
|
248
|
+
declare function getVisibleSteps(config: WizardConfig, answers: Record<string, unknown>): StepConfig[];
|
|
249
|
+
declare function wizardReducer(state: WizardState, transition: WizardTransition, config: WizardConfig): WizardState;
|
|
250
|
+
|
|
251
|
+
declare function resolveTheme(themeConfig?: ThemeConfig): ResolvedTheme;
|
|
252
|
+
|
|
253
|
+
declare function resolveEnvDefault(value: string | undefined): string | undefined;
|
|
254
|
+
|
|
255
|
+
interface StepPlugin {
|
|
256
|
+
render(config: Record<string, unknown>, state: WizardState, theme: ResolvedTheme): Promise<unknown>;
|
|
257
|
+
validate?(value: unknown, config: Record<string, unknown>): string | null;
|
|
258
|
+
}
|
|
259
|
+
interface GrimoirePlugin {
|
|
260
|
+
name: string;
|
|
261
|
+
steps: Record<string, StepPlugin>;
|
|
262
|
+
}
|
|
263
|
+
declare function registerPlugin(plugin: GrimoirePlugin): void;
|
|
264
|
+
declare function getPluginStep(stepType: string): StepPlugin | undefined;
|
|
265
|
+
declare function clearPlugins(): void;
|
|
266
|
+
|
|
267
|
+
interface RunWizardOptions {
|
|
268
|
+
renderer?: WizardRenderer;
|
|
269
|
+
quiet?: boolean;
|
|
270
|
+
plain?: boolean;
|
|
271
|
+
mockAnswers?: Record<string, unknown>;
|
|
272
|
+
templateAnswers?: Record<string, unknown>;
|
|
273
|
+
onBeforeStep?: (stepId: string, step: StepConfig, state: WizardState) => Promise<void> | void;
|
|
274
|
+
onAfterStep?: (stepId: string, value: unknown, state: WizardState) => Promise<void> | void;
|
|
275
|
+
onStepComplete?: (stepId: string, value: unknown, state: WizardState) => void;
|
|
276
|
+
onCancel?: (state: WizardState) => void;
|
|
277
|
+
plugins?: GrimoirePlugin[];
|
|
278
|
+
asyncValidate?: (stepId: string, value: unknown, answers: Record<string, unknown>) => Promise<string | null>;
|
|
279
|
+
cache?: boolean | {
|
|
280
|
+
dir?: string;
|
|
281
|
+
};
|
|
282
|
+
mru?: boolean;
|
|
283
|
+
}
|
|
284
|
+
declare function runPreFlightChecks(checks: PreFlightCheck[], theme: ResolvedTheme): void;
|
|
285
|
+
declare function runWizard(config: WizardConfig, options?: RunWizardOptions): Promise<Record<string, unknown>>;
|
|
286
|
+
|
|
287
|
+
declare function defineWizard(config: WizardConfig): WizardConfig;
|
|
288
|
+
|
|
289
|
+
declare class InquirerRenderer implements WizardRenderer {
|
|
290
|
+
renderStepHeader(stepIndex: number, totalVisible: number, message: string, theme: ResolvedTheme, description?: string): void;
|
|
291
|
+
renderText(step: TextStepConfig, state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
292
|
+
renderSelect(step: SelectStepConfig, state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
293
|
+
renderMultiSelect(step: MultiSelectStepConfig, state: WizardState, theme: ResolvedTheme): Promise<string[]>;
|
|
294
|
+
renderConfirm(step: ConfirmStepConfig, state: WizardState, theme: ResolvedTheme): Promise<boolean>;
|
|
295
|
+
renderPassword(step: PasswordStepConfig, _state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
296
|
+
renderNumber(step: NumberStepConfig, state: WizardState, theme: ResolvedTheme): Promise<number>;
|
|
297
|
+
renderSearch(step: SearchStepConfig, _state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
298
|
+
renderEditor(step: EditorStepConfig, _state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
299
|
+
renderPath(step: PathStepConfig, state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
300
|
+
renderToggle(step: ToggleStepConfig, state: WizardState, theme: ResolvedTheme): Promise<boolean>;
|
|
301
|
+
renderMessage(step: MessageStepConfig, _state: WizardState, theme: ResolvedTheme): void;
|
|
302
|
+
renderGroupHeader(group: string, theme: ResolvedTheme): void;
|
|
303
|
+
renderSummary(answers: Record<string, unknown>, steps: StepConfig[], theme: ResolvedTheme): void;
|
|
304
|
+
clear(): void;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Resolve {{stepId}} placeholders in a template string.
|
|
309
|
+
* Array values are joined with ", ". Unresolved placeholders remain as-is.
|
|
310
|
+
*/
|
|
311
|
+
declare function resolveTemplate(template: string, answers: Record<string, unknown>): string;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Render a figlet ASCII art banner for the wizard name.
|
|
315
|
+
* Falls back to plain bold text if figlet rendering fails.
|
|
316
|
+
*/
|
|
317
|
+
declare function renderBanner(name: string, theme: ResolvedTheme, options?: {
|
|
318
|
+
plain?: boolean;
|
|
319
|
+
}): string;
|
|
320
|
+
|
|
321
|
+
declare function slugify(name: string): string;
|
|
322
|
+
declare function getCacheDir(customDir?: string): string;
|
|
323
|
+
declare function loadCachedAnswers(wizardName: string, customDir?: string): Record<string, unknown> | undefined;
|
|
324
|
+
declare function saveCachedAnswers(wizardName: string, answers: Record<string, unknown>, customDir?: string): void;
|
|
325
|
+
declare function clearCache(wizardName?: string, customDir?: string): void;
|
|
326
|
+
|
|
327
|
+
declare function recordSelection(wizardName: string, stepId: string, value: string | string[]): void;
|
|
328
|
+
declare function getOrderedOptions(wizardName: string, stepId: string, options: SelectChoice[]): SelectChoice[];
|
|
329
|
+
declare function clearMruData(wizardName: string): void;
|
|
330
|
+
|
|
331
|
+
declare class InkRenderer implements WizardRenderer {
|
|
332
|
+
renderStepHeader(stepIndex: number, totalVisible: number, message: string, theme: ResolvedTheme, description?: string): void;
|
|
333
|
+
renderText(step: TextStepConfig, state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
334
|
+
renderSelect(step: SelectStepConfig, state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
335
|
+
renderMultiSelect(step: MultiSelectStepConfig, state: WizardState, theme: ResolvedTheme): Promise<string[]>;
|
|
336
|
+
renderConfirm(step: ConfirmStepConfig, state: WizardState, theme: ResolvedTheme): Promise<boolean>;
|
|
337
|
+
renderPassword(step: PasswordStepConfig, _state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
338
|
+
renderNumber(step: NumberStepConfig, state: WizardState, theme: ResolvedTheme): Promise<number>;
|
|
339
|
+
renderSearch(step: SearchStepConfig, _state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
340
|
+
renderEditor(step: EditorStepConfig, _state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
341
|
+
renderPath(step: PathStepConfig, state: WizardState, theme: ResolvedTheme): Promise<string>;
|
|
342
|
+
renderToggle(step: ToggleStepConfig, state: WizardState, theme: ResolvedTheme): Promise<boolean>;
|
|
343
|
+
renderMessage(step: MessageStepConfig, _state: WizardState, theme: ResolvedTheme): void;
|
|
344
|
+
renderGroupHeader(group: string, theme: ResolvedTheme): void;
|
|
345
|
+
renderSummary(answers: Record<string, unknown>, steps: StepConfig[], theme: ResolvedTheme): void;
|
|
346
|
+
clear(): void;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
declare function saveTemplate(wizardName: string, templateName: string, answers: Record<string, unknown>, excludeKeys?: string[]): void;
|
|
350
|
+
declare function loadTemplate(wizardName: string, templateName: string): Record<string, unknown> | undefined;
|
|
351
|
+
declare function listTemplates(wizardName: string): string[];
|
|
352
|
+
declare function deleteTemplate(wizardName: string, templateName: string): void;
|
|
353
|
+
|
|
354
|
+
export { type ActionConfig, type Condition, type ConfirmStepConfig, type EditorStepConfig, type GrimoirePlugin, InkRenderer, InquirerRenderer, type MessageStepConfig, type MultiSelectStepConfig, type NumberStepConfig, type PasswordStepConfig, type PathStepConfig, type PreFlightCheck, type ResolvedTheme, type RunWizardOptions, type SearchStepConfig, type SelectChoice, type SelectOption, type SelectStepConfig, type SeparatorOption, type StepConfig, type StepPlugin, type TextStepConfig, type ThemeConfig, type ToggleStepConfig, type ValidationRule, type WizardConfig, type WizardRenderer, type WizardState, type WizardTransition, clearCache, clearMruData, clearPlugins, createWizardState, defineWizard, deleteTemplate, evaluateCondition, getCacheDir, getOrderedOptions, getPluginStep, getVisibleSteps, isStepVisible, listTemplates, loadCachedAnswers, loadTemplate, loadWizardConfig, parseWizardConfig, parseWizardYAML, recordSelection, registerPlugin, renderBanner, resolveEnvDefault, resolveNextStep, resolveTemplate, resolveTheme, runPreFlightChecks, runWizard, saveCachedAnswers, saveTemplate, slugify, validateStepAnswer, wizardReducer };
|