@docentjs/cli 0.7.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nitish
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # @docentjs/cli
2
+
3
+ Command line tools for [Docent](https://github.com/FgrReloaded/docentjs) tour files.
4
+
5
+ ```sh
6
+ npx @docentjs/cli validate "tours/*.json"
7
+ ```
8
+
9
+ Or add it to a project and run it from scripts and CI:
10
+
11
+ ```sh
12
+ pnpm add -D @docentjs/cli
13
+ pnpm exec docent validate "tours/*.json"
14
+ ```
15
+
16
+ ## Commands
17
+
18
+ | Command | What it does |
19
+ | --- | --- |
20
+ | `docent validate <files...>` | Check tour files against the schema. Exits 1 when anything is wrong. |
21
+ | `docent schema [file]` | Print the tour JSON Schema, or write it to a file. |
22
+
23
+ Options: `--json` for machine-readable output, `--quiet` to print only problems, `--allow-unknown` to ignore unknown fields.
24
+
25
+ A file may hold one tour or a list of tours.
26
+
27
+ ```
28
+ tours/welcome.json
29
+ ✗ steps[0].arrow: "curvy" is not one of: caret, none, line, … Did you mean "curve"?
30
+ ! steps[1].titel: Unknown field, which Docent will ignore. Did you mean "title"?
31
+ 1 file checked: 1 error, 1 warning.
32
+ ```
33
+
34
+ MIT
package/dist/cli.mjs ADDED
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env node
2
+ import { glob, readFile, writeFile } from "node:fs/promises";
3
+ import { argv, exit, stdout } from "node:process";
4
+ import { formatIssues, tourJsonSchema, validateTour } from "@docentjs/core/validate";
5
+ //#region src/cli.ts
6
+ /**
7
+ * `docent` — check tour files without a browser.
8
+ *
9
+ * Tours are data, so they can be checked in a script, in CI, or by a tool
10
+ * that writes them. This reports the same problems the library reports in
11
+ * development, with the file and the path inside it.
12
+ */
13
+ const HELP = `docent — tools for Docent tour files
14
+
15
+ Usage
16
+ docent validate <files...> Check tour files against the schema
17
+ docent schema [file] Print the tour JSON Schema, or write it to a file
18
+
19
+ Options
20
+ --json Report as JSON, for other tools to read
21
+ --quiet Print only problems, not the summary
22
+ --allow-unknown Ignore unknown fields instead of warning about them
23
+ -h, --help Show this message
24
+
25
+ Examples
26
+ docent validate tours/*.json
27
+ docent validate tours/welcome.tour.json --json
28
+ docent schema tour-schema.json
29
+ `;
30
+ async function main(args) {
31
+ const flags = new Set(args.filter((a) => a.startsWith("-")));
32
+ const [command, ...paths] = args.filter((a) => !a.startsWith("-"));
33
+ if (flags.has("-h") || flags.has("--help") || command === void 0 || command === "help") {
34
+ stdout.write(HELP);
35
+ return command === void 0 ? 1 : 0;
36
+ }
37
+ if (command === "schema") {
38
+ const json = `${JSON.stringify(tourJsonSchema(), null, 2)}\n`;
39
+ if (paths[0]) {
40
+ await writeFile(paths[0], json);
41
+ stdout.write(`Wrote ${paths[0]}\n`);
42
+ } else stdout.write(json);
43
+ return 0;
44
+ }
45
+ if (command !== "validate") {
46
+ stdout.write(`Unknown command "${command}".\n\n${HELP}`);
47
+ return 1;
48
+ }
49
+ if (paths.length === 0) {
50
+ stdout.write("Give at least one file to check, for example: docent validate tours/*.json\n");
51
+ return 1;
52
+ }
53
+ const files = await expand(paths);
54
+ if (files.length === 0) {
55
+ stdout.write(`No files matched ${paths.join(", ")}\n`);
56
+ return 1;
57
+ }
58
+ const reports = [];
59
+ for (const file of files) reports.push(await checkFile(file, { unknownFields: !flags.has("--allow-unknown") }));
60
+ if (flags.has("--json")) stdout.write(`${JSON.stringify(reports, null, 2)}\n`);
61
+ else stdout.write(report(reports, flags.has("--quiet")));
62
+ return reports.some((r) => r.failed !== void 0 || r.issues.some((i) => i.level === "error")) ? 1 : 0;
63
+ }
64
+ /** Expand any patterns, so quoted globs work the same in every shell. */
65
+ async function expand(paths) {
66
+ const out = [];
67
+ for (const path of paths) {
68
+ if (!/[*?[]/.test(path)) {
69
+ out.push(path);
70
+ continue;
71
+ }
72
+ for await (const match of glob(path)) out.push(match);
73
+ }
74
+ return [...new Set(out)].sort();
75
+ }
76
+ /** One file, which may hold a single tour or a list of them. */
77
+ async function checkFile(file, options) {
78
+ let text;
79
+ try {
80
+ text = await readFile(file, "utf8");
81
+ } catch {
82
+ return {
83
+ file,
84
+ issues: [],
85
+ failed: "Could not read this file."
86
+ };
87
+ }
88
+ let data;
89
+ try {
90
+ data = JSON.parse(text);
91
+ } catch (error) {
92
+ return {
93
+ file,
94
+ issues: [],
95
+ failed: `Not valid JSON: ${error.message}`
96
+ };
97
+ }
98
+ return {
99
+ file,
100
+ issues: (Array.isArray(data) ? data : [data]).flatMap((tour, index) => {
101
+ const found = validateTour(tour, options);
102
+ if (!Array.isArray(data)) return found;
103
+ return found.map((issue) => ({
104
+ ...issue,
105
+ path: `[${index}]${issue.path ? `.${issue.path}` : ""}`
106
+ }));
107
+ })
108
+ };
109
+ }
110
+ function report(reports, quiet) {
111
+ const lines = [];
112
+ let errors = 0;
113
+ let warnings = 0;
114
+ for (const r of reports) {
115
+ if (r.failed) {
116
+ errors++;
117
+ lines.push(`${r.file}\n✗ ${r.failed}\n`);
118
+ continue;
119
+ }
120
+ errors += r.issues.filter((i) => i.level === "error").length;
121
+ warnings += r.issues.filter((i) => i.level === "warning").length;
122
+ if (r.issues.length > 0) lines.push(`${r.file}\n${formatIssues(r.issues)}\n`);
123
+ }
124
+ if (!quiet) {
125
+ const files = `${reports.length} file${reports.length === 1 ? "" : "s"}`;
126
+ lines.push(errors === 0 && warnings === 0 ? `${files} checked, no problems found.` : `${files} checked: ${errors} error${errors === 1 ? "" : "s"}, ${warnings} warning${warnings === 1 ? "" : "s"}.`);
127
+ }
128
+ return `${lines.join("\n")}\n`;
129
+ }
130
+ exit(await main(argv.slice(2)));
131
+ //#endregion
132
+ export {};
133
+
134
+ //# sourceMappingURL=cli.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.mjs","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * `docent` — check tour files without a browser.\n *\n * Tours are data, so they can be checked in a script, in CI, or by a tool\n * that writes them. This reports the same problems the library reports in\n * development, with the file and the path inside it.\n */\n\nimport { glob, readFile, writeFile } from 'node:fs/promises'\nimport { argv, exit, stdout } from 'node:process'\nimport { formatIssues, type TourIssue, tourJsonSchema, validateTour } from '@docentjs/core/validate'\n\nconst HELP = `docent — tools for Docent tour files\n\nUsage\n docent validate <files...> Check tour files against the schema\n docent schema [file] Print the tour JSON Schema, or write it to a file\n\nOptions\n --json Report as JSON, for other tools to read\n --quiet Print only problems, not the summary\n --allow-unknown Ignore unknown fields instead of warning about them\n -h, --help Show this message\n\nExamples\n docent validate tours/*.json\n docent validate tours/welcome.tour.json --json\n docent schema tour-schema.json\n`\n\ninterface FileReport {\n file: string\n issues: TourIssue[]\n /** Set when the file could not be read or parsed. */\n failed?: string\n}\n\nasync function main(args: string[]): Promise<number> {\n const flags = new Set(args.filter((a) => a.startsWith('-')))\n const rest = args.filter((a) => !a.startsWith('-'))\n const [command, ...paths] = rest\n\n if (flags.has('-h') || flags.has('--help') || command === undefined || command === 'help') {\n stdout.write(HELP)\n return command === undefined ? 1 : 0\n }\n\n if (command === 'schema') {\n const json = `${JSON.stringify(tourJsonSchema(), null, 2)}\\n`\n if (paths[0]) {\n await writeFile(paths[0], json)\n stdout.write(`Wrote ${paths[0]}\\n`)\n } else {\n stdout.write(json)\n }\n return 0\n }\n\n if (command !== 'validate') {\n stdout.write(`Unknown command \"${command}\".\\n\\n${HELP}`)\n return 1\n }\n\n if (paths.length === 0) {\n stdout.write('Give at least one file to check, for example: docent validate tours/*.json\\n')\n return 1\n }\n\n const files = await expand(paths)\n if (files.length === 0) {\n stdout.write(`No files matched ${paths.join(', ')}\\n`)\n return 1\n }\n\n const reports: FileReport[] = []\n for (const file of files) {\n reports.push(await checkFile(file, { unknownFields: !flags.has('--allow-unknown') }))\n }\n\n if (flags.has('--json')) {\n stdout.write(`${JSON.stringify(reports, null, 2)}\\n`)\n } else {\n stdout.write(report(reports, flags.has('--quiet')))\n }\n\n const bad = reports.some(\n (r) => r.failed !== undefined || r.issues.some((i) => i.level === 'error'),\n )\n return bad ? 1 : 0\n}\n\n/** Expand any patterns, so quoted globs work the same in every shell. */\nasync function expand(paths: string[]): Promise<string[]> {\n const out: string[] = []\n for (const path of paths) {\n if (!/[*?[]/.test(path)) {\n out.push(path)\n continue\n }\n for await (const match of glob(path)) out.push(match)\n }\n return [...new Set(out)].sort()\n}\n\n/** One file, which may hold a single tour or a list of them. */\nasync function checkFile(file: string, options: { unknownFields: boolean }): Promise<FileReport> {\n let text: string\n try {\n text = await readFile(file, 'utf8')\n } catch {\n return { file, issues: [], failed: 'Could not read this file.' }\n }\n let data: unknown\n try {\n data = JSON.parse(text)\n } catch (error) {\n return { file, issues: [], failed: `Not valid JSON: ${(error as Error).message}` }\n }\n const tours = Array.isArray(data) ? data : [data]\n const issues = tours.flatMap((tour, index) => {\n const found = validateTour(tour, options)\n if (!Array.isArray(data)) return found\n // Say which tour in the list, since the file holds several.\n return found.map((issue) => ({\n ...issue,\n path: `[${index}]${issue.path ? `.${issue.path}` : ''}`,\n }))\n })\n return { file, issues }\n}\n\nfunction report(reports: FileReport[], quiet: boolean): string {\n const lines: string[] = []\n let errors = 0\n let warnings = 0\n for (const r of reports) {\n if (r.failed) {\n errors++\n lines.push(`${r.file}\\n✗ ${r.failed}\\n`)\n continue\n }\n errors += r.issues.filter((i) => i.level === 'error').length\n warnings += r.issues.filter((i) => i.level === 'warning').length\n if (r.issues.length > 0) lines.push(`${r.file}\\n${formatIssues(r.issues)}\\n`)\n }\n if (!quiet) {\n const files = `${reports.length} file${reports.length === 1 ? '' : 's'}`\n lines.push(\n errors === 0 && warnings === 0\n ? `${files} checked, no problems found.`\n : `${files} checked: ${errors} error${errors === 1 ? '' : 's'}, ${warnings} warning${warnings === 1 ? '' : 's'}.`,\n )\n }\n return `${lines.join('\\n')}\\n`\n}\n\nexit(await main(argv.slice(2)))\n"],"mappings":";;;;;;;;;;;;AAaA,MAAM,OAAO;;;;;;;;;;;;;;;;;AAyBb,eAAe,KAAK,MAAiC;CACnD,MAAM,QAAQ,IAAI,IAAI,KAAK,QAAQ,MAAM,EAAE,WAAW,GAAG,CAAC,CAAC;CAE3D,MAAM,CAAC,SAAS,GAAG,SADN,KAAK,QAAQ,MAAM,CAAC,EAAE,WAAW,GAAG,CAClB;CAE/B,IAAI,MAAM,IAAI,IAAI,KAAK,MAAM,IAAI,QAAQ,KAAK,YAAY,KAAA,KAAa,YAAY,QAAQ;EACzF,OAAO,MAAM,IAAI;EACjB,OAAO,YAAY,KAAA,IAAY,IAAI;CACrC;CAEA,IAAI,YAAY,UAAU;EACxB,MAAM,OAAO,GAAG,KAAK,UAAU,eAAe,GAAG,MAAM,CAAC,EAAE;EAC1D,IAAI,MAAM,IAAI;GACZ,MAAM,UAAU,MAAM,IAAI,IA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AAa,IAAI,KAAK,IAAI,EACnH;CACF;CACA,OAAO,GAAG,MAAM,KAAK,IAAI,EAAE;AAC7B;AAEA,KAAK,MAAM,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@docentjs/cli",
3
+ "version": "0.7.0",
4
+ "description": "Command line tools for Docent: check tour files and print the tour JSON Schema.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/FgrReloaded/docentjs.git",
9
+ "directory": "packages/cli"
10
+ },
11
+ "homepage": "https://github.com/FgrReloaded/docentjs/tree/main/packages/cli#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/FgrReloaded/docentjs/issues"
14
+ },
15
+ "keywords": [
16
+ "product-tour",
17
+ "guided-tour",
18
+ "onboarding",
19
+ "cli",
20
+ "docent"
21
+ ],
22
+ "type": "module",
23
+ "bin": {
24
+ "docent": "./dist/cli.mjs"
25
+ },
26
+ "exports": {
27
+ "./package.json": "./package.json"
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "dependencies": {
33
+ "@docentjs/core": "0.7.0"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^24.10.1",
37
+ "tsdown": "^0.23.0",
38
+ "typescript": "^5.9.3"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "engines": {
44
+ "node": ">=22.18.0"
45
+ },
46
+ "scripts": {
47
+ "build": "tsdown",
48
+ "dev": "tsdown --watch",
49
+ "typecheck": "tsc --noEmit",
50
+ "clean": "rm -rf dist .turbo"
51
+ }
52
+ }