ctx7 0.3.8 → 0.3.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctx7",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "Context7 CLI - Manage AI coding skills and documentation context",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,120 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/setup/mcp-writer.ts
4
- import { access, readFile, writeFile, mkdir } from "fs/promises";
5
- import { dirname } from "path";
6
- function stripJsonComments(text) {
7
- let result = "";
8
- let i = 0;
9
- while (i < text.length) {
10
- if (text[i] === '"') {
11
- const start = i++;
12
- while (i < text.length && text[i] !== '"') {
13
- if (text[i] === "\\") i++;
14
- i++;
15
- }
16
- result += text.slice(start, ++i);
17
- } else if (text[i] === "/" && text[i + 1] === "/") {
18
- i += 2;
19
- while (i < text.length && text[i] !== "\n") i++;
20
- } else if (text[i] === "/" && text[i + 1] === "*") {
21
- i += 2;
22
- while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++;
23
- i += 2;
24
- } else {
25
- result += text[i++];
26
- }
27
- }
28
- return result;
29
- }
30
- async function readJsonConfig(filePath) {
31
- let raw;
32
- try {
33
- raw = await readFile(filePath, "utf-8");
34
- } catch {
35
- return {};
36
- }
37
- raw = raw.trim();
38
- if (!raw) return {};
39
- return JSON.parse(stripJsonComments(raw));
40
- }
41
- function mergeServerEntry(existing, configKey, serverName, entry) {
42
- const section = existing[configKey] ?? {};
43
- if (serverName in section) {
44
- return { config: existing, alreadyExists: true };
45
- }
46
- return {
47
- config: {
48
- ...existing,
49
- [configKey]: {
50
- ...section,
51
- [serverName]: entry
52
- }
53
- },
54
- alreadyExists: false
55
- };
56
- }
57
- async function resolveMcpPath(candidates) {
58
- for (const candidate of candidates) {
59
- try {
60
- await access(candidate);
61
- return candidate;
62
- } catch {
63
- }
64
- }
65
- return candidates[0];
66
- }
67
- async function writeJsonConfig(filePath, config) {
68
- await mkdir(dirname(filePath), { recursive: true });
69
- await writeFile(filePath, JSON.stringify(config, null, 2) + "\n", "utf-8");
70
- }
71
- async function readTomlServerExists(filePath, serverName) {
72
- try {
73
- const raw = await readFile(filePath, "utf-8");
74
- return raw.includes(`[mcp_servers.${serverName}]`);
75
- } catch {
76
- return false;
77
- }
78
- }
79
- function buildTomlServerBlock(serverName, entry) {
80
- const lines = [`[mcp_servers.${serverName}]`];
81
- const headers = entry.headers;
82
- for (const [key, value] of Object.entries(entry)) {
83
- if (key === "headers") continue;
84
- lines.push(`${key} = ${JSON.stringify(value)}`);
85
- }
86
- if (headers && Object.keys(headers).length > 0) {
87
- lines.push("");
88
- lines.push(`[mcp_servers.${serverName}.http_headers]`);
89
- for (const [key, value] of Object.entries(headers)) {
90
- lines.push(`${key} = ${JSON.stringify(value)}`);
91
- }
92
- }
93
- return lines.join("\n") + "\n";
94
- }
95
- async function appendTomlServer(filePath, serverName, entry) {
96
- if (await readTomlServerExists(filePath, serverName)) {
97
- return { alreadyExists: true };
98
- }
99
- const block = buildTomlServerBlock(serverName, entry);
100
- let existing = "";
101
- try {
102
- existing = await readFile(filePath, "utf-8");
103
- } catch {
104
- }
105
- const separator = existing.length > 0 && !existing.endsWith("\n") ? "\n\n" : existing.length > 0 ? "\n" : "";
106
- await mkdir(dirname(filePath), { recursive: true });
107
- await writeFile(filePath, existing + separator + block, "utf-8");
108
- return { alreadyExists: false };
109
- }
110
-
111
- export {
112
- readJsonConfig,
113
- mergeServerEntry,
114
- resolveMcpPath,
115
- writeJsonConfig,
116
- readTomlServerExists,
117
- buildTomlServerBlock,
118
- appendTomlServer
119
- };
120
- //# sourceMappingURL=chunk-WKOIWR6Y.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/setup/mcp-writer.ts"],"sourcesContent":["import { access, readFile, writeFile, mkdir } from \"fs/promises\";\nimport { dirname } from \"path\";\n\nfunction stripJsonComments(text: string): string {\n let result = \"\";\n let i = 0;\n while (i < text.length) {\n if (text[i] === '\"') {\n const start = i++;\n while (i < text.length && text[i] !== '\"') {\n if (text[i] === \"\\\\\") i++;\n i++;\n }\n result += text.slice(start, ++i);\n } else if (text[i] === \"/\" && text[i + 1] === \"/\") {\n i += 2;\n while (i < text.length && text[i] !== \"\\n\") i++;\n } else if (text[i] === \"/\" && text[i + 1] === \"*\") {\n i += 2;\n while (i < text.length && !(text[i] === \"*\" && text[i + 1] === \"/\")) i++;\n i += 2;\n } else {\n result += text[i++];\n }\n }\n return result;\n}\n\nexport async function readJsonConfig(filePath: string): Promise<Record<string, unknown>> {\n let raw: string;\n try {\n raw = await readFile(filePath, \"utf-8\");\n } catch {\n return {};\n }\n\n raw = raw.trim();\n if (!raw) return {};\n\n return JSON.parse(stripJsonComments(raw)) as Record<string, unknown>;\n}\n\nexport function mergeServerEntry(\n existing: Record<string, unknown>,\n configKey: string,\n serverName: string,\n entry: Record<string, unknown>\n): { config: Record<string, unknown>; alreadyExists: boolean } {\n const section = (existing[configKey] as Record<string, unknown> | undefined) ?? {};\n\n if (serverName in section) {\n return { config: existing, alreadyExists: true };\n }\n\n return {\n config: {\n ...existing,\n [configKey]: {\n ...section,\n [serverName]: entry,\n },\n },\n alreadyExists: false,\n };\n}\n\nexport async function resolveMcpPath(candidates: string[]): Promise<string> {\n for (const candidate of candidates) {\n try {\n await access(candidate);\n return candidate;\n } catch {\n // continue\n }\n }\n return candidates[0];\n}\n\nexport async function writeJsonConfig(\n filePath: string,\n config: Record<string, unknown>\n): Promise<void> {\n await mkdir(dirname(filePath), { recursive: true });\n await writeFile(filePath, JSON.stringify(config, null, 2) + \"\\n\", \"utf-8\");\n}\n\nexport async function readTomlServerExists(filePath: string, serverName: string): Promise<boolean> {\n try {\n const raw = await readFile(filePath, \"utf-8\");\n return raw.includes(`[mcp_servers.${serverName}]`);\n } catch {\n return false;\n }\n}\n\nexport function buildTomlServerBlock(serverName: string, entry: Record<string, unknown>): string {\n const lines: string[] = [`[mcp_servers.${serverName}]`];\n const headers = entry.headers as Record<string, string> | undefined;\n\n for (const [key, value] of Object.entries(entry)) {\n if (key === \"headers\") continue;\n lines.push(`${key} = ${JSON.stringify(value)}`);\n }\n\n if (headers && Object.keys(headers).length > 0) {\n lines.push(\"\");\n lines.push(`[mcp_servers.${serverName}.http_headers]`);\n for (const [key, value] of Object.entries(headers)) {\n lines.push(`${key} = ${JSON.stringify(value)}`);\n }\n }\n\n return lines.join(\"\\n\") + \"\\n\";\n}\n\nexport async function appendTomlServer(\n filePath: string,\n serverName: string,\n entry: Record<string, unknown>\n): Promise<{ alreadyExists: boolean }> {\n if (await readTomlServerExists(filePath, serverName)) {\n return { alreadyExists: true };\n }\n\n const block = buildTomlServerBlock(serverName, entry);\n\n let existing = \"\";\n try {\n existing = await readFile(filePath, \"utf-8\");\n } catch {\n // File doesn't exist\n }\n\n const separator =\n existing.length > 0 && !existing.endsWith(\"\\n\") ? \"\\n\\n\" : existing.length > 0 ? \"\\n\" : \"\";\n await mkdir(dirname(filePath), { recursive: true });\n await writeFile(filePath, existing + separator + block, \"utf-8\");\n return { alreadyExists: false };\n}\n"],"mappings":";;;AAAA,SAAS,QAAQ,UAAU,WAAW,aAAa;AACnD,SAAS,eAAe;AAExB,SAAS,kBAAkB,MAAsB;AAC/C,MAAI,SAAS;AACb,MAAI,IAAI;AACR,SAAO,IAAI,KAAK,QAAQ;AACtB,QAAI,KAAK,CAAC,MAAM,KAAK;AACnB,YAAM,QAAQ;AACd,aAAO,IAAI,KAAK,UAAU,KAAK,CAAC,MAAM,KAAK;AACzC,YAAI,KAAK,CAAC,MAAM,KAAM;AACtB;AAAA,MACF;AACA,gBAAU,KAAK,MAAM,OAAO,EAAE,CAAC;AAAA,IACjC,WAAW,KAAK,CAAC,MAAM,OAAO,KAAK,IAAI,CAAC,MAAM,KAAK;AACjD,WAAK;AACL,aAAO,IAAI,KAAK,UAAU,KAAK,CAAC,MAAM,KAAM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names":[]}
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- appendTomlServer,
4
- buildTomlServerBlock,
5
- mergeServerEntry,
6
- readJsonConfig,
7
- readTomlServerExists,
8
- resolveMcpPath,
9
- writeJsonConfig
10
- } from "./chunk-WKOIWR6Y.js";
11
- export {
12
- appendTomlServer,
13
- buildTomlServerBlock,
14
- mergeServerEntry,
15
- readJsonConfig,
16
- readTomlServerExists,
17
- resolveMcpPath,
18
- writeJsonConfig
19
- };
20
- //# sourceMappingURL=mcp-writer-IYBCUACD.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}