@citemap/cli 0.1.0 → 0.2.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/dist/index.js ADDED
@@ -0,0 +1,164 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { readFileSync } from "fs";
5
+ import { resolve } from "path";
6
+ import { validate, diagnose } from "@citemap/validator";
7
+ var VERSION = "0.2.0";
8
+ var colors = {
9
+ reset: "\x1B[0m",
10
+ bright: "\x1B[1m",
11
+ red: "\x1B[31m",
12
+ green: "\x1B[32m",
13
+ yellow: "\x1B[33m",
14
+ blue: "\x1B[34m",
15
+ cyan: "\x1B[36m"
16
+ };
17
+ function printUsage() {
18
+ console.log(`
19
+ ${colors.bright}citemap${colors.reset} \u2014 Validate citemap.json files for AI accuracy
20
+
21
+ ${colors.bright}Usage:${colors.reset}
22
+ citemap validate <path> Validate a citemap.json file
23
+ citemap diagnose <path> Run detailed analysis with scores
24
+ citemap --help Show this help message
25
+ citemap --version Show version number
26
+
27
+ ${colors.bright}Examples:${colors.reset}
28
+ citemap validate ./citemap.json
29
+ citemap diagnose .well-known/citemap.json
30
+
31
+ ${colors.bright}Learn more:${colors.reset}
32
+ https://github.com/citemaps/citemap
33
+ `);
34
+ }
35
+ function printVersion() {
36
+ console.log(`citemap v${VERSION}`);
37
+ }
38
+ function loadJSON(filePath) {
39
+ try {
40
+ const absolutePath = resolve(filePath);
41
+ const content = readFileSync(absolutePath, "utf-8");
42
+ return JSON.parse(content);
43
+ } catch (error) {
44
+ if (error instanceof SyntaxError) {
45
+ console.error(`${colors.red}\u2717 Invalid JSON${colors.reset}: ${error.message}`);
46
+ process.exit(1);
47
+ }
48
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
49
+ console.error(`${colors.red}\u2717 File not found${colors.reset}: ${filePath}`);
50
+ process.exit(1);
51
+ }
52
+ console.error(`${colors.red}\u2717 Error reading file${colors.reset}: ${error instanceof Error ? error.message : String(error)}`);
53
+ process.exit(1);
54
+ }
55
+ }
56
+ function formatValidationOutput(result) {
57
+ const statusIcon = result.valid ? `${colors.green}\u2713${colors.reset}` : `${colors.red}\u2717${colors.reset}`;
58
+ const statusText = result.valid ? `${colors.green}Valid${colors.reset}` : `${colors.red}Invalid${colors.reset}`;
59
+ console.log(`
60
+ ${statusIcon} ${statusText} citemap.json
61
+ `);
62
+ if (result.errors && result.errors.length > 0) {
63
+ console.log(`${colors.red}${colors.bright}Errors (${result.errors.length}):${colors.reset}`);
64
+ result.errors.forEach((error) => {
65
+ console.log(` ${colors.red}\u2022${colors.reset} ${error}`);
66
+ });
67
+ console.log();
68
+ }
69
+ if (result.warnings && result.warnings.length > 0) {
70
+ console.log(`${colors.yellow}${colors.bright}Warnings (${result.warnings.length}):${colors.reset}`);
71
+ result.warnings.forEach((warning) => {
72
+ console.log(` ${colors.yellow}\u2022${colors.reset} ${warning}`);
73
+ });
74
+ console.log();
75
+ }
76
+ if (result.valid) {
77
+ console.log(`${colors.green}All validations passed.${colors.reset}
78
+ `);
79
+ }
80
+ process.exit(result.valid ? 0 : 1);
81
+ }
82
+ function formatDiagnosticOutput(result) {
83
+ const statusIcon = result.valid ? `${colors.green}\u2713${colors.reset}` : `${colors.red}\u2717${colors.reset}`;
84
+ const statusText = result.valid ? `${colors.green}Valid${colors.reset}` : `${colors.red}Invalid${colors.reset}`;
85
+ console.log(`
86
+ ${statusIcon} ${statusText} citemap.json
87
+ `);
88
+ if (result.errors && result.errors.length > 0) {
89
+ console.log(`${colors.red}${colors.bright}Errors (${result.errors.length}):${colors.reset}`);
90
+ result.errors.forEach((error) => {
91
+ console.log(` ${colors.red}\u2022${colors.reset} ${error}`);
92
+ });
93
+ console.log();
94
+ }
95
+ if (result.warnings && result.warnings.length > 0) {
96
+ console.log(`${colors.yellow}${colors.bright}Warnings (${result.warnings.length}):${colors.reset}`);
97
+ result.warnings.forEach((warning) => {
98
+ console.log(` ${colors.yellow}\u2022${colors.reset} ${warning}`);
99
+ });
100
+ console.log();
101
+ }
102
+ if (result.scores) {
103
+ console.log(`${colors.bright}Quality Scores:${colors.reset}`);
104
+ const scores = result.scores;
105
+ Object.entries(scores).forEach(([key, score]) => {
106
+ const percentage = Math.round(score * 100);
107
+ const scoreColor = percentage >= 80 ? colors.green : percentage >= 60 ? colors.yellow : colors.red;
108
+ const bar = getProgressBar(percentage);
109
+ console.log(` ${key.padEnd(20)} ${scoreColor}${percentage.toString().padStart(3)}%${colors.reset} ${bar}`);
110
+ });
111
+ console.log();
112
+ }
113
+ if (result.valid) {
114
+ console.log(`${colors.green}\u2713 All validations passed.${colors.reset}
115
+ `);
116
+ } else {
117
+ console.log(`${colors.red}\u2717 Validation failed. See errors above.${colors.reset}
118
+ `);
119
+ }
120
+ process.exit(result.valid ? 0 : 1);
121
+ }
122
+ function getProgressBar(percentage, width = 20) {
123
+ const filled = Math.round(percentage / 100 * width);
124
+ const empty = width - filled;
125
+ return `[${colors.green}${"\u2588".repeat(filled)}${colors.reset}${colors.bright}${"\u2591".repeat(empty)}${colors.reset}]`;
126
+ }
127
+ async function main() {
128
+ const args = process.argv.slice(2);
129
+ if (args.length === 0 || args[0] === "--help") {
130
+ printUsage();
131
+ process.exit(0);
132
+ }
133
+ if (args[0] === "--version") {
134
+ printVersion();
135
+ process.exit(0);
136
+ }
137
+ const command = args[0];
138
+ const filePath = args[1];
139
+ if (!filePath) {
140
+ console.error(`${colors.red}Error: File path required${colors.reset}
141
+ `);
142
+ printUsage();
143
+ process.exit(1);
144
+ }
145
+ if (command !== "validate" && command !== "diagnose") {
146
+ console.error(`${colors.red}Error: Unknown command '${command}'${colors.reset}
147
+ `);
148
+ console.error(`Supported commands: ${colors.cyan}validate${colors.reset}, ${colors.cyan}diagnose${colors.reset}
149
+ `);
150
+ process.exit(1);
151
+ }
152
+ const data = loadJSON(filePath);
153
+ if (command === "validate") {
154
+ const result = validate(data);
155
+ formatValidationOutput(result);
156
+ } else if (command === "diagnose") {
157
+ const result = diagnose(data);
158
+ formatDiagnosticOutput(result);
159
+ }
160
+ }
161
+ main().catch((error) => {
162
+ console.error(`${colors.red}Fatal error:${colors.reset}`, error instanceof Error ? error.message : String(error));
163
+ process.exit(1);
164
+ });
package/package.json CHANGED
@@ -1,20 +1,38 @@
1
- {
2
- "name": "@citemap/cli",
3
- "version": "0.1.0",
4
- "description": "Command-line tool for validating citemap.json files against the v2.0 specification",
5
- "main": "index.js",
6
- "bin": {
7
- "citemap": "./bin/citemap.js"
8
- },
9
- "keywords": ["citemap", "cli", "validator", "json-schema", "seo", "ai", "structured-data"],
10
- "author": "CiteMaps.ai",
11
- "license": "MIT",
12
- "homepage": "https://citemaps.org",
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/citemaps/citemap"
16
- },
17
- "bugs": {
18
- "url": "https://github.com/citemaps/citemap/issues"
19
- }
20
- }
1
+ {
2
+ "name": "@citemap/cli",
3
+ "version": "0.2.0",
4
+ "description": "Command-line tool for validating citemap.json files",
5
+ "type": "module",
6
+ "bin": {
7
+ "citemap": "./dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsup src/index.ts --format cjs --dts",
14
+ "dev": "node --loader ts-node/esm src/index.ts"
15
+ },
16
+ "keywords": [
17
+ "citemap",
18
+ "cli",
19
+ "validator",
20
+ "ai",
21
+ "citation"
22
+ ],
23
+ "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/citemaps/citemap"
27
+ },
28
+ "engines": {
29
+ "node": ">=18.0.0"
30
+ },
31
+ "dependencies": {
32
+ "@citemap/validator": "^0.2.0"
33
+ },
34
+ "devDependencies": {
35
+ "tsup": "^8.0.0",
36
+ "typescript": "^5.4.0"
37
+ }
38
+ }
package/README.md DELETED
@@ -1,42 +0,0 @@
1
- # @citemap/cli
2
-
3
- Command-line tool for working with `citemap.json` files. Validate, score, and initialize CiteMap files directly from your terminal.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install -g @citemap/cli
9
- ```
10
-
11
- ## Commands (coming soon)
12
-
13
- ```bash
14
- # Validate a citemap.json file
15
- citemap validate ./citemap.json
16
-
17
- # Get a completeness score
18
- citemap score ./citemap.json
19
-
20
- # Create a starter citemap.json
21
- citemap init
22
- ```
23
-
24
- ## Status
25
-
26
- This package is under active development. Full CLI functionality will be published soon.
27
-
28
- ## Related Packages
29
-
30
- - [`@citemap/schema`](https://www.npmjs.com/package/@citemap/schema) — JSON Schema definition and TypeScript types
31
- - [`@citemap/validator`](https://www.npmjs.com/package/@citemap/validator) — Validate citemap.json files against the v2.0 spec
32
- - [`@citemap/generator`](https://www.npmjs.com/package/@citemap/generator) — AI-powered citemap.json generator (BYOK)
33
-
34
- ## Links
35
-
36
- - [CiteMap Specification](https://citemaps.org)
37
- - [CiteMaps.ai](https://citemaps.ai) — Generate and validate CiteMaps online
38
- - [GitHub](https://github.com/citemaps/citemap)
39
-
40
- ## License
41
-
42
- MIT
package/bin/citemap.js DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- console.log("@citemap/cli is under active development.");
4
- console.log("");
5
- console.log("Coming soon:");
6
- console.log(" citemap validate ./citemap.json Validate a CiteMap file");
7
- console.log(" citemap score ./citemap.json Get completeness score");
8
- console.log(" citemap init Create a starter citemap.json");
9
- console.log("");
10
- console.log("For more info, visit https://citemaps.org");
package/index.js DELETED
@@ -1,4 +0,0 @@
1
- // @citemap/cli — Command-line tool for citemap.json validation
2
- // Full implementation coming soon. See https://citemaps.org for the specification.
3
-
4
- module.exports = {};