@citemap/cli 0.3.2 → 0.3.4
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/bin/citemap.js +2 -0
- package/dist/index.js +8 -9
- package/dist/index.mjs +213 -0
- package/package.json +5 -4
package/bin/citemap.js
ADDED
package/dist/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
2
|
|
|
4
3
|
// src/index.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var VERSION = "0.3.
|
|
4
|
+
import { readFileSync } from "fs";
|
|
5
|
+
import { resolve } from "path";
|
|
6
|
+
import { validate, validateAndDiagnose } from "@citemap/validator";
|
|
7
|
+
var VERSION = "0.3.3";
|
|
9
8
|
var colors = {
|
|
10
9
|
reset: "\x1B[0m",
|
|
11
10
|
bright: "\x1B[1m",
|
|
@@ -40,8 +39,8 @@ function printVersion() {
|
|
|
40
39
|
}
|
|
41
40
|
function loadJSON(filePath) {
|
|
42
41
|
try {
|
|
43
|
-
const absolutePath =
|
|
44
|
-
const content =
|
|
42
|
+
const absolutePath = resolve(filePath);
|
|
43
|
+
const content = readFileSync(absolutePath, "utf-8");
|
|
45
44
|
return JSON.parse(content);
|
|
46
45
|
} catch (error) {
|
|
47
46
|
if (error instanceof SyntaxError) {
|
|
@@ -106,7 +105,7 @@ ${statusIcon} ${statusText} citemap.json ${colors.dim}v${result.version}${color
|
|
|
106
105
|
process.exit(result.valid ? 0 : 1);
|
|
107
106
|
}
|
|
108
107
|
function formatDiagnosticOutput(data) {
|
|
109
|
-
const result =
|
|
108
|
+
const result = validateAndDiagnose(data);
|
|
110
109
|
const diag = result.diagnosis;
|
|
111
110
|
const statusIcon = result.valid ? `${colors.green}\u2713${colors.reset}` : `${colors.red}\u2717${colors.reset}`;
|
|
112
111
|
const statusText = result.valid ? `${colors.green}Valid${colors.reset}` : `${colors.red}Invalid${colors.reset}`;
|
|
@@ -202,7 +201,7 @@ async function main() {
|
|
|
202
201
|
}
|
|
203
202
|
const data = loadJSON(filePath);
|
|
204
203
|
if (command === "validate") {
|
|
205
|
-
const result =
|
|
204
|
+
const result = validate(data);
|
|
206
205
|
formatValidationOutput(result);
|
|
207
206
|
} else if (command === "diagnose") {
|
|
208
207
|
formatDiagnosticOutput(data);
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
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
|
+
});
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@citemap/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Command-line tool for validating citemap.json files",
|
|
5
5
|
"bin": {
|
|
6
|
-
"citemap": "
|
|
6
|
+
"citemap": "bin/citemap.js"
|
|
7
7
|
},
|
|
8
8
|
"files": [
|
|
9
|
-
"dist"
|
|
9
|
+
"dist",
|
|
10
|
+
"bin"
|
|
10
11
|
],
|
|
11
12
|
"scripts": {
|
|
12
|
-
"build": "tsup src/index.ts --format
|
|
13
|
+
"build": "tsup src/index.ts --format esm --no-dts --out-dir dist",
|
|
13
14
|
"dev": "node --loader ts-node/esm src/index.ts",
|
|
14
15
|
"prepublishOnly": "npm run build"
|
|
15
16
|
},
|