@flowrunner/cli 0.1.6 → 0.1.7
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/cli.js +62 -10
- package/dist/cli.js.map +2 -2
- package/dist/index.js +55 -7
- package/dist/index.js.map +2 -2
- package/dist/types/packages/cli/src/operations/init/answers.d.ts +12 -1
- package/dist/types/packages/cli/src/templates/index.d.ts +2 -2
- package/dist/types/packages/cli/src/templates/manifest.d.ts +20 -2
- package/dist/types/packages/cli/src/templates/render.d.ts +2 -0
- package/package.json +1 -1
- package/templates/blank/template.json +9 -9
- package/templates/demo-todo-list/template.json +9 -9
- package/templates/qa-test/template.json +9 -9
package/dist/index.js
CHANGED
|
@@ -9086,6 +9086,16 @@ function serviceDirectory(serviceId, projectRoot = process.cwd()) {
|
|
|
9086
9086
|
|
|
9087
9087
|
// src/templates/manifest.ts
|
|
9088
9088
|
var SERVICE_ID_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
9089
|
+
function toServiceId(value) {
|
|
9090
|
+
return value.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^[^a-z]+/, "").replace(/-+$/, "");
|
|
9091
|
+
}
|
|
9092
|
+
function availableServiceId(id, projectRoot) {
|
|
9093
|
+
let candidate = id;
|
|
9094
|
+
for (let suffix = 2; import_fs9.default.existsSync(serviceDirectory(candidate, projectRoot)); suffix++) {
|
|
9095
|
+
candidate = `${id}-${suffix}`;
|
|
9096
|
+
}
|
|
9097
|
+
return candidate;
|
|
9098
|
+
}
|
|
9089
9099
|
var VALIDATORS = {
|
|
9090
9100
|
// Both halves of "is this a usable id" live together, so the prompt can re-ask on either. Availability is
|
|
9091
9101
|
// checked here rather than at write time so the user finds out while they are still on that question.
|
|
@@ -9100,15 +9110,20 @@ var VALIDATORS = {
|
|
|
9100
9110
|
},
|
|
9101
9111
|
nonEmpty: (value) => value.trim().length > 0 ? null : "must not be empty"
|
|
9102
9112
|
};
|
|
9113
|
+
var NORMALIZERS = {
|
|
9114
|
+
serviceId: toServiceId
|
|
9115
|
+
};
|
|
9103
9116
|
var VALIDATOR_NAMES = Object.keys(VALIDATORS);
|
|
9104
9117
|
var StringPromptSchema = import_zod5.z.object({
|
|
9105
9118
|
name: import_zod5.z.string().min(1),
|
|
9106
9119
|
label: import_zod5.z.string().min(1),
|
|
9107
9120
|
type: import_zod5.z.literal("string"),
|
|
9108
9121
|
hint: import_zod5.z.string().optional(),
|
|
9109
|
-
// May interpolate a value fixed by `values`,
|
|
9110
|
-
// "{{id}}", "{{
|
|
9111
|
-
|
|
9122
|
+
// May interpolate a value fixed by `values`, a value supplied up front (flag or `--set`), or an answer
|
|
9123
|
+
// collected *earlier* in the list: "{{id}}", "{{name|serviceId}}". A list is a chain of candidates: the
|
|
9124
|
+
// first whose placeholders all resolve to something non-empty wins — `["{{id|titleCase}}", "My Service"]`
|
|
9125
|
+
// follows an `--id` flag when there is one and falls back to the literal when there is not.
|
|
9126
|
+
default: import_zod5.z.union([import_zod5.z.string(), import_zod5.z.array(import_zod5.z.string()).min(1)]).default(""),
|
|
9112
9127
|
validate: import_zod5.z.enum(VALIDATOR_NAMES).optional()
|
|
9113
9128
|
});
|
|
9114
9129
|
var BooleanPromptSchema = import_zod5.z.object({
|
|
@@ -9235,7 +9250,8 @@ var IF_CLOSE = /^\s*(?:\/\/|#|<!--)\s*\{\{\/if\s*\}\}/;
|
|
|
9235
9250
|
var FILTERS = {
|
|
9236
9251
|
titleCase: (value) => value.split(/[-_\s]+/).filter(Boolean).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" "),
|
|
9237
9252
|
upperCase: (value) => value.toUpperCase(),
|
|
9238
|
-
lowerCase: (value) => value.toLowerCase()
|
|
9253
|
+
lowerCase: (value) => value.toLowerCase(),
|
|
9254
|
+
serviceId: toServiceId
|
|
9239
9255
|
};
|
|
9240
9256
|
function applyFilter(name, value) {
|
|
9241
9257
|
const filter = FILTERS[name];
|
|
@@ -9244,6 +9260,9 @@ function applyFilter(name, value) {
|
|
|
9244
9260
|
}
|
|
9245
9261
|
return filter(value);
|
|
9246
9262
|
}
|
|
9263
|
+
function canInterpolate(source, answers) {
|
|
9264
|
+
return [...source.matchAll(PLACEHOLDER)].every(([, name]) => name in answers);
|
|
9265
|
+
}
|
|
9247
9266
|
function interpolate(source, answers, origin) {
|
|
9248
9267
|
return source.replace(PLACEHOLDER, (_match, name, filter) => {
|
|
9249
9268
|
if (!(name in answers)) {
|
|
@@ -9336,7 +9355,15 @@ function resolveDefault(prompt, answers) {
|
|
|
9336
9355
|
if (prompt.type === "boolean" || prompt.type === "choice") {
|
|
9337
9356
|
return prompt.default;
|
|
9338
9357
|
}
|
|
9339
|
-
|
|
9358
|
+
const origin = `default of "${prompt.name}"`;
|
|
9359
|
+
const candidates = Array.isArray(prompt.default) ? prompt.default : [prompt.default];
|
|
9360
|
+
for (const candidate of candidates) {
|
|
9361
|
+
const value = canInterpolate(candidate, answers) ? interpolate(candidate, answers, origin) : "";
|
|
9362
|
+
if (value) {
|
|
9363
|
+
return value;
|
|
9364
|
+
}
|
|
9365
|
+
}
|
|
9366
|
+
return interpolate(candidates[candidates.length - 1], answers, origin);
|
|
9340
9367
|
}
|
|
9341
9368
|
function coerceBoolean(label, value) {
|
|
9342
9369
|
if (typeof value === "boolean") {
|
|
@@ -9360,6 +9387,16 @@ function validator(prompt, context) {
|
|
|
9360
9387
|
return failure && `${prompt.label} ${failure}`;
|
|
9361
9388
|
};
|
|
9362
9389
|
}
|
|
9390
|
+
function normalizer(prompt) {
|
|
9391
|
+
const normalize = prompt.type === "string" && prompt.validate ? NORMALIZERS[prompt.validate] : void 0;
|
|
9392
|
+
return normalize ?? ((value) => value);
|
|
9393
|
+
}
|
|
9394
|
+
function offeredDefault(prompt, fallback, context) {
|
|
9395
|
+
if (prompt.type === "string" && prompt.validate === "serviceId" && typeof fallback === "string" && fallback) {
|
|
9396
|
+
return availableServiceId(fallback, context.projectRoot);
|
|
9397
|
+
}
|
|
9398
|
+
return fallback;
|
|
9399
|
+
}
|
|
9363
9400
|
async function resolveAnswers(prompts, {
|
|
9364
9401
|
prefilled = {},
|
|
9365
9402
|
constants = {},
|
|
@@ -9369,6 +9406,7 @@ async function resolveAnswers(prompts, {
|
|
|
9369
9406
|
} = {}) {
|
|
9370
9407
|
const context = { projectRoot };
|
|
9371
9408
|
const answers = { ...constants };
|
|
9409
|
+
const prefilledDefaults = {};
|
|
9372
9410
|
const known = [...prompts.map((prompt) => prompt.name), ...Object.keys(constants)];
|
|
9373
9411
|
const unknown = Object.keys(prefilled).filter((name) => !known.includes(name));
|
|
9374
9412
|
if (unknown.length > 0) {
|
|
@@ -9377,7 +9415,12 @@ async function resolveAnswers(prompts, {
|
|
|
9377
9415
|
);
|
|
9378
9416
|
}
|
|
9379
9417
|
for (const prompt of prompts) {
|
|
9380
|
-
|
|
9418
|
+
if (prompt.name in prefilled && prompt.type === "string") {
|
|
9419
|
+
prefilledDefaults[prompt.name] = String(prefilled[prompt.name]);
|
|
9420
|
+
}
|
|
9421
|
+
}
|
|
9422
|
+
for (const prompt of prompts) {
|
|
9423
|
+
const fallback = resolveDefault(prompt, { ...prefilledDefaults, ...answers });
|
|
9381
9424
|
const validate2 = validator(prompt, context);
|
|
9382
9425
|
if (prompt.name in prefilled) {
|
|
9383
9426
|
const supplied = prefilled[prompt.name];
|
|
@@ -9414,7 +9457,12 @@ async function resolveAnswers(prompts, {
|
|
|
9414
9457
|
`"${prompt.name}" has no answer and there is no way to ask for one. Supply it up front, or accept the defaults.`
|
|
9415
9458
|
);
|
|
9416
9459
|
}
|
|
9417
|
-
answers[prompt.name] = await ask({
|
|
9460
|
+
answers[prompt.name] = await ask({
|
|
9461
|
+
prompt,
|
|
9462
|
+
fallback: offeredDefault(prompt, fallback, context),
|
|
9463
|
+
validate: validate2,
|
|
9464
|
+
normalize: normalizer(prompt)
|
|
9465
|
+
});
|
|
9418
9466
|
}
|
|
9419
9467
|
for (const [name, value] of Object.entries(prefilled)) {
|
|
9420
9468
|
if (prompts.some((prompt) => prompt.name === name)) {
|