@docsxai/engine 0.3.0-rc.3 → 0.3.0-rc.5
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/README.md +44 -34
- package/dist/atomic-write.d.ts +19 -0
- package/dist/atomic-write.js +127 -0
- package/dist/auth/api-login.d.ts +9 -51
- package/dist/auth/api-login.js +3 -3
- package/dist/auth/browser-session.js +1 -1
- package/dist/auth/cookie-jar.d.ts +4 -4
- package/dist/auth/cookie-jar.js +4 -4
- package/dist/auth/email-otp.d.ts +11 -147
- package/dist/auth/email-otp.js +4 -4
- package/dist/auth/http-basic.js +1 -1
- package/dist/auth/index.js +3 -3
- package/dist/auth/jwt-injection.d.ts +7 -131
- package/dist/auth/jwt-injection.js +5 -5
- package/dist/auth/manual-capture.d.ts +3 -3
- package/dist/auth/manual-capture.js +2 -2
- package/dist/auth/mtls.d.ts +1 -6
- package/dist/auth/mtls.js +1 -1
- package/dist/auth/pat-header.d.ts +1 -9
- package/dist/auth/pat-header.js +1 -1
- package/dist/auth/storage-state-cache.d.ts +16 -6
- package/dist/auth/storage-state-cache.js +65 -15
- package/dist/auth/test-backdoor.d.ts +2 -13
- package/dist/auth/test-backdoor.js +3 -3
- package/dist/auth/totp.d.ts +1 -1
- package/dist/auth/totp.js +4 -4
- package/dist/auth/types.d.ts +3 -3
- package/dist/auth/types.js +4 -4
- package/dist/auth/ui-form.d.ts +24 -153
- package/dist/auth/ui-form.js +3 -3
- package/dist/auth/webauthn.d.ts +7 -67
- package/dist/auth/webauthn.js +3 -3
- package/dist/auth.js +1 -1
- package/dist/backend-client-contracts.d.ts +1 -1
- package/dist/backend-client-contracts.js +2 -2
- package/dist/backend-client-oauth-login.js +1 -1
- package/dist/backend-client-state-cache.d.ts +2 -2
- package/dist/backend-client-state-cache.js +8 -8
- package/dist/backend-client-token.js +4 -4
- package/dist/backend-client-transport.d.ts +2 -2
- package/dist/backend-client-transport.js +3 -3
- package/dist/backend-client.js +6 -6
- package/dist/browser-build.d.ts +6 -0
- package/dist/browser-build.js +12 -0
- package/dist/browser-launch-error.d.ts +18 -0
- package/dist/browser-launch-error.js +63 -0
- package/dist/browser-wait.d.ts +7 -0
- package/dist/browser-wait.js +12 -0
- package/dist/calibrate.d.ts +6 -2
- package/dist/calibrate.js +20 -13
- package/dist/cli-backend-errors.d.ts +5 -0
- package/dist/cli-backend-errors.js +24 -3
- package/dist/cli-commands-auth.d.ts +1 -0
- package/dist/cli-commands-auth.js +114 -0
- package/dist/cli-commands-authoring.d.ts +0 -1
- package/dist/cli-commands-authoring.js +124 -101
- package/dist/cli-commands-backend.d.ts +1 -1
- package/dist/cli-commands-backend.js +76 -21
- package/dist/cli-commands-docpack.d.ts +3 -1
- package/dist/cli-commands-docpack.js +145 -39
- package/dist/cli-commands-init.d.ts +1 -0
- package/dist/cli-commands-init.js +100 -0
- package/dist/cli-commands-pack.d.ts +1 -1
- package/dist/cli-commands-pack.js +6 -4
- package/dist/cli-commands-session.d.ts +1 -3
- package/dist/cli-commands-session.js +109 -180
- package/dist/cli-commands-site.d.ts +2 -0
- package/dist/cli-commands-site.js +77 -0
- package/dist/cli-commands-style.d.ts +1 -0
- package/dist/cli-commands-style.js +85 -0
- package/dist/cli-flags.d.ts +18 -0
- package/dist/cli-flags.js +77 -0
- package/dist/cli-help.d.ts +30 -0
- package/dist/cli-help.js +174 -0
- package/dist/cli-messages.d.ts +30 -0
- package/dist/cli-messages.js +97 -0
- package/dist/cli-node-guard.d.ts +1 -0
- package/dist/cli-node-guard.js +8 -0
- package/dist/cli-retired.js +6 -0
- package/dist/cli-run-stale.d.ts +2 -0
- package/dist/cli-run-stale.js +13 -0
- package/dist/cli-run-summary.js +7 -3
- package/dist/cli-shared.d.ts +30 -1
- package/dist/cli-shared.js +112 -12
- package/dist/cli-unexpected.d.ts +12 -2
- package/dist/cli-unexpected.js +50 -4
- package/dist/cli-usage.d.ts +1 -1
- package/dist/cli-usage.js +115 -66
- package/dist/cli-value-flags.d.ts +8 -0
- package/dist/cli-value-flags.js +34 -0
- package/dist/cli-version.d.ts +6 -0
- package/dist/cli-version.js +25 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +42 -19
- package/dist/deprecation.d.ts +2 -0
- package/dist/deprecation.js +2 -0
- package/dist/device-scale-factor.d.ts +14 -0
- package/dist/device-scale-factor.js +38 -0
- package/dist/diagnose.js +14 -13
- package/dist/diff-compute.js +22 -8
- package/dist/diff-report.js +3 -3
- package/dist/diff-types.js +1 -1
- package/dist/diff.js +3 -3
- package/dist/doc-pack-io.js +62 -47
- package/dist/doc-pack.d.ts +567 -3487
- package/dist/doc-pack.js +47 -33
- package/dist/doctor-checks-config.d.ts +12 -0
- package/dist/doctor-checks-config.js +229 -0
- package/dist/doctor-checks-plugins.js +2 -2
- package/dist/doctor-checks-site.d.ts +3 -0
- package/dist/doctor-checks-site.js +21 -0
- package/dist/doctor-checks.d.ts +13 -2
- package/dist/doctor-checks.js +94 -79
- package/dist/doctor-next.d.ts +5 -0
- package/dist/doctor-next.js +52 -0
- package/dist/doctor.d.ts +36 -2
- package/dist/doctor.js +88 -29
- package/dist/environment-spec.d.ts +36 -44
- package/dist/environment-spec.js +31 -3
- package/dist/export/adf.d.ts +1 -1
- package/dist/export/adf.js +16 -27
- package/dist/export/playwright-test.d.ts +1 -1
- package/dist/export/playwright-test.js +13 -15
- package/dist/flow-file.d.ts +1 -1
- package/dist/flow-file.js +22 -4
- package/dist/flow-halt.d.ts +1 -1
- package/dist/flow-halt.js +15 -3
- package/dist/flow-lint.d.ts +3 -1
- package/dist/flow-lint.js +39 -26
- package/dist/flow-matrix-lint.js +2 -2
- package/dist/flow-runtime.d.ts +17 -6
- package/dist/flow-runtime.js +48 -17
- package/dist/flow-success.js +4 -4
- package/dist/flow-tree.js +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/main-module.d.ts +1 -0
- package/dist/main-module.js +17 -0
- package/dist/matrix-spec.d.ts +33 -106
- package/dist/matrix-spec.js +12 -3
- package/dist/node-floor.d.ts +4 -0
- package/dist/node-floor.js +14 -0
- package/dist/obstacles.js +1 -1
- package/dist/open-in-browser.d.ts +22 -0
- package/dist/open-in-browser.js +37 -0
- package/dist/playwright-driver.d.ts +8 -12
- package/dist/playwright-driver.js +75 -70
- package/dist/playwright-instrumented-browser.d.ts +10 -7
- package/dist/playwright-instrumented-browser.js +35 -12
- package/dist/plugins/load.d.ts +1 -1
- package/dist/plugins/load.js +4 -4
- package/dist/plugins/lock.js +11 -8
- package/dist/plugins/manifest.d.ts +16 -35
- package/dist/plugins/manifest.js +5 -5
- package/dist/plugins/plan.d.ts +3 -3
- package/dist/plugins/plan.js +14 -14
- package/dist/plugins/registry.d.ts +1 -1
- package/dist/plugins/registry.js +1 -1
- package/dist/plugins/runtime.js +3 -3
- package/dist/plugins/types.d.ts +1 -1
- package/dist/plugins-cli.js +36 -28
- package/dist/posix-path.d.ts +2 -0
- package/dist/posix-path.js +7 -0
- package/dist/redact.js +2 -2
- package/dist/run-flows.d.ts +7 -0
- package/dist/run-flows.js +75 -27
- package/dist/style.d.ts +2 -2
- package/dist/style.js +13 -11
- package/dist/verify-determinism.js +2 -1
- package/dist/verify-next-step.d.ts +2 -0
- package/dist/verify-next-step.js +24 -0
- package/dist/verify-report.js +3 -2
- package/dist/viewer-bin.d.ts +9 -3
- package/dist/viewer-bin.js +35 -12
- package/dist/workspace-templates.d.ts +15 -0
- package/dist/workspace-templates.js +88 -0
- package/dist/workspace.d.ts +78 -5
- package/dist/workspace.js +47 -28
- package/dist/zip.d.ts +1 -1
- package/dist/zip.js +23 -6
- package/package.json +6 -6
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The flags each command accepts, and the parse that holds argv to them. An unknown flag is a usage
|
|
2
|
+
// error with a "did you mean" when one is close, a flag given twice is a usage error, and a boolean
|
|
3
|
+
// flag never takes the next argument as its value (`run --pause ws` keeps `ws` as the workspace).
|
|
4
|
+
// Commands with their own argv loop (`burn`, `pack`, `site`) check their flags there.
|
|
5
|
+
// Leaf module: imports only the help and message helpers.
|
|
6
|
+
import { nearestName } from "./cli-help.js";
|
|
7
|
+
import { usageError } from "./cli-messages.js";
|
|
8
|
+
import { parseFlags } from "./cli-shared.js";
|
|
9
|
+
const RUN_VALUE = [
|
|
10
|
+
"flow",
|
|
11
|
+
"base-url",
|
|
12
|
+
"stop-after",
|
|
13
|
+
"start-from",
|
|
14
|
+
"variant",
|
|
15
|
+
"cdp",
|
|
16
|
+
"concurrency",
|
|
17
|
+
"runs",
|
|
18
|
+
"format",
|
|
19
|
+
"device-scale-factor",
|
|
20
|
+
];
|
|
21
|
+
/** Every command that reads its argv through {@link parseCommandFlags}, with the flags in `--help`. */
|
|
22
|
+
export const COMMAND_FLAGS = {
|
|
23
|
+
init: {
|
|
24
|
+
value: ["app-url", "auth", "role", "ttl", "capture-trigger", "auth-cookie", "persist"],
|
|
25
|
+
bool: ["ignore-https-errors", "force", "example"],
|
|
26
|
+
},
|
|
27
|
+
"add-flow": { value: ["from", "name"], bool: [] },
|
|
28
|
+
inspect: {
|
|
29
|
+
value: ["url", "selector", "cdp", "wait", "wait-for", "role"],
|
|
30
|
+
bool: ["headed", "ignore-https-errors"],
|
|
31
|
+
},
|
|
32
|
+
run: {
|
|
33
|
+
value: RUN_VALUE,
|
|
34
|
+
bool: ["headed", "ignore-https-errors", "pause"],
|
|
35
|
+
loose: ["verify-determinism"],
|
|
36
|
+
},
|
|
37
|
+
lint: { value: ["flow", "format"], bool: [] },
|
|
38
|
+
"flow-tree": { value: ["format"], bool: [] },
|
|
39
|
+
diagnose: { value: ["flow", "step", "cdp", "variant", "format"], bool: [] },
|
|
40
|
+
style: { value: ["format"], bool: ["check"] },
|
|
41
|
+
zip: { value: ["out"], bool: ["include-viewer"] },
|
|
42
|
+
baseline: { value: ["out"], bool: [] },
|
|
43
|
+
diff: { value: ["against", "format", "fail-on"], bool: [] },
|
|
44
|
+
"export adf": { value: ["mode", "flow", "title", "out"], bool: [] },
|
|
45
|
+
"export playwright": { value: ["flow", "out"], bool: [] },
|
|
46
|
+
plugins: { value: ["format"], bool: [] },
|
|
47
|
+
doctor: { value: ["format"], bool: ["offline"] },
|
|
48
|
+
render: { value: ["lang"], bool: ["open"] },
|
|
49
|
+
login: { value: ["backend-url"], bool: [], loose: ["oauth"] },
|
|
50
|
+
push: { value: ["kind", "author"], bool: [] },
|
|
51
|
+
pull: { value: ["rev"], bool: [] },
|
|
52
|
+
"capture-auth": {
|
|
53
|
+
value: ["base-url", "role", "auth-cookie", "cdp"],
|
|
54
|
+
bool: ["fresh", "headless", "ignore-https-errors"],
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Parse `args` for `label` (the key into {@link COMMAND_FLAGS} unless `spec` names another).
|
|
59
|
+
* Returns the parsed argv, or exit code 2 after the usage error.
|
|
60
|
+
*/
|
|
61
|
+
export function parseCommandFlags(label, args, spec = label) {
|
|
62
|
+
const known = COMMAND_FLAGS[spec];
|
|
63
|
+
if (!known)
|
|
64
|
+
throw new Error(`no flag table for ${spec}`);
|
|
65
|
+
const { positionals, flags, repeated, boolWithValue } = parseFlags(args, known.bool);
|
|
66
|
+
const all = [...known.value, ...known.bool, ...(known.loose ?? [])];
|
|
67
|
+
const unknown = [...flags.keys()].find((k) => !all.includes(k));
|
|
68
|
+
if (unknown !== undefined) {
|
|
69
|
+
const near = nearestName(unknown, all);
|
|
70
|
+
return usageError(label, `unknown flag --${unknown}${near ? `, did you mean --${near}?` : ""}`);
|
|
71
|
+
}
|
|
72
|
+
if (boolWithValue[0])
|
|
73
|
+
return usageError(label, `--${boolWithValue[0]} takes no value`);
|
|
74
|
+
if (repeated[0])
|
|
75
|
+
return usageError(label, `--${repeated[0]} given more than once`);
|
|
76
|
+
return { positionals, flags };
|
|
77
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** The first steps for a new user, printed before any long list. */
|
|
2
|
+
export declare const START_HERE = "Start here (an example flow on example.com):\n 1. docsxai init <workspace-dir> --example\n 2. docsxai run <workspace-dir>\n 3. docsxai render <workspace-dir> --open\nYour own app: docsxai init <workspace-dir> --app-url <url>, then docsxai add-flow.";
|
|
3
|
+
/** Commands by purpose, each with a one-line description. Every dispatched command appears once. */
|
|
4
|
+
export declare const COMMAND_GROUPS: ReadonlyArray<{
|
|
5
|
+
title: string;
|
|
6
|
+
commands: ReadonlyArray<readonly [name: string, description: string]>;
|
|
7
|
+
}>;
|
|
8
|
+
/** Every command name in {@link COMMAND_GROUPS}, in listing order. */
|
|
9
|
+
export declare function commandNames(): string[];
|
|
10
|
+
/** The grouped command list, one line each. */
|
|
11
|
+
export declare function groupedCommands(): string;
|
|
12
|
+
/** What `docsxai` prints with no argument: the first steps, then the commands by purpose. */
|
|
13
|
+
export declare function startScreen(): string;
|
|
14
|
+
/** What `docsxai --help` prints: the first steps and the groups, then the full usage text. */
|
|
15
|
+
export declare function fullHelp(): string;
|
|
16
|
+
/** Levenshtein distance between two strings. */
|
|
17
|
+
export declare function editDistance(a: string, b: string): number;
|
|
18
|
+
/** The name in `names` closest to `input` within edit distance 2, or `undefined`. The first listed wins a tie. */
|
|
19
|
+
export declare function nearestName(input: string, names: readonly string[]): string | undefined;
|
|
20
|
+
/** The command closest to `input` within edit distance 2, or `undefined`. */
|
|
21
|
+
export declare function suggestCommand(input: string): string | undefined;
|
|
22
|
+
/** The usage lines and one example of `command`, or `undefined` for a name that is not a command. */
|
|
23
|
+
export declare function commandHelp(command: string): string | undefined;
|
|
24
|
+
/** Print the unknown-command message, with a suggestion when one is close. Returns exit code 2. */
|
|
25
|
+
export declare function unknownCommand(cmd: string): number;
|
|
26
|
+
/**
|
|
27
|
+
* Handle `help [<command>]` and `<command> --help|-h`. Returns the exit code, or `undefined` when
|
|
28
|
+
* argv is an ordinary command line. `doctor` keeps its own help, so it is left to its handler.
|
|
29
|
+
*/
|
|
30
|
+
export declare function tryHelp(cmd: string | undefined, rest: string[]): number | undefined;
|
package/dist/cli-help.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// Help screens and typo suggestions for the `docsxai` CLI. Builds on the USAGE text and the
|
|
2
|
+
// per-command usage lookup in cli-messages.ts; cli.ts calls it for `help`, `--help` and an unknown
|
|
3
|
+
// command. Leaf module: no command handler imports from here.
|
|
4
|
+
import { USAGE } from "./cli-usage.js";
|
|
5
|
+
import { commandUsage } from "./cli-messages.js";
|
|
6
|
+
import { RETIRED_COMMANDS } from "./cli-retired.js";
|
|
7
|
+
import { findRetired } from "./deprecation.js";
|
|
8
|
+
/** The first steps for a new user, printed before any long list. */
|
|
9
|
+
export const START_HERE = `Start here (an example flow on example.com):
|
|
10
|
+
1. docsxai init <workspace-dir> --example
|
|
11
|
+
2. docsxai run <workspace-dir>
|
|
12
|
+
3. docsxai render <workspace-dir> --open
|
|
13
|
+
Your own app: docsxai init <workspace-dir> --app-url <url>, then docsxai add-flow.`;
|
|
14
|
+
/** Commands by purpose, each with a one-line description. Every dispatched command appears once. */
|
|
15
|
+
export const COMMAND_GROUPS = [
|
|
16
|
+
{
|
|
17
|
+
title: "Getting started",
|
|
18
|
+
commands: [
|
|
19
|
+
["init", "scaffold a workspace for your app"],
|
|
20
|
+
["add-flow", "add a flow from a flow-file (formerly calibrate)"],
|
|
21
|
+
["inspect", "list the page's test ids to pin locators"],
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
title: "Run and verify",
|
|
26
|
+
commands: [
|
|
27
|
+
["run", "capture screenshots and annotations (--verify-determinism to check)"],
|
|
28
|
+
["lint", "static checks on the flow files"],
|
|
29
|
+
["flow-tree", "print the extends graph"],
|
|
30
|
+
["style", "create or check docs/style.yaml"],
|
|
31
|
+
["baseline", "snapshot the doc pack as the diff baseline"],
|
|
32
|
+
["diff", "compare the workspace with a baseline"],
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
title: "Publish",
|
|
37
|
+
commands: [
|
|
38
|
+
["render", "build the static viewer"],
|
|
39
|
+
["burn", "bake annotations into copies of the screenshots"],
|
|
40
|
+
["site", "write a Starlight docs site from the doc pack"],
|
|
41
|
+
["zip", "package the doc pack as one archive"],
|
|
42
|
+
["export", "write the flows as ADF or Playwright specs"],
|
|
43
|
+
["push", "upload the doc pack as a backend revision"],
|
|
44
|
+
["pull", "fetch a backend revision into the workspace"],
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
{ title: "Packs", commands: [["pack", "build or check a screenshot pack for a docs site"]] },
|
|
48
|
+
{
|
|
49
|
+
title: "Auth",
|
|
50
|
+
commands: [
|
|
51
|
+
["capture-auth", "log in once and cache the session"],
|
|
52
|
+
["login", "check a backend token or sign in with OAuth"],
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
{ title: "Plugins", commands: [["plugins", "list, inspect or sync a workspace's plugins"]] },
|
|
56
|
+
{
|
|
57
|
+
title: "Diagnostics",
|
|
58
|
+
commands: [
|
|
59
|
+
["doctor", "check the environment and the workspace"],
|
|
60
|
+
["diagnose", "explain a halted step and suggest a fix"],
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
/** Every command name in {@link COMMAND_GROUPS}, in listing order. */
|
|
65
|
+
export function commandNames() {
|
|
66
|
+
return COMMAND_GROUPS.flatMap((g) => g.commands.map(([name]) => name));
|
|
67
|
+
}
|
|
68
|
+
/** The grouped command list, one line each. */
|
|
69
|
+
export function groupedCommands() {
|
|
70
|
+
const lines = [];
|
|
71
|
+
for (const g of COMMAND_GROUPS) {
|
|
72
|
+
lines.push(`${g.title}:`);
|
|
73
|
+
for (const [name, description] of g.commands) {
|
|
74
|
+
lines.push(` ${name.padEnd(13)}${description}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return lines.join("\n");
|
|
78
|
+
}
|
|
79
|
+
/** What `docsxai` prints with no argument: the first steps, then the commands by purpose. */
|
|
80
|
+
export function startScreen() {
|
|
81
|
+
return [
|
|
82
|
+
"docsxai: deterministic execution CLI",
|
|
83
|
+
"",
|
|
84
|
+
START_HERE,
|
|
85
|
+
"",
|
|
86
|
+
groupedCommands(),
|
|
87
|
+
"",
|
|
88
|
+
"docsxai help <command> usage and an example for one command",
|
|
89
|
+
"docsxai --help every command and flag, with notes",
|
|
90
|
+
"",
|
|
91
|
+
].join("\n");
|
|
92
|
+
}
|
|
93
|
+
/** What `docsxai --help` prints: the first steps and the groups, then the full usage text. */
|
|
94
|
+
export function fullHelp() {
|
|
95
|
+
const [title, ...rest] = USAGE.split("\n");
|
|
96
|
+
return [title, "", START_HERE, "", groupedCommands(), ...rest, ""].join("\n");
|
|
97
|
+
}
|
|
98
|
+
/** Levenshtein distance between two strings. */
|
|
99
|
+
export function editDistance(a, b) {
|
|
100
|
+
let prev = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
101
|
+
for (let i = 1; i <= a.length; i++) {
|
|
102
|
+
const row = [i];
|
|
103
|
+
for (let j = 1; j <= b.length; j++) {
|
|
104
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
105
|
+
row.push(Math.min(prev[j] + 1, row[j - 1] + 1, prev[j - 1] + cost));
|
|
106
|
+
}
|
|
107
|
+
prev = row;
|
|
108
|
+
}
|
|
109
|
+
return prev[b.length];
|
|
110
|
+
}
|
|
111
|
+
/** The name in `names` closest to `input` within edit distance 2, or `undefined`. The first listed wins a tie. */
|
|
112
|
+
export function nearestName(input, names) {
|
|
113
|
+
let best;
|
|
114
|
+
let bestDistance = 3;
|
|
115
|
+
for (const name of names) {
|
|
116
|
+
const d = editDistance(input.toLowerCase(), name);
|
|
117
|
+
if (d < bestDistance) {
|
|
118
|
+
best = name;
|
|
119
|
+
bestDistance = d;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return best;
|
|
123
|
+
}
|
|
124
|
+
/** The command closest to `input` within edit distance 2, or `undefined`. */
|
|
125
|
+
export function suggestCommand(input) {
|
|
126
|
+
return nearestName(input, commandNames());
|
|
127
|
+
}
|
|
128
|
+
/** The usage lines and one example of `command`, or `undefined` for a name that is not a command. */
|
|
129
|
+
export function commandHelp(command) {
|
|
130
|
+
const usage = commandUsage(command);
|
|
131
|
+
if (usage.length === 0)
|
|
132
|
+
return undefined;
|
|
133
|
+
const lines = usage.map((l, i) => `${i === 0 ? "usage: " : " "}${l}`);
|
|
134
|
+
const examples = USAGE.slice(USAGE.indexOf("\nExamples:\n") + "\nExamples:\n".length)
|
|
135
|
+
.split("\n")
|
|
136
|
+
.map((l) => l.trim())
|
|
137
|
+
.filter((l) => l.split(" ")[1] === command);
|
|
138
|
+
if (examples[0])
|
|
139
|
+
lines.push(`example: ${examples[0]}`);
|
|
140
|
+
lines.push("run `docsxai --help` for every command and the notes");
|
|
141
|
+
return lines.join("\n") + "\n";
|
|
142
|
+
}
|
|
143
|
+
/** Print the unknown-command message, with a suggestion when one is close. Returns exit code 2. */
|
|
144
|
+
export function unknownCommand(cmd) {
|
|
145
|
+
const near = suggestCommand(cmd);
|
|
146
|
+
const hint = near ? `did you mean \`docsxai ${near}\`?\n` : "";
|
|
147
|
+
process.stderr.write(`unknown command: ${cmd}\n${hint}run \`docsxai --help\` to list the commands\n`);
|
|
148
|
+
return 2;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Handle `help [<command>]` and `<command> --help|-h`. Returns the exit code, or `undefined` when
|
|
152
|
+
* argv is an ordinary command line. `doctor` keeps its own help, so it is left to its handler.
|
|
153
|
+
*/
|
|
154
|
+
export function tryHelp(cmd, rest) {
|
|
155
|
+
if (cmd === undefined) {
|
|
156
|
+
process.stdout.write(startScreen());
|
|
157
|
+
return 0;
|
|
158
|
+
}
|
|
159
|
+
if (cmd === "--help" || cmd === "-h" || (cmd === "help" && rest.length === 0)) {
|
|
160
|
+
process.stdout.write(fullHelp());
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
const asksHelp = rest.some((a) => a === "--help" || a === "-h");
|
|
164
|
+
const target = cmd === "help" ? rest[0] : asksHelp ? cmd : undefined;
|
|
165
|
+
if (target === undefined || (cmd !== "help" && target === "doctor"))
|
|
166
|
+
return undefined;
|
|
167
|
+
// `help calibrate` answers with the help of the command a retired name now runs.
|
|
168
|
+
const retired = findRetired(RETIRED_COMMANDS, target);
|
|
169
|
+
const text = commandHelp(retired ? retired.rewrite([])[0] : target);
|
|
170
|
+
if (text === undefined)
|
|
171
|
+
return unknownCommand(target);
|
|
172
|
+
process.stdout.write(text);
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
package/dist/cli-messages.d.ts
CHANGED
|
@@ -20,3 +20,33 @@ export declare function redactUrl(raw: string): string;
|
|
|
20
20
|
* `fetch` and from a backend can quote the URL they were given, user:password and query included.
|
|
21
21
|
*/
|
|
22
22
|
export declare function redactUrlsIn(text: string): string;
|
|
23
|
+
/** The code of a file-system error the operator fixes: `EACCES`, `EPERM`, `EROFS` or `ENOSPC`. `undefined` for any other error. */
|
|
24
|
+
export declare function fsErrorCode(e: unknown): string | undefined;
|
|
25
|
+
/** The command to run after a file operation failed with `code` at `target` (when known). */
|
|
26
|
+
export declare function fsNext(code: string, target?: string): string;
|
|
27
|
+
/** What went wrong with a file operation and the command to run next, as two parts for callers that print them apart. */
|
|
28
|
+
export interface FsProblem {
|
|
29
|
+
reason: string;
|
|
30
|
+
next: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The problem when `target` (or a directory under it) is a file: names the file, says a directory is
|
|
34
|
+
* needed there, and moves the file aside. `target` is the path the failing call named, when known.
|
|
35
|
+
*/
|
|
36
|
+
export declare function notDirectoryProblem(target?: string): FsProblem;
|
|
37
|
+
/**
|
|
38
|
+
* {@link describeFsError} as a reason and a next step: for `EACCES`, `EPERM`, `EROFS`, `ENOSPC` and
|
|
39
|
+
* `ENOTDIR`. `undefined` for any other error.
|
|
40
|
+
*/
|
|
41
|
+
export declare function describeFsProblem(e: unknown, opts?: {
|
|
42
|
+
creating?: boolean;
|
|
43
|
+
}): FsProblem | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* A line for a file operation that failed with {@link fsErrorCode}, or with `ENOTDIR`: what failed,
|
|
46
|
+
* why, and the next command. `undefined` for any other error, so the caller keeps its own wording.
|
|
47
|
+
* A refused create (`creating`, or a failing call on a path that does not exist yet) names the nearest
|
|
48
|
+
* existing parent in the chmod, because the path that failed is not there to change.
|
|
49
|
+
*/
|
|
50
|
+
export declare function describeFsError(e: unknown, opts?: {
|
|
51
|
+
creating?: boolean;
|
|
52
|
+
}): string | undefined;
|
package/dist/cli-messages.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Shared wording for CLI errors. A failing command says what failed, why, and the next command to
|
|
2
2
|
// run, in that order, on `<command>: ` lines with an indented `next:` line. Usage errors show the
|
|
3
3
|
// failing command's own usage line instead of the whole help text. Leaf: imports only the help text.
|
|
4
|
+
import { existsSync, statSync } from "node:fs";
|
|
5
|
+
import * as path from "node:path";
|
|
4
6
|
import { USAGE } from "./cli-usage.js";
|
|
5
7
|
/** The `Usage:` entries of `docsxai --help`, one whitespace-normalised line per entry. */
|
|
6
8
|
function usageEntries() {
|
|
@@ -85,3 +87,98 @@ export function redactUrl(raw) {
|
|
|
85
87
|
export function redactUrlsIn(text) {
|
|
86
88
|
return text.replace(/\b[a-z][a-z0-9+.-]*:\/\/[^\s"'<>()`]+/gi, (url) => redactUrl(url));
|
|
87
89
|
}
|
|
90
|
+
const FS_REASONS = {
|
|
91
|
+
EACCES: "permission denied",
|
|
92
|
+
EPERM: "operation not permitted",
|
|
93
|
+
EROFS: "read-only file system",
|
|
94
|
+
ENOSPC: "no space left on device",
|
|
95
|
+
};
|
|
96
|
+
/** The code of a file-system error the operator fixes: `EACCES`, `EPERM`, `EROFS` or `ENOSPC`. `undefined` for any other error. */
|
|
97
|
+
export function fsErrorCode(e) {
|
|
98
|
+
const code = e instanceof Error ? e.code : undefined;
|
|
99
|
+
return code !== undefined && code in FS_REASONS ? code : undefined;
|
|
100
|
+
}
|
|
101
|
+
/** The command to run after a file operation failed with `code` at `target` (when known). */
|
|
102
|
+
export function fsNext(code, target) {
|
|
103
|
+
if (code === "ENOSPC")
|
|
104
|
+
return "free disk space, then rerun the command";
|
|
105
|
+
if (code === "EROFS")
|
|
106
|
+
return "pick a directory on a writable disk, then rerun the command";
|
|
107
|
+
return target
|
|
108
|
+
? `chmod -R u+rw ${shellQuote(target)} (or pick another directory), then rerun the command`
|
|
109
|
+
: "make the directory accessible (or pick another one), then rerun the command";
|
|
110
|
+
}
|
|
111
|
+
/** The nearest directory above `target` (or `target` itself) that exists, for a chmod when `target` is yet to be made. */
|
|
112
|
+
function nearestExisting(target) {
|
|
113
|
+
let dir = path.resolve(target);
|
|
114
|
+
while (!existsSync(dir) && path.dirname(dir) !== dir)
|
|
115
|
+
dir = path.dirname(dir);
|
|
116
|
+
return dir;
|
|
117
|
+
}
|
|
118
|
+
/** The nearest path at or above `target` that exists and is not a directory: the file standing where a directory should be. */
|
|
119
|
+
function blockingFile(target) {
|
|
120
|
+
let probe = path.resolve(target);
|
|
121
|
+
for (;;) {
|
|
122
|
+
try {
|
|
123
|
+
return statSync(probe).isDirectory() ? undefined : probe;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
const parent = path.dirname(probe);
|
|
127
|
+
if (parent === probe)
|
|
128
|
+
return undefined;
|
|
129
|
+
probe = parent;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The problem when `target` (or a directory under it) is a file: names the file, says a directory is
|
|
135
|
+
* needed there, and moves the file aside. `target` is the path the failing call named, when known.
|
|
136
|
+
*/
|
|
137
|
+
export function notDirectoryProblem(target) {
|
|
138
|
+
const file = target ? (blockingFile(target) ?? path.resolve(target)) : undefined;
|
|
139
|
+
if (file === undefined) {
|
|
140
|
+
return {
|
|
141
|
+
reason: "a file stands where docsxai needs a directory (ENOTDIR)",
|
|
142
|
+
next: "move the file aside, then rerun the command",
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const shown = redactUrlsIn(file);
|
|
146
|
+
return {
|
|
147
|
+
reason: `${shown} is a file, but docsxai needs a directory there (ENOTDIR)`,
|
|
148
|
+
next: `mv ${shellQuote(file)} ${shellQuote(`${file}.bak`)}, then rerun the command`,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* {@link describeFsError} as a reason and a next step: for `EACCES`, `EPERM`, `EROFS`, `ENOSPC` and
|
|
153
|
+
* `ENOTDIR`. `undefined` for any other error.
|
|
154
|
+
*/
|
|
155
|
+
export function describeFsProblem(e, opts = {}) {
|
|
156
|
+
const target = e instanceof Error ? e.path : undefined;
|
|
157
|
+
const raw = e instanceof Error ? e : undefined;
|
|
158
|
+
// `mkdir -p` over a path that runs through a file fails with EEXIST rather than ENOTDIR.
|
|
159
|
+
if (raw?.code === "ENOTDIR" || (raw?.code === "EEXIST" && raw.syscall === "mkdir")) {
|
|
160
|
+
return notDirectoryProblem(target);
|
|
161
|
+
}
|
|
162
|
+
const code = fsErrorCode(e);
|
|
163
|
+
if (code === undefined)
|
|
164
|
+
return undefined;
|
|
165
|
+
const where = target ? ` ${redactUrlsIn(target)}` : "";
|
|
166
|
+
// A real error carries the failing `syscall`; a path that is not there yet means the denied
|
|
167
|
+
// directory is its parent, which is where the chmod has to go.
|
|
168
|
+
const creating = opts.creating || (e.syscall && !existsSync(target ?? ""));
|
|
169
|
+
const parent = creating && target && (code === "EACCES" || code === "EPERM");
|
|
170
|
+
const next = parent
|
|
171
|
+
? `chmod u+rwx ${shellQuote(nearestExisting(target))} (or pick another directory), then rerun the command`
|
|
172
|
+
: fsNext(code, target);
|
|
173
|
+
return { reason: `cannot access${where} (${code}, ${FS_REASONS[code]})`, next };
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* A line for a file operation that failed with {@link fsErrorCode}, or with `ENOTDIR`: what failed,
|
|
177
|
+
* why, and the next command. `undefined` for any other error, so the caller keeps its own wording.
|
|
178
|
+
* A refused create (`creating`, or a failing call on a path that does not exist yet) names the nearest
|
|
179
|
+
* existing parent in the chmod, because the path that failed is not there to change.
|
|
180
|
+
*/
|
|
181
|
+
export function describeFsError(e, opts = {}) {
|
|
182
|
+
const problem = describeFsProblem(e, opts);
|
|
183
|
+
return problem ? withNext(problem.reason, problem.next) : undefined;
|
|
184
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Imported first by cli.ts so it runs before the modules that refuse an old Node on their own.
|
|
2
|
+
// Exits 1 with one `docsxai:` line; a Node that can run the CLI passes through untouched.
|
|
3
|
+
import { nodeFloorMessage } from "./node-floor.js";
|
|
4
|
+
const tooOld = nodeFloorMessage(process.versions.node);
|
|
5
|
+
if (tooOld) {
|
|
6
|
+
process.stderr.write(tooOld);
|
|
7
|
+
process.exit(1);
|
|
8
|
+
}
|
package/dist/cli-retired.js
CHANGED
|
@@ -9,4 +9,10 @@ export const RETIRED_COMMANDS = {
|
|
|
9
9
|
note: "same flags, `--check` added",
|
|
10
10
|
rewrite: (args) => ["pack", ...args, "--check"],
|
|
11
11
|
},
|
|
12
|
+
calibrate: {
|
|
13
|
+
since: "0.3.0",
|
|
14
|
+
replacement: "`docsxai add-flow`",
|
|
15
|
+
message: "calibrate is deprecated since 0.3.0, use add-flow (calibrate will be removed in 0.5.0)",
|
|
16
|
+
rewrite: (args) => ["add-flow", ...args],
|
|
17
|
+
},
|
|
12
18
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// A flow that gained a `matrix` writes its variants under docs/<flow>/<variant>/, so an
|
|
2
|
+
// annotations.json left at docs/<flow>/ from before is stale. Split out of the `run` handler.
|
|
3
|
+
import { promises as fs } from "node:fs";
|
|
4
|
+
import { resolveWorkspacePath } from "./workspace.js";
|
|
5
|
+
/** One stderr warning per matrix flow in `matrixFlows` that still has a pre-matrix docs/<flow>/annotations.json. */
|
|
6
|
+
export async function warnStaleMatrixOutputs(projectDir, matrixFlows) {
|
|
7
|
+
for (const name of matrixFlows) {
|
|
8
|
+
const stale = resolveWorkspacePath(projectDir, "docs", name, "annotations.json");
|
|
9
|
+
if (await fs.access(stale).then(() => true, () => false)) {
|
|
10
|
+
process.stderr.write(`run: warning: docs/${name}/annotations.json is from before ${name} had a matrix; its variants write to docs/${name}/<variant>/, so remove the old docs/${name}/ outputs\n`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
package/dist/cli-run-summary.js
CHANGED
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
// outputs went, and for each failure the command that digs into it. Success goes to stdout with the
|
|
3
3
|
// progress lines; a failure goes to stderr with the halt messages it summarises.
|
|
4
4
|
import * as path from "node:path";
|
|
5
|
-
import { sanitizeForTerminal, shellQuote } from "./cli-messages.js";
|
|
5
|
+
import { fsNext, sanitizeForTerminal, shellQuote } from "./cli-messages.js";
|
|
6
6
|
/** The command to run for a failure: `diagnose` for a halted step, `doctor` when the browser never started. */
|
|
7
7
|
export function nextForFailure(projectDir, f) {
|
|
8
8
|
const dir = shellQuote(projectDir);
|
|
9
|
-
if (f.
|
|
10
|
-
return
|
|
9
|
+
if (f.next)
|
|
10
|
+
return f.next;
|
|
11
|
+
if (f.step === null) {
|
|
12
|
+
const m = /^cannot write the outputs under .* \((EACCES|EPERM|EROFS|ENOSPC)\)/.exec(f.message);
|
|
13
|
+
return m ? fsNext(m[1], projectDir) : `docsxai doctor ${dir}`;
|
|
14
|
+
}
|
|
11
15
|
const slash = f.flow.indexOf("/");
|
|
12
16
|
const flow = slash === -1 ? f.flow : f.flow.slice(0, slash);
|
|
13
17
|
const variant = slash === -1 ? "" : ` --variant ${shellQuote(f.flow.slice(slash + 1))}`;
|
package/dist/cli-shared.d.ts
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Split argv into positionals and `--flag [value]` / `--flag=value` pairs. A flag in `bool` never
|
|
3
|
+
* takes the next argument as its value. `repeated` lists the flags given more than once and
|
|
4
|
+
* `boolWithValue` the `bool` flags given as `--flag=value`; the caller turns either into a usage error.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseFlags(args: string[], bool?: readonly string[]): {
|
|
2
7
|
positionals: string[];
|
|
3
8
|
flags: Map<string, string | true>;
|
|
9
|
+
repeated: string[];
|
|
10
|
+
boolWithValue: string[];
|
|
4
11
|
};
|
|
12
|
+
/** True when `value` parses as an `http:` or `https:` URL. */
|
|
13
|
+
export declare function isHttpUrl(value: string): boolean;
|
|
14
|
+
/** A URL `docsxai run` can open: http(s), or file: for a local static site. */
|
|
15
|
+
export declare function isRunnableUrl(value: string): boolean;
|
|
16
|
+
/** The first of `names` given as a bare flag (`--flow` with nothing after it), or `undefined`. */
|
|
17
|
+
export declare function flagMissingValue(flags: Map<string, string | true>, names: readonly string[]): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Exit code 2 (after the usage error) when any of `names` was given as a bare flag, else
|
|
20
|
+
* `undefined`. A value flag with nothing after it would otherwise fall back to its default.
|
|
21
|
+
*/
|
|
22
|
+
export declare function bareValueFlagExit(label: string, flags: Map<string, string | true>, names: readonly string[]): number | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Record that `file` declares the flow `name` in `owners`. Returns the error text when an earlier
|
|
25
|
+
* file already declared it: two files with one `name:` write to one `docs/<name>/` directory.
|
|
26
|
+
*/
|
|
27
|
+
export declare function claimFlowName(owners: Map<string, string>, name: string, file: string): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Why `projectDir` cannot be a workspace at all: it does not exist, or it is a file. `undefined` when
|
|
30
|
+
* it is a directory (an empty one included). Commands that write into the workspace call this first,
|
|
31
|
+
* so a mistyped path fails instead of creating the directory.
|
|
32
|
+
*/
|
|
33
|
+
export declare function workspaceDirProblem(projectDir: string): Promise<string | undefined>;
|
|
5
34
|
export declare function listFlowFiles(projectDir: string): Promise<string[]>;
|