@citemap/cli 0.3.4 → 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.
package/README.md CHANGED
@@ -102,3 +102,14 @@ If a citemap claims a level via `citemapLevel` that doesn't match actual content
102
102
  ## License
103
103
 
104
104
  MIT
105
+
106
+
107
+ ## 0.4.1
108
+
109
+ - The `citemap` command runs the current build (0.4.0's bin still loaded an old 0.3.x file, so URLs read as "File not found").
110
+
111
+ ## 0.4.0
112
+
113
+ - `citemap validate <url>` reads a citemap over https.
114
+ - Content files: when a citemap lists `contentFiles`, the CLI reads each one (https only, up to 50, 4 MB each), checks it, and checks the joined record (duplicate `@id`s, relationship endpoints). `--no-follow` skips them.
115
+ - v3.3 / v3.4 files are checked against the spec's structural rules instead of the strict v3.0 schema.
package/bin/citemap.js CHANGED
@@ -1,2 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import('../dist/index.js');
2
+ // tsup writes ESM as dist/index.mjs (no "type": "module" here); 0.4.0 still
3
+ // pointed at a stale dist/index.js from 0.3.x.
4
+ import('../dist/index.mjs');
package/dist/index.mjs CHANGED
@@ -3,8 +3,8 @@
3
3
  // src/index.ts
4
4
  import { readFileSync } from "fs";
5
5
  import { resolve } from "path";
6
- import { validate, validateAndDiagnose } from "@citemap/validator";
7
- var VERSION = "0.3.3";
6
+ import { validate, validateAndDiagnose, validateContentFile, checkAcrossFiles } from "@citemap/validator";
7
+ var VERSION = "0.4.1";
8
8
  var colors = {
9
9
  reset: "\x1B[0m",
10
10
  bright: "\x1B[1m",
@@ -21,13 +21,18 @@ function printUsage() {
21
21
  ${colors.bright}citemap${colors.reset} \u2014 Validate citemap.json files for AI accuracy
22
22
 
23
23
  ${colors.bright}Usage:${colors.reset}
24
- citemap validate <path> Validate a citemap.json file
25
- citemap diagnose <path> Run detailed analysis with scores and level assessment
24
+ citemap validate <path|url> Validate a citemap.json file or URL
25
+ citemap diagnose <path|url> Run detailed analysis with scores and level assessment
26
+
27
+ ${colors.bright}Options:${colors.reset}
28
+ --no-follow Don't read the content files a citemap lists in contentFiles
29
+ (followed by default: https only, up to 50 files)
26
30
  citemap --help Show this help message
27
31
  citemap --version Show version number
28
32
 
29
33
  ${colors.bright}Examples:${colors.reset}
30
34
  citemap validate ./citemap.json
35
+ citemap validate https://example.com/citemap.json
31
36
  citemap diagnose .well-known/citemap.json
32
37
 
33
38
  ${colors.bright}Learn more:${colors.reset}
@@ -102,7 +107,7 @@ ${statusIcon} ${statusText} citemap.json ${colors.dim}v${result.version}${color
102
107
  console.log(`${colors.green}All validations passed.${colors.reset}
103
108
  `);
104
109
  }
105
- process.exit(result.valid ? 0 : 1);
110
+ return result.valid;
106
111
  }
107
112
  function formatDiagnosticOutput(data) {
108
113
  const result = validateAndDiagnose(data);
@@ -172,7 +177,60 @@ ${statusIcon} ${statusText} citemap.json ${colors.dim}v${result.version}${color
172
177
  console.log(`${colors.red}\u2717 Validation failed. See errors above.${colors.reset}
173
178
  `);
174
179
  }
175
- process.exit(result.valid ? 0 : 1);
180
+ return result.valid;
181
+ }
182
+ var MAX_FILES = 50;
183
+ var MAX_BYTES = 4 * 1024 * 1024;
184
+ async function fetchJSON(url) {
185
+ const ctrl = new AbortController();
186
+ const t = setTimeout(() => ctrl.abort(), 15e3);
187
+ try {
188
+ const res = await fetch(url, { signal: ctrl.signal, headers: { Accept: "application/json", "User-Agent": `citemap-cli/${VERSION}` } });
189
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
190
+ const text = await res.text();
191
+ if (text.length > MAX_BYTES) throw new Error("larger than 4 MB");
192
+ return JSON.parse(text);
193
+ } finally {
194
+ clearTimeout(t);
195
+ }
196
+ }
197
+ async function checkContentFiles(main2) {
198
+ const refs = Array.isArray(main2?.contentFiles) ? main2.contentFiles : [];
199
+ if (!refs.length) return true;
200
+ console.log(`${colors.bright}Content files${colors.reset} ${colors.dim}(${refs.length} listed)${colors.reset}`);
201
+ const read = [];
202
+ let ok = true;
203
+ for (const ref of refs.slice(0, MAX_FILES)) {
204
+ const label = `${ref?.type ?? "?"}${ref?.year ? " " + ref.year : ""}${ref?.category ? " \xB7 " + ref.category : ""}`;
205
+ if (typeof ref?.url !== "string" || !/^https:\/\//i.test(ref.url)) {
206
+ console.log(` ${colors.red}\u2717${colors.reset} ${label}: url isn't https`);
207
+ ok = false;
208
+ continue;
209
+ }
210
+ try {
211
+ const data = await fetchJSON(ref.url);
212
+ const r = validateContentFile(data, ref);
213
+ read.push({ url: ref.url, data });
214
+ if (r.valid) console.log(` ${colors.green}\u2713${colors.reset} ${label} ${colors.dim}(${r.count} item${r.count === 1 ? "" : "s"})${colors.reset}`);
215
+ else {
216
+ ok = false;
217
+ console.log(` ${colors.red}\u2717${colors.reset} ${label}: ${r.errors.map((e) => e.message).join("; ")}`);
218
+ }
219
+ for (const w of r.warnings) console.log(` ${colors.yellow}\u26A0${colors.reset} ${w.message}`);
220
+ } catch (e) {
221
+ ok = false;
222
+ console.log(` ${colors.red}\u2717${colors.reset} ${label}: couldn't read ${ref.url} (${e instanceof Error ? e.message : String(e)})`);
223
+ }
224
+ }
225
+ if (refs.length > MAX_FILES) console.log(` ${colors.yellow}\u26A0${colors.reset} ${refs.length - MAX_FILES} more listed; only ${MAX_FILES} read`);
226
+ const across = checkAcrossFiles(main2, read);
227
+ for (const e of across.errors) {
228
+ ok = false;
229
+ console.log(` ${colors.red}\u2717${colors.reset} ${e.message}`);
230
+ }
231
+ for (const w of across.warnings) console.log(` ${colors.yellow}\u26A0${colors.reset} ${w.message}`);
232
+ console.log("");
233
+ return ok;
176
234
  }
177
235
  async function main() {
178
236
  const args = process.argv.slice(2);
@@ -185,7 +243,8 @@ async function main() {
185
243
  process.exit(0);
186
244
  }
187
245
  const command = args[0];
188
- const filePath = args[1];
246
+ const follow = !args.includes("--no-follow");
247
+ const filePath = args.slice(1).find((a) => !a.startsWith("--"));
189
248
  if (!filePath) {
190
249
  console.error(`${colors.red}Error: File path required${colors.reset}
191
250
  `);
@@ -199,13 +258,27 @@ async function main() {
199
258
  `);
200
259
  process.exit(1);
201
260
  }
202
- const data = loadJSON(filePath);
203
- if (command === "validate") {
204
- const result = validate(data);
205
- formatValidationOutput(result);
206
- } else if (command === "diagnose") {
207
- formatDiagnosticOutput(data);
261
+ let data;
262
+ if (/^https?:\/\//i.test(filePath)) {
263
+ try {
264
+ data = await fetchJSON(filePath);
265
+ } catch (e) {
266
+ console.error(`${colors.red}\u2717 Couldn't read ${filePath}${colors.reset}: ${e instanceof Error ? e.message : String(e)}`);
267
+ process.exit(1);
268
+ }
269
+ } else data = loadJSON(filePath);
270
+ if (data?.["@type"] === "CitemapContentFile") {
271
+ const r = validateContentFile(data);
272
+ console.log(`
273
+ ${r.valid ? colors.green + "\u2713 Valid" : colors.red + "\u2717 Invalid"}${colors.reset} content file ${colors.dim}(${r.contentType ?? "?"}, ${r.count} items)${colors.reset}`);
274
+ for (const e of r.errors) console.log(` ${colors.red}\u2717${colors.reset} ${e.path}: ${e.message}`);
275
+ for (const w of r.warnings) console.log(` ${colors.yellow}\u26A0${colors.reset} ${w.path}: ${w.message}`);
276
+ console.log("");
277
+ process.exit(r.valid ? 0 : 1);
208
278
  }
279
+ const valid = command === "validate" ? formatValidationOutput(validate(data)) : formatDiagnosticOutput(data);
280
+ const filesOk = follow ? await checkContentFiles(data) : true;
281
+ process.exit(valid && filesOk ? 0 : 1);
209
282
  }
210
283
  main().catch((error) => {
211
284
  console.error(`${colors.red}Fatal error:${colors.reset}`, error instanceof Error ? error.message : String(error));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@citemap/cli",
3
- "version": "0.3.4",
3
+ "version": "0.4.1",
4
4
  "description": "Command-line tool for validating citemap.json files",
5
5
  "bin": {
6
6
  "citemap": "bin/citemap.js"
@@ -10,7 +10,7 @@
10
10
  "bin"
11
11
  ],
12
12
  "scripts": {
13
- "build": "tsup src/index.ts --format esm --no-dts --out-dir dist",
13
+ "build": "tsup src/index.ts --format esm --no-dts --out-dir dist --clean",
14
14
  "dev": "node --loader ts-node/esm src/index.ts",
15
15
  "prepublishOnly": "npm run build"
16
16
  },
@@ -24,13 +24,13 @@
24
24
  "license": "MIT",
25
25
  "repository": {
26
26
  "type": "git",
27
- "url": "https://github.com/citemaps/citemap"
27
+ "url": "git+https://github.com/citemaps/citemap.git"
28
28
  },
29
29
  "engines": {
30
30
  "node": ">=18.0.0"
31
31
  },
32
32
  "dependencies": {
33
- "@citemap/validator": "^0.3.1"
33
+ "@citemap/validator": "^0.4.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^25.5.0",
package/dist/index.js DELETED
@@ -1,213 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/index.ts
4
- import { readFileSync } from "fs";
5
- import { resolve } from "path";
6
- import { validate, validateAndDiagnose } from "@citemap/validator";
7
- var VERSION = "0.3.3";
8
- var colors = {
9
- reset: "\x1B[0m",
10
- bright: "\x1B[1m",
11
- dim: "\x1B[2m",
12
- red: "\x1B[31m",
13
- green: "\x1B[32m",
14
- yellow: "\x1B[33m",
15
- blue: "\x1B[34m",
16
- magenta: "\x1B[35m",
17
- cyan: "\x1B[36m"
18
- };
19
- function printUsage() {
20
- console.log(`
21
- ${colors.bright}citemap${colors.reset} \u2014 Validate citemap.json files for AI accuracy
22
-
23
- ${colors.bright}Usage:${colors.reset}
24
- citemap validate <path> Validate a citemap.json file
25
- citemap diagnose <path> Run detailed analysis with scores and level assessment
26
- citemap --help Show this help message
27
- citemap --version Show version number
28
-
29
- ${colors.bright}Examples:${colors.reset}
30
- citemap validate ./citemap.json
31
- citemap diagnose .well-known/citemap.json
32
-
33
- ${colors.bright}Learn more:${colors.reset}
34
- https://github.com/citemaps/citemap
35
- `);
36
- }
37
- function printVersion() {
38
- console.log(`citemap v${VERSION}`);
39
- }
40
- function loadJSON(filePath) {
41
- try {
42
- const absolutePath = resolve(filePath);
43
- const content = readFileSync(absolutePath, "utf-8");
44
- return JSON.parse(content);
45
- } catch (error) {
46
- if (error instanceof SyntaxError) {
47
- console.error(`${colors.red}\u2717 Invalid JSON${colors.reset}: ${error.message}`);
48
- process.exit(1);
49
- }
50
- if (error instanceof Error && "code" in error && error.code === "ENOENT") {
51
- console.error(`${colors.red}\u2717 File not found${colors.reset}: ${filePath}`);
52
- process.exit(1);
53
- }
54
- console.error(`${colors.red}\u2717 Error reading file${colors.reset}: ${error instanceof Error ? error.message : String(error)}`);
55
- process.exit(1);
56
- }
57
- }
58
- function getProgressBar(percentage, width = 20) {
59
- const filled = Math.round(percentage / 100 * width);
60
- const empty = width - filled;
61
- return `[${colors.green}${"\u2588".repeat(filled)}${colors.reset}${colors.dim}${"\u2591".repeat(empty)}${colors.reset}]`;
62
- }
63
- function scoreColor(score) {
64
- if (score >= 80) return colors.green;
65
- if (score >= 60) return colors.yellow;
66
- return colors.red;
67
- }
68
- function formatValidationOutput(result) {
69
- const statusIcon = result.valid ? `${colors.green}\u2713${colors.reset}` : `${colors.red}\u2717${colors.reset}`;
70
- const statusText = result.valid ? `${colors.green}Valid${colors.reset}` : `${colors.red}Invalid${colors.reset}`;
71
- console.log(`
72
- ${statusIcon} ${statusText} citemap.json ${colors.dim}v${result.version}${colors.reset}`);
73
- const lvl = result.level;
74
- const levelColor = lvl.current === 3 ? colors.green : lvl.current === 2 ? colors.cyan : colors.yellow;
75
- console.log(` ${levelColor}${colors.bright}${lvl.badge}${colors.reset}`);
76
- if (!lvl.claimAccurate && lvl.claimed != null) {
77
- console.log(` ${colors.yellow}\u26A0 Claimed Level ${lvl.claimed}, actual Level ${lvl.current}${colors.reset}`);
78
- }
79
- console.log();
80
- if (result.errors.length > 0) {
81
- console.log(`${colors.red}${colors.bright}Errors (${result.errors.length}):${colors.reset}`);
82
- result.errors.forEach((error) => {
83
- console.log(` ${colors.red}\u2022${colors.reset} ${error.path}: ${error.message}`);
84
- });
85
- console.log();
86
- }
87
- if (result.warnings.length > 0) {
88
- console.log(`${colors.yellow}${colors.bright}Warnings (${result.warnings.length}):${colors.reset}`);
89
- result.warnings.forEach((warning) => {
90
- console.log(` ${colors.yellow}\u2022${colors.reset} ${warning.path}: ${warning.message}`);
91
- console.log(` ${colors.dim}\u2192 ${warning.suggestion}${colors.reset}`);
92
- });
93
- console.log();
94
- }
95
- const s = result.score;
96
- console.log(`${colors.bright}Quality Score: ${scoreColor(s.overall)}${s.overall}%${colors.reset}`);
97
- console.log(` Completeness ${scoreColor(s.completeness)}${s.completeness.toString().padStart(3)}%${colors.reset} ${getProgressBar(s.completeness)}`);
98
- console.log(` Modules ${scoreColor(s.modules)}${s.modules.toString().padStart(3)}%${colors.reset} ${getProgressBar(s.modules)}`);
99
- console.log(` Trust ${scoreColor(s.trust)}${s.trust.toString().padStart(3)}%${colors.reset} ${getProgressBar(s.trust)}`);
100
- console.log();
101
- if (result.valid) {
102
- console.log(`${colors.green}All validations passed.${colors.reset}
103
- `);
104
- }
105
- process.exit(result.valid ? 0 : 1);
106
- }
107
- function formatDiagnosticOutput(data) {
108
- const result = validateAndDiagnose(data);
109
- const diag = result.diagnosis;
110
- const statusIcon = result.valid ? `${colors.green}\u2713${colors.reset}` : `${colors.red}\u2717${colors.reset}`;
111
- const statusText = result.valid ? `${colors.green}Valid${colors.reset}` : `${colors.red}Invalid${colors.reset}`;
112
- console.log(`
113
- ${statusIcon} ${statusText} citemap.json ${colors.dim}v${result.version}${colors.reset}`);
114
- const lvl = result.level;
115
- const levelColor = lvl.current === 3 ? colors.green : lvl.current === 2 ? colors.cyan : colors.yellow;
116
- console.log(` ${levelColor}${colors.bright}${lvl.badge}${colors.reset}`);
117
- if (!lvl.claimAccurate && lvl.claimed != null) {
118
- console.log(` ${colors.yellow}\u26A0 Claimed Level ${lvl.claimed}, actual Level ${lvl.current}${colors.reset}`);
119
- }
120
- console.log();
121
- if (result.errors.length > 0) {
122
- console.log(`${colors.red}${colors.bright}Errors (${result.errors.length}):${colors.reset}`);
123
- result.errors.forEach((error) => {
124
- console.log(` ${colors.red}\u2022${colors.reset} ${error.path}: ${error.message}`);
125
- });
126
- console.log();
127
- }
128
- if (result.warnings.length > 0) {
129
- console.log(`${colors.yellow}${colors.bright}Warnings (${result.warnings.length}):${colors.reset}`);
130
- result.warnings.forEach((warning) => {
131
- console.log(` ${colors.yellow}\u2022${colors.reset} ${warning.path}: ${warning.message}`);
132
- console.log(` ${colors.dim}\u2192 ${warning.suggestion}${colors.reset}`);
133
- });
134
- console.log();
135
- }
136
- const s = result.score;
137
- console.log(`${colors.bright}Quality Scores:${colors.reset}`);
138
- console.log(` Overall ${scoreColor(s.overall)}${s.overall.toString().padStart(3)}%${colors.reset} ${getProgressBar(s.overall)}`);
139
- console.log(` Completeness ${scoreColor(s.completeness)}${s.completeness.toString().padStart(3)}%${colors.reset} ${getProgressBar(s.completeness)}`);
140
- console.log(` Modules ${scoreColor(s.modules)}${s.modules.toString().padStart(3)}%${colors.reset} ${getProgressBar(s.modules)}`);
141
- console.log(` Trust ${scoreColor(s.trust)}${s.trust.toString().padStart(3)}%${colors.reset} ${getProgressBar(s.trust)}`);
142
- console.log();
143
- console.log(`${colors.bright}Diagnosis:${colors.reset}`);
144
- console.log(` Site type: ${colors.cyan}${diag.siteType}${colors.reset}`);
145
- console.log(` Field coverage: ${scoreColor(diag.fieldCoverage.percentage)}${diag.fieldCoverage.filled}/${diag.fieldCoverage.total} (${diag.fieldCoverage.percentage}%)${colors.reset}`);
146
- if (diag.presentModules.length > 0) {
147
- console.log(` Modules present: ${colors.green}${diag.presentModules.join(", ")}${colors.reset}`);
148
- }
149
- if (diag.missingModules.length > 0) {
150
- console.log(` Modules missing: ${colors.yellow}${diag.missingModules.join(", ")}${colors.reset}`);
151
- }
152
- console.log();
153
- if (lvl.nextLevelHints.length > 0) {
154
- const nextLevel = lvl.current + 1;
155
- console.log(`${colors.bright}To reach Level ${nextLevel}:${colors.reset}`);
156
- lvl.nextLevelHints.forEach((hint) => {
157
- console.log(` ${colors.magenta}\u2192${colors.reset} ${hint}`);
158
- });
159
- console.log();
160
- }
161
- if (diag.recommendations.length > 0) {
162
- console.log(`${colors.bright}Recommendations:${colors.reset}`);
163
- diag.recommendations.forEach((rec) => {
164
- console.log(` ${colors.blue}\u2022${colors.reset} ${rec}`);
165
- });
166
- console.log();
167
- }
168
- if (result.valid) {
169
- console.log(`${colors.green}\u2713 All validations passed.${colors.reset}
170
- `);
171
- } else {
172
- console.log(`${colors.red}\u2717 Validation failed. See errors above.${colors.reset}
173
- `);
174
- }
175
- process.exit(result.valid ? 0 : 1);
176
- }
177
- async function main() {
178
- const args = process.argv.slice(2);
179
- if (args.length === 0 || args[0] === "--help") {
180
- printUsage();
181
- process.exit(0);
182
- }
183
- if (args[0] === "--version") {
184
- printVersion();
185
- process.exit(0);
186
- }
187
- const command = args[0];
188
- const filePath = args[1];
189
- if (!filePath) {
190
- console.error(`${colors.red}Error: File path required${colors.reset}
191
- `);
192
- printUsage();
193
- process.exit(1);
194
- }
195
- if (command !== "validate" && command !== "diagnose") {
196
- console.error(`${colors.red}Error: Unknown command '${command}'${colors.reset}
197
- `);
198
- console.error(`Supported commands: ${colors.cyan}validate${colors.reset}, ${colors.cyan}diagnose${colors.reset}
199
- `);
200
- process.exit(1);
201
- }
202
- const data = loadJSON(filePath);
203
- if (command === "validate") {
204
- const result = validate(data);
205
- formatValidationOutput(result);
206
- } else if (command === "diagnose") {
207
- formatDiagnosticOutput(data);
208
- }
209
- }
210
- main().catch((error) => {
211
- console.error(`${colors.red}Fatal error:${colors.reset}`, error instanceof Error ? error.message : String(error));
212
- process.exit(1);
213
- });