@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/cli.js
CHANGED
|
@@ -4185,7 +4185,7 @@ var require_package = __commonJS({
|
|
|
4185
4185
|
"package.json"(exports2, module2) {
|
|
4186
4186
|
module2.exports = {
|
|
4187
4187
|
name: "@flowrunner/cli",
|
|
4188
|
-
version: "0.1.
|
|
4188
|
+
version: "0.1.7",
|
|
4189
4189
|
publishConfig: {
|
|
4190
4190
|
access: "public"
|
|
4191
4191
|
},
|
|
@@ -4464,6 +4464,16 @@ function serviceDirectory(serviceId, projectRoot = process.cwd()) {
|
|
|
4464
4464
|
|
|
4465
4465
|
// src/templates/manifest.ts
|
|
4466
4466
|
var SERVICE_ID_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
4467
|
+
function toServiceId(value) {
|
|
4468
|
+
return value.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^[^a-z]+/, "").replace(/-+$/, "");
|
|
4469
|
+
}
|
|
4470
|
+
function availableServiceId(id, projectRoot) {
|
|
4471
|
+
let candidate = id;
|
|
4472
|
+
for (let suffix = 2; import_fs.default.existsSync(serviceDirectory(candidate, projectRoot)); suffix++) {
|
|
4473
|
+
candidate = `${id}-${suffix}`;
|
|
4474
|
+
}
|
|
4475
|
+
return candidate;
|
|
4476
|
+
}
|
|
4467
4477
|
var VALIDATORS = {
|
|
4468
4478
|
// Both halves of "is this a usable id" live together, so the prompt can re-ask on either. Availability is
|
|
4469
4479
|
// checked here rather than at write time so the user finds out while they are still on that question.
|
|
@@ -4478,15 +4488,20 @@ var VALIDATORS = {
|
|
|
4478
4488
|
},
|
|
4479
4489
|
nonEmpty: (value) => value.trim().length > 0 ? null : "must not be empty"
|
|
4480
4490
|
};
|
|
4491
|
+
var NORMALIZERS = {
|
|
4492
|
+
serviceId: toServiceId
|
|
4493
|
+
};
|
|
4481
4494
|
var VALIDATOR_NAMES = Object.keys(VALIDATORS);
|
|
4482
4495
|
var StringPromptSchema = import_zod.z.object({
|
|
4483
4496
|
name: import_zod.z.string().min(1),
|
|
4484
4497
|
label: import_zod.z.string().min(1),
|
|
4485
4498
|
type: import_zod.z.literal("string"),
|
|
4486
4499
|
hint: import_zod.z.string().optional(),
|
|
4487
|
-
// May interpolate a value fixed by `values`,
|
|
4488
|
-
// "{{id}}", "{{
|
|
4489
|
-
|
|
4500
|
+
// May interpolate a value fixed by `values`, a value supplied up front (flag or `--set`), or an answer
|
|
4501
|
+
// collected *earlier* in the list: "{{id}}", "{{name|serviceId}}". A list is a chain of candidates: the
|
|
4502
|
+
// first whose placeholders all resolve to something non-empty wins — `["{{id|titleCase}}", "My Service"]`
|
|
4503
|
+
// follows an `--id` flag when there is one and falls back to the literal when there is not.
|
|
4504
|
+
default: import_zod.z.union([import_zod.z.string(), import_zod.z.array(import_zod.z.string()).min(1)]).default(""),
|
|
4490
4505
|
validate: import_zod.z.enum(VALIDATOR_NAMES).optional()
|
|
4491
4506
|
});
|
|
4492
4507
|
var BooleanPromptSchema = import_zod.z.object({
|
|
@@ -4642,7 +4657,8 @@ var IF_CLOSE = /^\s*(?:\/\/|#|<!--)\s*\{\{\/if\s*\}\}/;
|
|
|
4642
4657
|
var FILTERS = {
|
|
4643
4658
|
titleCase: (value) => value.split(/[-_\s]+/).filter(Boolean).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" "),
|
|
4644
4659
|
upperCase: (value) => value.toUpperCase(),
|
|
4645
|
-
lowerCase: (value) => value.toLowerCase()
|
|
4660
|
+
lowerCase: (value) => value.toLowerCase(),
|
|
4661
|
+
serviceId: toServiceId
|
|
4646
4662
|
};
|
|
4647
4663
|
function applyFilter(name, value) {
|
|
4648
4664
|
const filter = FILTERS[name];
|
|
@@ -4651,6 +4667,9 @@ function applyFilter(name, value) {
|
|
|
4651
4667
|
}
|
|
4652
4668
|
return filter(value);
|
|
4653
4669
|
}
|
|
4670
|
+
function canInterpolate(source, answers) {
|
|
4671
|
+
return [...source.matchAll(PLACEHOLDER)].every(([, name]) => name in answers);
|
|
4672
|
+
}
|
|
4654
4673
|
function interpolate(source, answers, origin) {
|
|
4655
4674
|
return source.replace(PLACEHOLDER, (_match, name, filter) => {
|
|
4656
4675
|
if (!(name in answers)) {
|
|
@@ -4748,7 +4767,15 @@ function resolveDefault(prompt, answers) {
|
|
|
4748
4767
|
if (prompt.type === "boolean" || prompt.type === "choice") {
|
|
4749
4768
|
return prompt.default;
|
|
4750
4769
|
}
|
|
4751
|
-
|
|
4770
|
+
const origin = `default of "${prompt.name}"`;
|
|
4771
|
+
const candidates = Array.isArray(prompt.default) ? prompt.default : [prompt.default];
|
|
4772
|
+
for (const candidate of candidates) {
|
|
4773
|
+
const value = canInterpolate(candidate, answers) ? interpolate(candidate, answers, origin) : "";
|
|
4774
|
+
if (value) {
|
|
4775
|
+
return value;
|
|
4776
|
+
}
|
|
4777
|
+
}
|
|
4778
|
+
return interpolate(candidates[candidates.length - 1], answers, origin);
|
|
4752
4779
|
}
|
|
4753
4780
|
function coerceBoolean(label, value) {
|
|
4754
4781
|
if (typeof value === "boolean") {
|
|
@@ -4772,6 +4799,16 @@ function validator(prompt, context) {
|
|
|
4772
4799
|
return failure && `${prompt.label} ${failure}`;
|
|
4773
4800
|
};
|
|
4774
4801
|
}
|
|
4802
|
+
function normalizer(prompt) {
|
|
4803
|
+
const normalize = prompt.type === "string" && prompt.validate ? NORMALIZERS[prompt.validate] : void 0;
|
|
4804
|
+
return normalize ?? ((value) => value);
|
|
4805
|
+
}
|
|
4806
|
+
function offeredDefault(prompt, fallback, context) {
|
|
4807
|
+
if (prompt.type === "string" && prompt.validate === "serviceId" && typeof fallback === "string" && fallback) {
|
|
4808
|
+
return availableServiceId(fallback, context.projectRoot);
|
|
4809
|
+
}
|
|
4810
|
+
return fallback;
|
|
4811
|
+
}
|
|
4775
4812
|
async function resolveAnswers(prompts, {
|
|
4776
4813
|
prefilled = {},
|
|
4777
4814
|
constants = {},
|
|
@@ -4781,6 +4818,7 @@ async function resolveAnswers(prompts, {
|
|
|
4781
4818
|
} = {}) {
|
|
4782
4819
|
const context = { projectRoot };
|
|
4783
4820
|
const answers = { ...constants };
|
|
4821
|
+
const prefilledDefaults = {};
|
|
4784
4822
|
const known = [...prompts.map((prompt) => prompt.name), ...Object.keys(constants)];
|
|
4785
4823
|
const unknown = Object.keys(prefilled).filter((name) => !known.includes(name));
|
|
4786
4824
|
if (unknown.length > 0) {
|
|
@@ -4789,7 +4827,12 @@ async function resolveAnswers(prompts, {
|
|
|
4789
4827
|
);
|
|
4790
4828
|
}
|
|
4791
4829
|
for (const prompt of prompts) {
|
|
4792
|
-
|
|
4830
|
+
if (prompt.name in prefilled && prompt.type === "string") {
|
|
4831
|
+
prefilledDefaults[prompt.name] = String(prefilled[prompt.name]);
|
|
4832
|
+
}
|
|
4833
|
+
}
|
|
4834
|
+
for (const prompt of prompts) {
|
|
4835
|
+
const fallback = resolveDefault(prompt, { ...prefilledDefaults, ...answers });
|
|
4793
4836
|
const validate2 = validator(prompt, context);
|
|
4794
4837
|
if (prompt.name in prefilled) {
|
|
4795
4838
|
const supplied = prefilled[prompt.name];
|
|
@@ -4826,7 +4869,12 @@ async function resolveAnswers(prompts, {
|
|
|
4826
4869
|
`"${prompt.name}" has no answer and there is no way to ask for one. Supply it up front, or accept the defaults.`
|
|
4827
4870
|
);
|
|
4828
4871
|
}
|
|
4829
|
-
answers[prompt.name] = await ask({
|
|
4872
|
+
answers[prompt.name] = await ask({
|
|
4873
|
+
prompt,
|
|
4874
|
+
fallback: offeredDefault(prompt, fallback, context),
|
|
4875
|
+
validate: validate2,
|
|
4876
|
+
normalize: normalizer(prompt)
|
|
4877
|
+
});
|
|
4830
4878
|
}
|
|
4831
4879
|
for (const [name, value] of Object.entries(prefilled)) {
|
|
4832
4880
|
if (prompts.some((prompt) => prompt.name === name)) {
|
|
@@ -10142,7 +10190,7 @@ function createPrompter() {
|
|
|
10142
10190
|
close: () => rl?.close()
|
|
10143
10191
|
};
|
|
10144
10192
|
}
|
|
10145
|
-
async function askOne({ prompt, fallback, validate: validate2 }, readlineInterface) {
|
|
10193
|
+
async function askOne({ prompt, fallback, validate: validate2, normalize }, readlineInterface) {
|
|
10146
10194
|
markDirty();
|
|
10147
10195
|
hint2(prompt.hint);
|
|
10148
10196
|
if (prompt.type === "choice") {
|
|
@@ -10155,7 +10203,11 @@ async function askOne({ prompt, fallback, validate: validate2 }, readlineInterfa
|
|
|
10155
10203
|
}
|
|
10156
10204
|
while (true) {
|
|
10157
10205
|
const raw = (await readlineInterface().question(`${prompt.label} (${fallback}): `)).trim();
|
|
10158
|
-
const
|
|
10206
|
+
const typed = raw === "" ? String(fallback) : raw;
|
|
10207
|
+
const value = normalize(typed);
|
|
10208
|
+
if (value && value !== typed) {
|
|
10209
|
+
say(`${DIM} \u2192 ${value}${RESET}`);
|
|
10210
|
+
}
|
|
10159
10211
|
const failure = validate2(value);
|
|
10160
10212
|
if (!failure) {
|
|
10161
10213
|
return value;
|