@gnawbit/tabretake 0.0.0-stage → 0.4.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.
@@ -0,0 +1,18 @@
1
+ import { inspectConfig, readConfig } from "./lib/config.mjs";
2
+ import { parseCommand } from "./lib/options.mjs";
3
+ import { schemaVersion, version } from "./lib/metadata.mjs";
4
+
5
+ export async function validate(argv) {
6
+ const { values } = parseCommand("validate", argv);
7
+ if (!values.config) {
8
+ const error = new Error("Provide --config story.json");
9
+ error.code = "CONFIG_REQUIRED";
10
+ throw error;
11
+ }
12
+ const result = { schemaVersion, version, ...inspectConfig(await readConfig(values.config)) };
13
+ if (values.json) console.log(JSON.stringify(result));
14
+ else if (result.ok) console.log(`Valid ${result.kind} config.`);
15
+ else for (const error of result.errors) console.error(`${error.path}: ${error.message}\n ${error.hint}`);
16
+ if (!result.ok) process.exitCode = 1;
17
+ return result;
18
+ }