@seasb/metafab 0.0.1 → 1.0.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/README.md +46 -1
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +317 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/build.js +70 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/check.d.ts +2 -0
- package/dist/commands/check.js +41 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/create.d.ts +2 -0
- package/dist/commands/create.js +74 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/detach.d.ts +2 -0
- package/dist/commands/detach.js +24 -0
- package/dist/commands/detach.js.map +1 -0
- package/dist/commands/diff.d.ts +2 -0
- package/dist/commands/diff.js +35 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/import.d.ts +2 -0
- package/dist/commands/import.js +107 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +77 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/map.d.ts +2 -0
- package/dist/commands/map.js +43 -0
- package/dist/commands/map.js.map +1 -0
- package/dist/commands/not-implemented.d.ts +2 -0
- package/dist/commands/not-implemented.js +19 -0
- package/dist/commands/not-implemented.js.map +1 -0
- package/dist/commands/pipeline-add.d.ts +2 -0
- package/dist/commands/pipeline-add.js +67 -0
- package/dist/commands/pipeline-add.js.map +1 -0
- package/dist/commands/pipeline-remove.d.ts +2 -0
- package/dist/commands/pipeline-remove.js +44 -0
- package/dist/commands/pipeline-remove.js.map +1 -0
- package/dist/commands/publish.d.ts +2 -0
- package/dist/commands/publish.js +147 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/types.d.ts +45 -0
- package/dist/commands/types.js +2 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/update.d.ts +2 -0
- package/dist/commands/update.js +97 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/core/adopt.d.ts +53 -0
- package/dist/core/adopt.js +676 -0
- package/dist/core/adopt.js.map +1 -0
- package/dist/core/build/agents.d.ts +23 -0
- package/dist/core/build/agents.js +60 -0
- package/dist/core/build/agents.js.map +1 -0
- package/dist/core/build/index.d.ts +4 -0
- package/dist/core/build/index.js +5 -0
- package/dist/core/build/index.js.map +1 -0
- package/dist/core/build/markers.d.ts +34 -0
- package/dist/core/build/markers.js +97 -0
- package/dist/core/build/markers.js.map +1 -0
- package/dist/core/build/plan.d.ts +48 -0
- package/dist/core/build/plan.js +792 -0
- package/dist/core/build/plan.js.map +1 -0
- package/dist/core/build/skill.d.ts +60 -0
- package/dist/core/build/skill.js +275 -0
- package/dist/core/build/skill.js.map +1 -0
- package/dist/core/check/drift.d.ts +13 -0
- package/dist/core/check/drift.js +205 -0
- package/dist/core/check/drift.js.map +1 -0
- package/dist/core/check/index.d.ts +12 -0
- package/dist/core/check/index.js +78 -0
- package/dist/core/check/index.js.map +1 -0
- package/dist/core/check/markers.d.ts +9 -0
- package/dist/core/check/markers.js +220 -0
- package/dist/core/check/markers.js.map +1 -0
- package/dist/core/config/destinations.d.ts +5 -0
- package/dist/core/config/destinations.js +20 -0
- package/dist/core/config/destinations.js.map +1 -0
- package/dist/core/config/load.d.ts +4 -0
- package/dist/core/config/load.js +41 -0
- package/dist/core/config/load.js.map +1 -0
- package/dist/core/config/parse.d.ts +8 -0
- package/dist/core/config/parse.js +198 -0
- package/dist/core/config/parse.js.map +1 -0
- package/dist/core/config/source.d.ts +14 -0
- package/dist/core/config/source.js +44 -0
- package/dist/core/config/source.js.map +1 -0
- package/dist/core/config/types.d.ts +48 -0
- package/dist/core/config/types.js +2 -0
- package/dist/core/config/types.js.map +1 -0
- package/dist/core/config/validate.d.ts +11 -0
- package/dist/core/config/validate.js +351 -0
- package/dist/core/config/validate.js.map +1 -0
- package/dist/core/config/writers.d.ts +14 -0
- package/dist/core/config/writers.js +261 -0
- package/dist/core/config/writers.js.map +1 -0
- package/dist/core/config.d.ts +7 -0
- package/dist/core/config.js +8 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/discovery.d.ts +34 -0
- package/dist/core/discovery.js +272 -0
- package/dist/core/discovery.js.map +1 -0
- package/dist/core/edit/create.d.ts +18 -0
- package/dist/core/edit/create.js +190 -0
- package/dist/core/edit/create.js.map +1 -0
- package/dist/core/edit/document.d.ts +4 -0
- package/dist/core/edit/document.js +16 -0
- package/dist/core/edit/document.js.map +1 -0
- package/dist/core/edit/factory-yaml.d.ts +17 -0
- package/dist/core/edit/factory-yaml.js +211 -0
- package/dist/core/edit/factory-yaml.js.map +1 -0
- package/dist/core/edit/files.d.ts +6 -0
- package/dist/core/edit/files.js +47 -0
- package/dist/core/edit/files.js.map +1 -0
- package/dist/core/edit/index.d.ts +9 -0
- package/dist/core/edit/index.js +10 -0
- package/dist/core/edit/index.js.map +1 -0
- package/dist/core/edit/map.d.ts +24 -0
- package/dist/core/edit/map.js +82 -0
- package/dist/core/edit/map.js.map +1 -0
- package/dist/core/edit/names.d.ts +2 -0
- package/dist/core/edit/names.js +17 -0
- package/dist/core/edit/names.js.map +1 -0
- package/dist/core/edit/paths.d.ts +8 -0
- package/dist/core/edit/paths.js +76 -0
- package/dist/core/edit/paths.js.map +1 -0
- package/dist/core/edit/pipeline.d.ts +19 -0
- package/dist/core/edit/pipeline.js +146 -0
- package/dist/core/edit/pipeline.js.map +1 -0
- package/dist/core/edit/skill.d.ts +1 -0
- package/dist/core/edit/skill.js +10 -0
- package/dist/core/edit/skill.js.map +1 -0
- package/dist/core/factory/discovery.d.ts +9 -0
- package/dist/core/factory/discovery.js +139 -0
- package/dist/core/factory/discovery.js.map +1 -0
- package/dist/core/factory/factory-yaml.d.ts +16 -0
- package/dist/core/factory/factory-yaml.js +375 -0
- package/dist/core/factory/factory-yaml.js.map +1 -0
- package/dist/core/factory/index.d.ts +5 -0
- package/dist/core/factory/index.js +6 -0
- package/dist/core/factory/index.js.map +1 -0
- package/dist/core/factory/lines.d.ts +8 -0
- package/dist/core/factory/lines.js +11 -0
- package/dist/core/factory/lines.js.map +1 -0
- package/dist/core/factory/load.d.ts +4 -0
- package/dist/core/factory/load.js +81 -0
- package/dist/core/factory/load.js.map +1 -0
- package/dist/core/factory/requires.d.ts +9 -0
- package/dist/core/factory/requires.js +123 -0
- package/dist/core/factory/requires.js.map +1 -0
- package/dist/core/factory/types.d.ts +45 -0
- package/dist/core/factory/types.js +2 -0
- package/dist/core/factory/types.js.map +1 -0
- package/dist/core/factory/validate.d.ts +41 -0
- package/dist/core/factory/validate.js +441 -0
- package/dist/core/factory/validate.js.map +1 -0
- package/dist/core/hooks/index.d.ts +8 -0
- package/dist/core/hooks/index.js +15 -0
- package/dist/core/hooks/index.js.map +1 -0
- package/dist/core/hooks/script.d.ts +21 -0
- package/dist/core/hooks/script.js +34 -0
- package/dist/core/hooks/script.js.map +1 -0
- package/dist/core/hooks/sync.d.ts +17 -0
- package/dist/core/hooks/sync.js +262 -0
- package/dist/core/hooks/sync.js.map +1 -0
- package/dist/core/import/conflicts.d.ts +82 -0
- package/dist/core/import/conflicts.js +256 -0
- package/dist/core/import/conflicts.js.map +1 -0
- package/dist/core/import/copy.d.ts +10 -0
- package/dist/core/import/copy.js +76 -0
- package/dist/core/import/copy.js.map +1 -0
- package/dist/core/import/file-tree.d.ts +43 -0
- package/dist/core/import/file-tree.js +107 -0
- package/dist/core/import/file-tree.js.map +1 -0
- package/dist/core/import/index.d.ts +5 -0
- package/dist/core/import/index.js +6 -0
- package/dist/core/import/index.js.map +1 -0
- package/dist/core/import/pipeline-changes.d.ts +8 -0
- package/dist/core/import/pipeline-changes.js +89 -0
- package/dist/core/import/pipeline-changes.js.map +1 -0
- package/dist/core/import/run.d.ts +76 -0
- package/dist/core/import/run.js +258 -0
- package/dist/core/import/run.js.map +1 -0
- package/dist/core/init/gitattributes.d.ts +20 -0
- package/dist/core/init/gitattributes.js +89 -0
- package/dist/core/init/gitattributes.js.map +1 -0
- package/dist/core/init/index.d.ts +4 -0
- package/dist/core/init/index.js +5 -0
- package/dist/core/init/index.js.map +1 -0
- package/dist/core/init/name.d.ts +1 -0
- package/dist/core/init/name.js +4 -0
- package/dist/core/init/name.js.map +1 -0
- package/dist/core/init/run.d.ts +51 -0
- package/dist/core/init/run.js +261 -0
- package/dist/core/init/run.js.map +1 -0
- package/dist/core/init/targets.d.ts +17 -0
- package/dist/core/init/targets.js +87 -0
- package/dist/core/init/targets.js.map +1 -0
- package/dist/core/merge.d.ts +88 -0
- package/dist/core/merge.js +239 -0
- package/dist/core/merge.js.map +1 -0
- package/dist/core/publish/exclude.d.ts +9 -0
- package/dist/core/publish/exclude.js +32 -0
- package/dist/core/publish/exclude.js.map +1 -0
- package/dist/core/publish/git-target.d.ts +32 -0
- package/dist/core/publish/git-target.js +447 -0
- package/dist/core/publish/git-target.js.map +1 -0
- package/dist/core/publish/index.d.ts +10 -0
- package/dist/core/publish/index.js +11 -0
- package/dist/core/publish/index.js.map +1 -0
- package/dist/core/publish/npm-target.d.ts +15 -0
- package/dist/core/publish/npm-target.js +170 -0
- package/dist/core/publish/npm-target.js.map +1 -0
- package/dist/core/publish/package-json.d.ts +31 -0
- package/dist/core/publish/package-json.js +74 -0
- package/dist/core/publish/package-json.js.map +1 -0
- package/dist/core/publish/prepare.d.ts +24 -0
- package/dist/core/publish/prepare.js +93 -0
- package/dist/core/publish/prepare.js.map +1 -0
- package/dist/core/publish/provenance.d.ts +1 -0
- package/dist/core/publish/provenance.js +20 -0
- package/dist/core/publish/provenance.js.map +1 -0
- package/dist/core/publish/publish.d.ts +13 -0
- package/dist/core/publish/publish.js +130 -0
- package/dist/core/publish/publish.js.map +1 -0
- package/dist/core/publish/readme.d.ts +22 -0
- package/dist/core/publish/readme.js +112 -0
- package/dist/core/publish/readme.js.map +1 -0
- package/dist/core/publish/stage.d.ts +19 -0
- package/dist/core/publish/stage.js +333 -0
- package/dist/core/publish/stage.js.map +1 -0
- package/dist/core/publish/types.d.ts +71 -0
- package/dist/core/publish/types.js +2 -0
- package/dist/core/publish/types.js.map +1 -0
- package/dist/core/requires/check.d.ts +15 -0
- package/dist/core/requires/check.js +83 -0
- package/dist/core/requires/check.js.map +1 -0
- package/dist/core/requires/index.d.ts +4 -0
- package/dist/core/requires/index.js +5 -0
- package/dist/core/requires/index.js.map +1 -0
- package/dist/core/requires/inspect.d.ts +44 -0
- package/dist/core/requires/inspect.js +114 -0
- package/dist/core/requires/inspect.js.map +1 -0
- package/dist/core/requires/paths.d.ts +29 -0
- package/dist/core/requires/paths.js +83 -0
- package/dist/core/requires/paths.js.map +1 -0
- package/dist/core/requires/setup.d.ts +37 -0
- package/dist/core/requires/setup.js +147 -0
- package/dist/core/requires/setup.js.map +1 -0
- package/dist/core/setup.d.ts +27 -0
- package/dist/core/setup.js +84 -0
- package/dist/core/setup.js.map +1 -0
- package/dist/core/sources/cache.d.ts +38 -0
- package/dist/core/sources/cache.js +200 -0
- package/dist/core/sources/cache.js.map +1 -0
- package/dist/core/sources/containment.d.ts +21 -0
- package/dist/core/sources/containment.js +50 -0
- package/dist/core/sources/containment.js.map +1 -0
- package/dist/core/sources/env.d.ts +12 -0
- package/dist/core/sources/env.js +28 -0
- package/dist/core/sources/env.js.map +1 -0
- package/dist/core/sources/extract.d.ts +25 -0
- package/dist/core/sources/extract.js +676 -0
- package/dist/core/sources/extract.js.map +1 -0
- package/dist/core/sources/git-process.d.ts +26 -0
- package/dist/core/sources/git-process.js +51 -0
- package/dist/core/sources/git-process.js.map +1 -0
- package/dist/core/sources/git.d.ts +41 -0
- package/dist/core/sources/git.js +511 -0
- package/dist/core/sources/git.js.map +1 -0
- package/dist/core/sources/https.d.ts +21 -0
- package/dist/core/sources/https.js +208 -0
- package/dist/core/sources/https.js.map +1 -0
- package/dist/core/sources/index.d.ts +13 -0
- package/dist/core/sources/index.js +14 -0
- package/dist/core/sources/index.js.map +1 -0
- package/dist/core/sources/npm-cli.d.ts +19 -0
- package/dist/core/sources/npm-cli.js +43 -0
- package/dist/core/sources/npm-cli.js.map +1 -0
- package/dist/core/sources/npm.d.ts +29 -0
- package/dist/core/sources/npm.js +386 -0
- package/dist/core/sources/npm.js.map +1 -0
- package/dist/core/sources/parse.d.ts +32 -0
- package/dist/core/sources/parse.js +389 -0
- package/dist/core/sources/parse.js.map +1 -0
- package/dist/core/sources/path.d.ts +10 -0
- package/dist/core/sources/path.js +316 -0
- package/dist/core/sources/path.js.map +1 -0
- package/dist/core/sources/redact.d.ts +2 -0
- package/dist/core/sources/redact.js +70 -0
- package/dist/core/sources/redact.js.map +1 -0
- package/dist/core/sources/resolve.d.ts +9 -0
- package/dist/core/sources/resolve.js +29 -0
- package/dist/core/sources/resolve.js.map +1 -0
- package/dist/core/sources/types.d.ts +86 -0
- package/dist/core/sources/types.js +2 -0
- package/dist/core/sources/types.js.map +1 -0
- package/dist/core/sources/validate.d.ts +9 -0
- package/dist/core/sources/validate.js +111 -0
- package/dist/core/sources/validate.js.map +1 -0
- package/dist/core/summary.d.ts +77 -0
- package/dist/core/summary.js +405 -0
- package/dist/core/summary.js.map +1 -0
- package/dist/core/update/clashes.d.ts +63 -0
- package/dist/core/update/clashes.js +192 -0
- package/dist/core/update/clashes.js.map +1 -0
- package/dist/core/update/detach.d.ts +21 -0
- package/dist/core/update/detach.js +38 -0
- package/dist/core/update/detach.js.map +1 -0
- package/dist/core/update/diff.d.ts +58 -0
- package/dist/core/update/diff.js +180 -0
- package/dist/core/update/diff.js.map +1 -0
- package/dist/core/update/fetch.d.ts +34 -0
- package/dist/core/update/fetch.js +73 -0
- package/dist/core/update/fetch.js.map +1 -0
- package/dist/core/update/index.d.ts +6 -0
- package/dist/core/update/index.js +7 -0
- package/dist/core/update/index.js.map +1 -0
- package/dist/core/update/restore.d.ts +20 -0
- package/dist/core/update/restore.js +195 -0
- package/dist/core/update/restore.js.map +1 -0
- package/dist/core/update/run.d.ts +113 -0
- package/dist/core/update/run.js +1132 -0
- package/dist/core/update/run.js.map +1 -0
- package/dist/core/update/select.d.ts +39 -0
- package/dist/core/update/select.js +157 -0
- package/dist/core/update/select.js.map +1 -0
- package/dist/core/update/spelling.d.ts +51 -0
- package/dist/core/update/spelling.js +185 -0
- package/dist/core/update/spelling.js.map +1 -0
- package/dist/core/update/trees.d.ts +24 -0
- package/dist/core/update/trees.js +72 -0
- package/dist/core/update/trees.js.map +1 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -0
- package/dist/help.d.ts +46 -0
- package/dist/help.js +103 -0
- package/dist/help.js.map +1 -0
- package/dist/input.d.ts +25 -0
- package/dist/input.js +173 -0
- package/dist/input.js.map +1 -0
- package/dist/output.d.ts +21 -0
- package/dist/output.js +37 -0
- package/dist/output.js.map +1 -0
- package/dist/util/frontmatter.d.ts +12 -0
- package/dist/util/frontmatter.js +58 -0
- package/dist/util/frontmatter.js.map +1 -0
- package/dist/util/fs.d.ts +32 -0
- package/dist/util/fs.js +126 -0
- package/dist/util/fs.js.map +1 -0
- package/dist/util/git-names.d.ts +8 -0
- package/dist/util/git-names.js +25 -0
- package/dist/util/git-names.js.map +1 -0
- package/dist/util/git.d.ts +12 -0
- package/dist/util/git.js +33 -0
- package/dist/util/git.js.map +1 -0
- package/dist/util/suggest.d.ts +6 -0
- package/dist/util/suggest.js +48 -0
- package/dist/util/suggest.js.map +1 -0
- package/dist/util/text.d.ts +8 -0
- package/dist/util/text.js +19 -0
- package/dist/util/text.js.map +1 -0
- package/dist/util/version.d.ts +7 -0
- package/dist/util/version.js +13 -0
- package/dist/util/version.js.map +1 -0
- package/dist/util/yaml.d.ts +30 -0
- package/dist/util/yaml.js +201 -0
- package/dist/util/yaml.js.map +1 -0
- package/package.json +50 -3
- package/resources/metafab-skill/SKILL.md +99 -0
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare enum ExitCode {
|
|
2
|
+
Ok = 0,
|
|
3
|
+
Failed = 1,
|
|
4
|
+
NeedsInput = 2,
|
|
5
|
+
FetchFailed = 3,
|
|
6
|
+
InvalidFab = 4,
|
|
7
|
+
NotOwned = 5
|
|
8
|
+
}
|
|
9
|
+
export interface Problem {
|
|
10
|
+
level: "error" | "warning";
|
|
11
|
+
file: string;
|
|
12
|
+
line?: number;
|
|
13
|
+
message: string;
|
|
14
|
+
fix?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface MetafabErrorOptions {
|
|
17
|
+
exitCode?: ExitCode;
|
|
18
|
+
code?: string;
|
|
19
|
+
problems?: Problem[];
|
|
20
|
+
details?: unknown;
|
|
21
|
+
cause?: unknown;
|
|
22
|
+
}
|
|
23
|
+
export declare class MetafabError extends Error {
|
|
24
|
+
readonly exitCode: ExitCode;
|
|
25
|
+
readonly code: string;
|
|
26
|
+
readonly problems?: Problem[];
|
|
27
|
+
readonly details?: unknown;
|
|
28
|
+
constructor(message: string, options?: MetafabErrorOptions);
|
|
29
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export var ExitCode;
|
|
2
|
+
(function (ExitCode) {
|
|
3
|
+
ExitCode[ExitCode["Ok"] = 0] = "Ok";
|
|
4
|
+
ExitCode[ExitCode["Failed"] = 1] = "Failed";
|
|
5
|
+
ExitCode[ExitCode["NeedsInput"] = 2] = "NeedsInput";
|
|
6
|
+
ExitCode[ExitCode["FetchFailed"] = 3] = "FetchFailed";
|
|
7
|
+
ExitCode[ExitCode["InvalidFab"] = 4] = "InvalidFab";
|
|
8
|
+
ExitCode[ExitCode["NotOwned"] = 5] = "NotOwned";
|
|
9
|
+
})(ExitCode || (ExitCode = {}));
|
|
10
|
+
export class MetafabError extends Error {
|
|
11
|
+
exitCode;
|
|
12
|
+
code;
|
|
13
|
+
problems;
|
|
14
|
+
details;
|
|
15
|
+
constructor(message, options = {}) {
|
|
16
|
+
super(message, options.cause === undefined ? undefined : { cause: options.cause });
|
|
17
|
+
this.name = "MetafabError";
|
|
18
|
+
this.exitCode = options.exitCode ?? ExitCode.Failed;
|
|
19
|
+
this.code = options.code ?? "error";
|
|
20
|
+
this.problems = options.problems;
|
|
21
|
+
this.details = options.details;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,mCAAM,CAAA;IACN,2CAAU,CAAA;IACV,mDAAc,CAAA;IACd,qDAAe,CAAA;IACf,mDAAc,CAAA;IACd,+CAAY,CAAA;AACd,CAAC,EAPW,QAAQ,KAAR,QAAQ,QAOnB;AAkBD,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,QAAQ,CAAW;IACnB,IAAI,CAAS;IACb,QAAQ,CAAa;IACrB,OAAO,CAAW;IAE3B,YAAY,OAAe,EAAE,OAAO,GAAwB,EAAE;QAC5D,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QACnF,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC;QACpD,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC;QACpC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,CAAC;CACF"}
|
package/dist/help.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { CommandDefinition, CommandOptions } from "./commands/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The flags `main` adds to every command's `parseArgs` options. They are also the
|
|
4
|
+
* last lines of every command's help, so the parser and the help cannot drift.
|
|
5
|
+
*/
|
|
6
|
+
export declare const GLOBAL_OPTIONS: CommandOptions;
|
|
7
|
+
export interface HelpArgument {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
optional: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface HelpOption {
|
|
13
|
+
/** The flag as help prints it, such as `--force` or `-h, --help`. */
|
|
14
|
+
flag: string;
|
|
15
|
+
/** The placeholder an option that takes a value prints after its flag. */
|
|
16
|
+
value?: string;
|
|
17
|
+
description: string;
|
|
18
|
+
}
|
|
19
|
+
export interface CommandHelp {
|
|
20
|
+
command: string;
|
|
21
|
+
usage: string;
|
|
22
|
+
description: string;
|
|
23
|
+
arguments: HelpArgument[];
|
|
24
|
+
options: HelpOption[];
|
|
25
|
+
}
|
|
26
|
+
/** A command as the global help and the group help list it. */
|
|
27
|
+
export interface CommandSummary {
|
|
28
|
+
command: string;
|
|
29
|
+
usage: string;
|
|
30
|
+
description: string;
|
|
31
|
+
}
|
|
32
|
+
export interface GroupHelp {
|
|
33
|
+
command: string;
|
|
34
|
+
subcommands: CommandSummary[];
|
|
35
|
+
}
|
|
36
|
+
/** The help of one command: its own options, then `--json` and `-h, --help`. */
|
|
37
|
+
export declare function commandHelp(definition: CommandDefinition): CommandHelp;
|
|
38
|
+
export declare function renderCommandHelp(help: CommandHelp): string;
|
|
39
|
+
/** The commands whose name starts with `<group> `, in definition order. */
|
|
40
|
+
export declare function groupHelp(group: string, definitions: readonly CommandDefinition[]): GroupHelp;
|
|
41
|
+
export declare function renderGroupHelp(help: GroupHelp): string;
|
|
42
|
+
/** The command list `metafab --help` prints, with the same text and data. */
|
|
43
|
+
export declare function globalHelp(commands: readonly CommandDefinition[]): {
|
|
44
|
+
text: string;
|
|
45
|
+
commands: CommandSummary[];
|
|
46
|
+
};
|
package/dist/help.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The flags `main` adds to every command's `parseArgs` options. They are also the
|
|
3
|
+
* last lines of every command's help, so the parser and the help cannot drift.
|
|
4
|
+
*/
|
|
5
|
+
export const GLOBAL_OPTIONS = {
|
|
6
|
+
json: { type: "boolean", description: "Write one JSON object to stdout" },
|
|
7
|
+
help: { type: "boolean", short: "h", description: "Show this help" },
|
|
8
|
+
};
|
|
9
|
+
function flagLabel(name, option) {
|
|
10
|
+
const short = option.short === undefined ? "" : `-${option.short}, `;
|
|
11
|
+
const value = option.value === undefined ? "" : ` ${option.value}`;
|
|
12
|
+
return `${short}--${name}${value}`;
|
|
13
|
+
}
|
|
14
|
+
function helpOption(name, option) {
|
|
15
|
+
return {
|
|
16
|
+
flag: flagLabel(name, option),
|
|
17
|
+
...(option.value === undefined ? {} : { value: option.value }),
|
|
18
|
+
description: option.description,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function helpArgument(argument) {
|
|
22
|
+
return {
|
|
23
|
+
name: argument.name,
|
|
24
|
+
description: argument.description,
|
|
25
|
+
optional: argument.optional === true,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function summary(definition) {
|
|
29
|
+
return { command: definition.name, usage: definition.usage, description: definition.description };
|
|
30
|
+
}
|
|
31
|
+
/** The help of one command: its own options, then `--json` and `-h, --help`. */
|
|
32
|
+
export function commandHelp(definition) {
|
|
33
|
+
return {
|
|
34
|
+
command: definition.name,
|
|
35
|
+
usage: definition.usage,
|
|
36
|
+
description: definition.description,
|
|
37
|
+
arguments: (definition.arguments ?? []).map(helpArgument),
|
|
38
|
+
options: [
|
|
39
|
+
...Object.entries(definition.options ?? {}).map(([name, option]) => helpOption(name, option)),
|
|
40
|
+
...Object.entries(GLOBAL_OPTIONS).map(([name, option]) => helpOption(name, option)),
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function padTo(labels) {
|
|
45
|
+
return labels.length === 0 ? 0 : Math.max(...labels.map((label) => label.length)) + 2;
|
|
46
|
+
}
|
|
47
|
+
export function renderCommandHelp(help) {
|
|
48
|
+
const argumentsText = help.arguments.map((argument) => `<${argument.name}>`);
|
|
49
|
+
const width = padTo([...argumentsText, ...help.options.map((option) => option.flag)]);
|
|
50
|
+
const lines = [`Usage: ${help.usage}`, "", help.description];
|
|
51
|
+
if (help.arguments.length > 0) {
|
|
52
|
+
lines.push("", "Arguments:");
|
|
53
|
+
help.arguments.forEach((argument, index) => {
|
|
54
|
+
lines.push(` ${argumentsText[index].padEnd(width)}${argument.description}`);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
lines.push("", "Options:");
|
|
58
|
+
for (const option of help.options)
|
|
59
|
+
lines.push(` ${option.flag.padEnd(width)}${option.description}`);
|
|
60
|
+
return lines.join("\n");
|
|
61
|
+
}
|
|
62
|
+
/** The commands whose name starts with `<group> `, in definition order. */
|
|
63
|
+
export function groupHelp(group, definitions) {
|
|
64
|
+
return {
|
|
65
|
+
command: group,
|
|
66
|
+
subcommands: definitions
|
|
67
|
+
.filter((definition) => definition.name.startsWith(`${group} `))
|
|
68
|
+
.map(summary),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function renderGroupHelp(help) {
|
|
72
|
+
const width = padTo(help.subcommands.map((subcommand) => subcommand.usage));
|
|
73
|
+
return [
|
|
74
|
+
`Usage: metafab ${help.command} <subcommand>`,
|
|
75
|
+
"",
|
|
76
|
+
"Subcommands:",
|
|
77
|
+
...help.subcommands.map((subcommand) => ` ${subcommand.usage.padEnd(width)}${subcommand.description}`),
|
|
78
|
+
"",
|
|
79
|
+
`Run metafab ${help.command} <subcommand> --help for its options.`,
|
|
80
|
+
].join("\n");
|
|
81
|
+
}
|
|
82
|
+
/** The command list `metafab --help` prints, with the same text and data. */
|
|
83
|
+
export function globalHelp(commands) {
|
|
84
|
+
const width = Math.max(...commands.map((command) => command.name.length)) + 2;
|
|
85
|
+
const labels = [
|
|
86
|
+
...Object.entries(GLOBAL_OPTIONS).map(([name, option]) => helpOption(name, option)),
|
|
87
|
+
{ flag: "--version", description: "Show the metafab version" },
|
|
88
|
+
];
|
|
89
|
+
const optionWidth = Math.max(...labels.map((option) => option.flag.length)) + 1;
|
|
90
|
+
return {
|
|
91
|
+
text: [
|
|
92
|
+
"metafab <command> [options]",
|
|
93
|
+
"",
|
|
94
|
+
"Commands:",
|
|
95
|
+
...commands.map((command) => ` ${command.name.padEnd(width)}${command.description}`),
|
|
96
|
+
"",
|
|
97
|
+
"Options:",
|
|
98
|
+
...labels.map((option) => ` ${option.flag.padEnd(optionWidth)}${option.description}`),
|
|
99
|
+
].join("\n"),
|
|
100
|
+
commands: commands.map(summary),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=help.js.map
|
package/dist/help.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.js","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAmB;IAC5C,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,iCAAiC,EAAE;IACzE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,gBAAgB,EAAE;CACrE,CAAC;AAoCF,SAAS,SAAS,CAAC,IAAY,EAAE,MAA+B;IAC9D,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,KAAK,IAAI,CAAC;IACrE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;IACnE,OAAO,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,EAAE,CAAC;AACrC,CAAC;AAED,SAAS,UAA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C,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;IAC9E,MAAM,MAAM,GAAG;QACb,GAAG,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnF,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,0BAA0B,EAAE;KAC/D,CAAC;IACF,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;IAEhF,OAAO;QACL,IAAI,EAAE;YACJ,6BAA6B;YAC7B,EAAE;YACF,WAAW;YACX,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;YACrF,EAAE;YACF,UAAU;YACV,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;SACvF,CAAC,IAAI,CAAC,IAAI,CAAC;QACZ,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;KAChC,CAAC;AACJ,CAAC"}
|
package/dist/input.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { MetafabError } from "./errors.js";
|
|
2
|
+
export interface RequiredValue {
|
|
3
|
+
name: string;
|
|
4
|
+
flag?: string;
|
|
5
|
+
description: string;
|
|
6
|
+
choices?: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface InputIO {
|
|
9
|
+
tty?: boolean;
|
|
10
|
+
stdin?: NodeJS.ReadableStream;
|
|
11
|
+
stderr?: (text: string) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare class NeedsInput extends MetafabError {
|
|
14
|
+
readonly required: RequiredValue[];
|
|
15
|
+
constructor(required: RequiredValue[]);
|
|
16
|
+
}
|
|
17
|
+
/** Closes every open reader. `main` calls it in `finally`. */
|
|
18
|
+
export declare function closeInput(): void;
|
|
19
|
+
/** @internal Test-only: how many input streams still have an open reader. */
|
|
20
|
+
export declare function openReaderCount(): number;
|
|
21
|
+
export declare function ask(required: RequiredValue, io?: InputIO): Promise<string>;
|
|
22
|
+
export interface ConfirmOptions {
|
|
23
|
+
default?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare function confirm(required: RequiredValue, options?: ConfirmOptions, io?: InputIO): Promise<boolean>;
|
package/dist/input.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
2
|
+
import { ExitCode, MetafabError } from "./errors.js";
|
|
3
|
+
export class NeedsInput extends MetafabError {
|
|
4
|
+
required;
|
|
5
|
+
constructor(required) {
|
|
6
|
+
const names = required.map((value) => value.name).join(", ");
|
|
7
|
+
super(`Required input was unavailable in non-interactive mode: ${names}`, {
|
|
8
|
+
exitCode: ExitCode.NeedsInput,
|
|
9
|
+
code: "needs-input",
|
|
10
|
+
details: { required },
|
|
11
|
+
});
|
|
12
|
+
this.name = "NeedsInput";
|
|
13
|
+
this.required = required;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const readers = new Map();
|
|
17
|
+
/** Input streams whose end a reader has already seen. */
|
|
18
|
+
const endedStreams = new WeakSet();
|
|
19
|
+
/** `readableEnded` is on `stream.Readable`, not on the `NodeJS.ReadableStream` type. */
|
|
20
|
+
function hasEnded(stream) {
|
|
21
|
+
const state = stream;
|
|
22
|
+
return state.readableEnded === true || state.destroyed === true || state.closed === true;
|
|
23
|
+
}
|
|
24
|
+
const closedReader = {
|
|
25
|
+
next: async () => undefined,
|
|
26
|
+
close: () => undefined,
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The one reader for `stdin`, created on first use. Its lines are queued, so a
|
|
30
|
+
* chunk that holds several answers answers several questions. The reader is
|
|
31
|
+
* paused while no question waits, so a child process that later reads standard
|
|
32
|
+
* input is not starved.
|
|
33
|
+
*/
|
|
34
|
+
function readerFor(stdin) {
|
|
35
|
+
const existing = readers.get(stdin);
|
|
36
|
+
if (existing !== undefined)
|
|
37
|
+
return existing;
|
|
38
|
+
// A reader removed at the end of input must not be created again: a stream
|
|
39
|
+
// that already ended never announces the end a second time.
|
|
40
|
+
if (endedStreams.has(stdin) || hasEnded(stdin))
|
|
41
|
+
return closedReader;
|
|
42
|
+
const queued = [];
|
|
43
|
+
const waiting = [];
|
|
44
|
+
let ended = false;
|
|
45
|
+
const rl = createInterface({ input: stdin, crlfDelay: Infinity });
|
|
46
|
+
rl.pause();
|
|
47
|
+
const settle = () => {
|
|
48
|
+
while (waiting.length > 0 && (queued.length > 0 || ended)) {
|
|
49
|
+
waiting.shift()(queued.shift());
|
|
50
|
+
}
|
|
51
|
+
if (ended) {
|
|
52
|
+
// Queued answers still belong to later questions; the reader goes away
|
|
53
|
+
// once nothing is left to hand out.
|
|
54
|
+
if (queued.length === 0 && waiting.length === 0)
|
|
55
|
+
readers.delete(stdin);
|
|
56
|
+
}
|
|
57
|
+
else if (waiting.length === 0) {
|
|
58
|
+
rl.pause();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
rl.on("line", (line) => {
|
|
62
|
+
if (waiting.length > 0)
|
|
63
|
+
waiting.shift()(line);
|
|
64
|
+
else
|
|
65
|
+
queued.push(line);
|
|
66
|
+
settle();
|
|
67
|
+
});
|
|
68
|
+
rl.on("close", () => {
|
|
69
|
+
ended = true;
|
|
70
|
+
if (hasEnded(stdin))
|
|
71
|
+
endedStreams.add(stdin);
|
|
72
|
+
settle();
|
|
73
|
+
});
|
|
74
|
+
// A stream that is destroyed instead of ended (`destroy()` with no `end()`)
|
|
75
|
+
// announces `close` but never `end`, so readline leaves its interface open.
|
|
76
|
+
// Treat that as the end of input too, or the next question waits forever on
|
|
77
|
+
// a dead stream.
|
|
78
|
+
const onStreamClose = () => {
|
|
79
|
+
ended = true;
|
|
80
|
+
endedStreams.add(stdin);
|
|
81
|
+
settle();
|
|
82
|
+
};
|
|
83
|
+
stdin.on("close", onStreamClose);
|
|
84
|
+
const reader = {
|
|
85
|
+
next() {
|
|
86
|
+
return new Promise((resolve) => {
|
|
87
|
+
if (queued.length > 0) {
|
|
88
|
+
resolve(queued.shift());
|
|
89
|
+
settle();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (ended) {
|
|
93
|
+
resolve(undefined);
|
|
94
|
+
settle();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
waiting.push(resolve);
|
|
98
|
+
rl.resume();
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
close() {
|
|
102
|
+
stdin.off("close", onStreamClose);
|
|
103
|
+
rl.close();
|
|
104
|
+
readers.delete(stdin);
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
readers.set(stdin, reader);
|
|
108
|
+
return reader;
|
|
109
|
+
}
|
|
110
|
+
/** Closes every open reader. `main` calls it in `finally`. */
|
|
111
|
+
export function closeInput() {
|
|
112
|
+
for (const reader of [...readers.values()])
|
|
113
|
+
reader.close();
|
|
114
|
+
readers.clear();
|
|
115
|
+
}
|
|
116
|
+
/** @internal Test-only: how many input streams still have an open reader. */
|
|
117
|
+
export function openReaderCount() {
|
|
118
|
+
return readers.size;
|
|
119
|
+
}
|
|
120
|
+
function resolveIO(io = {}) {
|
|
121
|
+
return {
|
|
122
|
+
tty: io.tty ?? process.stdin.isTTY === true,
|
|
123
|
+
stdin: io.stdin ?? process.stdin,
|
|
124
|
+
stderr: io.stderr ??
|
|
125
|
+
((text) => {
|
|
126
|
+
process.stderr.write(text);
|
|
127
|
+
}),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function assertInteractive(io, required) {
|
|
131
|
+
if (!io.tty)
|
|
132
|
+
throw new NeedsInput([required]);
|
|
133
|
+
}
|
|
134
|
+
function promptFor(required) {
|
|
135
|
+
const choices = required.choices === undefined ? "" : ` (${required.choices.join("/")})`;
|
|
136
|
+
return `${required.description}${choices} `;
|
|
137
|
+
}
|
|
138
|
+
async function question(text, required, io) {
|
|
139
|
+
io.stderr(text);
|
|
140
|
+
const answer = await readerFor(io.stdin).next();
|
|
141
|
+
if (answer === undefined)
|
|
142
|
+
throw new NeedsInput([required]);
|
|
143
|
+
return answer.trim();
|
|
144
|
+
}
|
|
145
|
+
export async function ask(required, io) {
|
|
146
|
+
const resolved = resolveIO(io);
|
|
147
|
+
assertInteractive(resolved, required);
|
|
148
|
+
const prompt = promptFor(required);
|
|
149
|
+
for (;;) {
|
|
150
|
+
const answer = await question(prompt, required, resolved);
|
|
151
|
+
if (answer === "" || required.choices === undefined || required.choices.includes(answer)) {
|
|
152
|
+
return answer;
|
|
153
|
+
}
|
|
154
|
+
resolved.stderr(`Choose one of: ${required.choices.join(", ")}\n`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
export async function confirm(required, options = {}, io) {
|
|
158
|
+
const resolved = resolveIO(io);
|
|
159
|
+
assertInteractive(resolved, required);
|
|
160
|
+
const fallback = options.default ?? false;
|
|
161
|
+
const prompt = `${required.description} ${fallback ? "[Y/n]" : "[y/N]"} `;
|
|
162
|
+
for (;;) {
|
|
163
|
+
const answer = (await question(prompt, required, resolved)).toLowerCase();
|
|
164
|
+
if (answer === "")
|
|
165
|
+
return fallback;
|
|
166
|
+
if (answer === "y" || answer === "yes")
|
|
167
|
+
return true;
|
|
168
|
+
if (answer === "n" || answer === "no")
|
|
169
|
+
return false;
|
|
170
|
+
resolved.stderr("Answer yes or no.\n");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=input.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AQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC;IAE1E,SAAS,CAAC;QACR,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAC1E,IAAI,MAAM,KAAK,EAAE;YAAE,OAAO,QAAQ,CAAC;QACnC,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,KAAK;YAAE,OAAO,IAAI,CAAC;QACpD,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,KAAK,CAAC;QACpD,QAAQ,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;AACH,CAAC"}
|
package/dist/output.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ExitCode } from "./errors.js";
|
|
2
|
+
import type { Problem } from "./errors.js";
|
|
3
|
+
export interface CommandResult {
|
|
4
|
+
ok: boolean;
|
|
5
|
+
command: string;
|
|
6
|
+
exitCode: ExitCode;
|
|
7
|
+
problems?: Problem[];
|
|
8
|
+
summary?: string;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface RenderOptions {
|
|
12
|
+
json?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface RenderedResult {
|
|
15
|
+
stdout: string;
|
|
16
|
+
stderr: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function formatProblem(problem: Problem): string;
|
|
19
|
+
export declare function formatProblems(problems: readonly Problem[]): string;
|
|
20
|
+
export declare function summarizeResult(result: CommandResult): string;
|
|
21
|
+
export declare function renderResult(result: CommandResult, options?: RenderOptions): RenderedResult;
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ExitCode } from "./errors.js";
|
|
2
|
+
export function formatProblem(problem) {
|
|
3
|
+
const location = problem.line === undefined ? problem.file : `${problem.file}:${problem.line}`;
|
|
4
|
+
const lines = [`${location}: ${problem.level}: ${problem.message}`];
|
|
5
|
+
if (problem.fix !== undefined)
|
|
6
|
+
lines.push(` fix: ${problem.fix}`);
|
|
7
|
+
return lines.join("\n");
|
|
8
|
+
}
|
|
9
|
+
export function formatProblems(problems) {
|
|
10
|
+
return problems.map(formatProblem).join("\n");
|
|
11
|
+
}
|
|
12
|
+
export function summarizeResult(result) {
|
|
13
|
+
if (result.summary !== undefined && result.summary !== "")
|
|
14
|
+
return result.summary;
|
|
15
|
+
const problems = result.problems ?? [];
|
|
16
|
+
const errors = problems.filter((problem) => problem.level === "error").length;
|
|
17
|
+
const warnings = problems.filter((problem) => problem.level === "warning").length;
|
|
18
|
+
const status = result.ok ? "ok" : "failed";
|
|
19
|
+
const counts = [];
|
|
20
|
+
if (errors > 0)
|
|
21
|
+
counts.push(`${errors} error${errors === 1 ? "" : "s"}`);
|
|
22
|
+
if (warnings > 0)
|
|
23
|
+
counts.push(`${warnings} warning${warnings === 1 ? "" : "s"}`);
|
|
24
|
+
const suffix = counts.length === 0 ? "" : ` (${counts.join(", ")})`;
|
|
25
|
+
return `${result.command}: ${status}${suffix}`;
|
|
26
|
+
}
|
|
27
|
+
export function renderResult(result, options = {}) {
|
|
28
|
+
if (options.json === true) {
|
|
29
|
+
return { stdout: `${JSON.stringify(result, null, 2)}\n`, stderr: "" };
|
|
30
|
+
}
|
|
31
|
+
const summary = summarizeResult(result);
|
|
32
|
+
const stdout = summary.endsWith("\n") ? summary : `${summary}\n`;
|
|
33
|
+
const problems = result.problems ?? [];
|
|
34
|
+
const stderr = problems.length === 0 ? "" : `${formatProblems(problems)}\n`;
|
|
35
|
+
return { stdout, stderr };
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAA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,CAAC,IAAI,CAAC;IAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { YamlDocument, YamlProblem } from "./yaml.js";
|
|
2
|
+
export type FrontmatterResult = ({
|
|
3
|
+
ok: true;
|
|
4
|
+
text: string;
|
|
5
|
+
body: string;
|
|
6
|
+
startLine: number;
|
|
7
|
+
endLine: number;
|
|
8
|
+
} & YamlDocument) | {
|
|
9
|
+
ok: false;
|
|
10
|
+
problems: YamlProblem[];
|
|
11
|
+
};
|
|
12
|
+
export declare function parseFrontmatter(source: string): FrontmatterResult;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { toLF } from "./text.js";
|
|
2
|
+
import { parseYaml } from "./yaml.js";
|
|
3
|
+
const DELIMITER = "---";
|
|
4
|
+
function missingFrontmatter() {
|
|
5
|
+
return {
|
|
6
|
+
ok: false,
|
|
7
|
+
problems: [
|
|
8
|
+
{
|
|
9
|
+
message: "Missing frontmatter: the file must start with '---'",
|
|
10
|
+
line: 1,
|
|
11
|
+
fix: "Add a frontmatter block that starts with --- and ends with ---",
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function unterminatedFrontmatter() {
|
|
17
|
+
return {
|
|
18
|
+
ok: false,
|
|
19
|
+
problems: [
|
|
20
|
+
{
|
|
21
|
+
message: "Unterminated frontmatter: add a closing '---' line",
|
|
22
|
+
line: 1,
|
|
23
|
+
fix: "Add a line that contains only --- after the frontmatter",
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function parseFrontmatter(source) {
|
|
29
|
+
const text = toLF(source);
|
|
30
|
+
if (!text.startsWith(`${DELIMITER}\n`)) {
|
|
31
|
+
return missingFrontmatter();
|
|
32
|
+
}
|
|
33
|
+
const lines = text.split("\n");
|
|
34
|
+
let closing = -1;
|
|
35
|
+
for (let index = 1; index < lines.length; index += 1) {
|
|
36
|
+
if (lines[index] === DELIMITER) {
|
|
37
|
+
closing = index;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (closing === -1) {
|
|
42
|
+
return unterminatedFrontmatter();
|
|
43
|
+
}
|
|
44
|
+
const frontmatter = lines.slice(1, closing).join("\n");
|
|
45
|
+
const body = lines.slice(closing + 1).join("\n");
|
|
46
|
+
const parsed = parseYaml(frontmatter, { lineOffset: 1 });
|
|
47
|
+
if (!parsed.ok) {
|
|
48
|
+
return parsed;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
text: frontmatter,
|
|
52
|
+
body,
|
|
53
|
+
startLine: 1,
|
|
54
|
+
endLine: closing + 1,
|
|
55
|
+
...parsed,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=frontmatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../../src/util/frontmatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAOtC,MAAM,SAAS,GAAG,KAAK,CAAC;AAExB,SAAS,kBAAkB;IACzB,OAAO;QACL,EAAE,EAAE,KAAK;QACT,QAAQ,EAAE;YACR;gBACE,OAAO,EAAE,qDAAqD;gBAC9D,IAAI,EAAE,CAAC;gBACP,GAAG,EAAE,gEAAgE;aACtE;SACF;KACF,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB;IAC9B,OAAO;QACL,EAAE,EAAE,KAAK;QACT,QAAQ,EAAE;YACR;gBACE,OAAO,EAAE,oDAAoD;gBAC7D,IAAI,EAAE,CAAC;gBACP,GAAG,EAAE,yDAAyD;aAC/D;SACF;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,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
|
+
readonly name: string;
|
|
4
|
+
isFile(): boolean;
|
|
5
|
+
isDirectory(): boolean;
|
|
6
|
+
isSymbolicLink(): boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Lists `directory` with `readdir(directory, { withFileTypes: true })`. An
|
|
10
|
+
* entry the filesystem reported with no type (every Dirent predicate false,
|
|
11
|
+
* DT_UNKNOWN) is typed from `lstat` instead. An entry that vanished before the
|
|
12
|
+
* `lstat` (ENOENT) is dropped. Any other `lstat` error (EACCES, EIO, ...) is
|
|
13
|
+
* thrown unchanged, exactly like an error from `readdir` itself, so the
|
|
14
|
+
* caller's existing handling for an unreadable directory applies: it never
|
|
15
|
+
* silently skips an entry it could not classify.
|
|
16
|
+
*/
|
|
17
|
+
export declare function readdirTyped(directory: string): Promise<DirEntry[]>;
|
|
18
|
+
export interface ListOptions {
|
|
19
|
+
ignore?: (relativePath: string, isDirectory: boolean) => boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface TreeDifference {
|
|
22
|
+
path: string;
|
|
23
|
+
kind: "missing" | "extra" | "content" | "mode";
|
|
24
|
+
}
|
|
25
|
+
export declare function toPosixPath(value: string): string;
|
|
26
|
+
export declare function normalizeProblemPath(file: string, root?: string): string;
|
|
27
|
+
export declare function pathExists(target: string): Promise<boolean>;
|
|
28
|
+
export declare function isDirectory(target: string): Promise<boolean>;
|
|
29
|
+
export declare function listFiles(root: string, options?: ListOptions): Promise<string[]>;
|
|
30
|
+
export declare function copyFileWithMode(source: string, destination: string): Promise<void>;
|
|
31
|
+
export declare function copyTree(source: string, destination: string, options?: ListOptions): Promise<void>;
|
|
32
|
+
export declare function compareTrees(expected: string, actual: string, options?: ListOptions): Promise<TreeDifference[]>;
|