@flowrunner/cli 0.1.5 → 0.1.6-dev.1
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 +93 -33
- package/dist/cli.js.map +3 -3
- 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/dist/types/shared/src/constants/docs.d.ts +4 -0
- package/dist/types/shared/src/constants/index.d.ts +1 -0
- package/package.json +1 -1
- package/runtime/types/shared/src/constants/docs.d.ts +4 -0
- package/runtime/types/shared/src/constants/index.d.ts +1 -0
- 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.6-dev.1",
|
|
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)) {
|
|
@@ -4672,7 +4691,7 @@ function stripConditionals(source, answers, origin) {
|
|
|
4672
4691
|
throw new Error(`Unknown flag "${name}" in {{#if}} at ${origin}:${index + 1}`);
|
|
4673
4692
|
}
|
|
4674
4693
|
const matches = expected === void 0 ? Boolean(answers[name]) : String(answers[name]) === expected;
|
|
4675
|
-
stack.push({ name, keep: matches && stack.every((
|
|
4694
|
+
stack.push({ name, keep: matches && stack.every((frame) => frame.keep) });
|
|
4676
4695
|
continue;
|
|
4677
4696
|
}
|
|
4678
4697
|
if (IF_CLOSE.test(line)) {
|
|
@@ -4681,7 +4700,7 @@ function stripConditionals(source, answers, origin) {
|
|
|
4681
4700
|
}
|
|
4682
4701
|
continue;
|
|
4683
4702
|
}
|
|
4684
|
-
if (stack.every((
|
|
4703
|
+
if (stack.every((frame) => frame.keep)) {
|
|
4685
4704
|
output.push(line);
|
|
4686
4705
|
}
|
|
4687
4706
|
}
|
|
@@ -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)) {
|
|
@@ -9933,6 +9981,7 @@ async function interactiveLogin(gap) {
|
|
|
9933
9981
|
|
|
9934
9982
|
// src/cli/prompts/select-list.ts
|
|
9935
9983
|
var import_node_readline = __toESM(require("node:readline"));
|
|
9984
|
+
var import_node_util = require("node:util");
|
|
9936
9985
|
function canRenderList() {
|
|
9937
9986
|
return Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
9938
9987
|
}
|
|
@@ -9973,46 +10022,52 @@ var SHOW_CURSOR = "\x1B[?25h";
|
|
|
9973
10022
|
function styling() {
|
|
9974
10023
|
return process.env.NO_COLOR ? { dim: "", bold: "", reset: "" } : { dim: "\x1B[2m", bold: "\x1B[1m", reset: "\x1B[0m" };
|
|
9975
10024
|
}
|
|
9976
|
-
function
|
|
9977
|
-
|
|
9978
|
-
return plainLength <= width ? line : `${line.slice(0, line.length - (plainLength - width) - 1)}\u2026`;
|
|
10025
|
+
function terminalColumns() {
|
|
10026
|
+
return process.stdout.columns || 80;
|
|
9979
10027
|
}
|
|
9980
|
-
function
|
|
10028
|
+
function renderFrame(choices, selected, columns) {
|
|
9981
10029
|
const { dim, bold, reset } = styling();
|
|
9982
|
-
const
|
|
10030
|
+
const rows = [];
|
|
9983
10031
|
for (const [index, choice] of choices.entries()) {
|
|
9984
10032
|
const active = index === selected;
|
|
9985
|
-
|
|
9986
|
-
const label = active ? `${bold}${choice.label}${reset}` : choice.label;
|
|
9987
|
-
lines.push(fit(`${pointer} ${label}`, `${pointer} ${choice.label}`.length));
|
|
10033
|
+
rows.push({ prefix: active ? "\u276F " : " ", text: choice.label, style: active ? bold : "" });
|
|
9988
10034
|
if (choice.description) {
|
|
9989
|
-
|
|
10035
|
+
rows.push({ prefix: " ", text: choice.description, style: dim });
|
|
9990
10036
|
}
|
|
9991
10037
|
}
|
|
9992
|
-
|
|
9993
|
-
|
|
9994
|
-
|
|
9995
|
-
|
|
9996
|
-
|
|
9997
|
-
|
|
10038
|
+
rows.push({ prefix: "", text: "", style: "" });
|
|
10039
|
+
rows.push({ prefix: " ", text: "\u2191/\u2193 to move \xB7 enter to select \xB7 esc to cancel", style: dim });
|
|
10040
|
+
const width = columns - 1;
|
|
10041
|
+
return rows.map(({ prefix, text: text2, style }) => {
|
|
10042
|
+
const room = width - prefix.length;
|
|
10043
|
+
const fitted = text2.length <= room ? text2 : `${text2.slice(0, Math.max(room - 1, 0))}\u2026`;
|
|
10044
|
+
return style && fitted ? `${prefix}${style}${fitted}${reset}` : `${prefix}${fitted}`;
|
|
10045
|
+
});
|
|
10046
|
+
}
|
|
10047
|
+
function rowsOccupied(lines, columns) {
|
|
10048
|
+
return lines.reduce((total, line) => {
|
|
10049
|
+
const visible = (0, import_node_util.stripVTControlCharacters)(line).length;
|
|
10050
|
+
return total + Math.max(1, Math.ceil(visible / columns));
|
|
10051
|
+
}, 0);
|
|
9998
10052
|
}
|
|
9999
10053
|
function selectFromList(title, choices, startAt = 0) {
|
|
10000
10054
|
const { stdin, stdout } = process;
|
|
10001
10055
|
return new Promise((resolve, reject) => {
|
|
10002
10056
|
let selected = Math.min(Math.max(startAt, 0), choices.length - 1);
|
|
10003
|
-
let painted =
|
|
10057
|
+
let painted = [];
|
|
10004
10058
|
const draw = () => {
|
|
10005
|
-
|
|
10006
|
-
|
|
10059
|
+
const columns = terminalColumns();
|
|
10060
|
+
if (painted.length > 0) {
|
|
10061
|
+
import_node_readline.default.moveCursor(stdout, 0, -rowsOccupied(painted, columns));
|
|
10007
10062
|
import_node_readline.default.clearScreenDown(stdout);
|
|
10008
10063
|
}
|
|
10009
|
-
|
|
10010
|
-
stdout.write(`${
|
|
10064
|
+
painted = renderFrame(choices, selected, columns);
|
|
10065
|
+
stdout.write(`${painted.join("\n")}
|
|
10011
10066
|
`);
|
|
10012
|
-
painted = lines.length;
|
|
10013
10067
|
};
|
|
10014
10068
|
const cleanup = () => {
|
|
10015
10069
|
stdin.off("keypress", onKeypress);
|
|
10070
|
+
stdout.off("resize", draw);
|
|
10016
10071
|
if (stdin.isTTY) {
|
|
10017
10072
|
stdin.setRawMode(false);
|
|
10018
10073
|
}
|
|
@@ -10044,6 +10099,7 @@ ${title}
|
|
|
10044
10099
|
stdin.setRawMode(true);
|
|
10045
10100
|
stdin.resume();
|
|
10046
10101
|
stdin.on("keypress", onKeypress);
|
|
10102
|
+
stdout.on("resize", draw);
|
|
10047
10103
|
draw();
|
|
10048
10104
|
});
|
|
10049
10105
|
}
|
|
@@ -10134,7 +10190,7 @@ function createPrompter() {
|
|
|
10134
10190
|
close: () => rl?.close()
|
|
10135
10191
|
};
|
|
10136
10192
|
}
|
|
10137
|
-
async function askOne({ prompt, fallback, validate: validate2 }, readlineInterface) {
|
|
10193
|
+
async function askOne({ prompt, fallback, validate: validate2, normalize }, readlineInterface) {
|
|
10138
10194
|
markDirty();
|
|
10139
10195
|
hint2(prompt.hint);
|
|
10140
10196
|
if (prompt.type === "choice") {
|
|
@@ -10147,7 +10203,11 @@ async function askOne({ prompt, fallback, validate: validate2 }, readlineInterfa
|
|
|
10147
10203
|
}
|
|
10148
10204
|
while (true) {
|
|
10149
10205
|
const raw = (await readlineInterface().question(`${prompt.label} (${fallback}): `)).trim();
|
|
10150
|
-
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
|
+
}
|
|
10151
10211
|
const failure = validate2(value);
|
|
10152
10212
|
if (!failure) {
|
|
10153
10213
|
return value;
|