@citemap/cli 0.3.4 → 0.4.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 +7 -0
- package/dist/index.mjs +86 -13
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -102,3 +102,10 @@ 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.0
|
|
108
|
+
|
|
109
|
+
- `citemap validate <url>` reads a citemap over https.
|
|
110
|
+
- 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.
|
|
111
|
+
- v3.3 / v3.4 files are checked against the spec's structural rules instead of the strict v3.0 schema.
|
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.
|
|
6
|
+
import { validate, validateAndDiagnose, validateContentFile, checkAcrossFiles } from "@citemap/validator";
|
|
7
|
+
var VERSION = "0.4.0";
|
|
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>
|
|
25
|
-
citemap diagnose <path>
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
203
|
-
if (
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Command-line tool for validating citemap.json files",
|
|
5
5
|
"bin": {
|
|
6
6
|
"citemap": "bin/citemap.js"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"node": ">=18.0.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@citemap/validator": "^0.
|
|
33
|
+
"@citemap/validator": "^0.4.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^25.5.0",
|