docsui-cli 0.0.59

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.
Files changed (49) hide show
  1. package/README.md +279 -0
  2. package/dist/commands/add.d.ts +5 -0
  3. package/dist/commands/add.js +254 -0
  4. package/dist/commands/doctor.d.ts +5 -0
  5. package/dist/commands/doctor.js +250 -0
  6. package/dist/commands/init.d.ts +5 -0
  7. package/dist/commands/init.js +548 -0
  8. package/dist/commands/list.d.ts +5 -0
  9. package/dist/commands/list.js +84 -0
  10. package/dist/commands/mcp.d.ts +3 -0
  11. package/dist/commands/mcp.js +1562 -0
  12. package/dist/commands/new.d.ts +5 -0
  13. package/dist/commands/new.js +113 -0
  14. package/dist/commands/remove.d.ts +5 -0
  15. package/dist/commands/remove.js +134 -0
  16. package/dist/commands/save.d.ts +5 -0
  17. package/dist/commands/save.js +60 -0
  18. package/dist/commands/update.d.ts +5 -0
  19. package/dist/commands/update.js +247 -0
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.js +88 -0
  22. package/dist/latex-to-primitives.d.ts +59 -0
  23. package/dist/latex-to-primitives.js +1019 -0
  24. package/dist/lib/component-registry.d.ts +33 -0
  25. package/dist/lib/component-registry.js +843 -0
  26. package/dist/lib/css-tokens.d.ts +8 -0
  27. package/dist/lib/css-tokens.js +294 -0
  28. package/dist/metadata.d.ts +1 -0
  29. package/dist/metadata.js +4 -0
  30. package/dist/symbol-map.d.ts +30 -0
  31. package/dist/symbol-map.js +1607 -0
  32. package/dist/utils/detect-structure.d.ts +16 -0
  33. package/dist/utils/detect-structure.js +58 -0
  34. package/dist/utils/fetch-component.d.ts +13 -0
  35. package/dist/utils/fetch-component.js +81 -0
  36. package/dist/utils/get-config.d.ts +14 -0
  37. package/dist/utils/get-config.js +19 -0
  38. package/dist/utils/install-deps.d.ts +3 -0
  39. package/dist/utils/install-deps.js +23 -0
  40. package/dist/utils/save-mdx-page.d.ts +35 -0
  41. package/dist/utils/save-mdx-page.js +44 -0
  42. package/dist/utils/scan-mdx.d.ts +20 -0
  43. package/dist/utils/scan-mdx.js +106 -0
  44. package/dist/utils/telemetry.d.ts +3 -0
  45. package/dist/utils/telemetry.js +42 -0
  46. package/dist/utils/write-component.d.ts +7 -0
  47. package/dist/utils/write-component.js +25 -0
  48. package/dist/webview-bundle.js +3478 -0
  49. package/package.json +94 -0
@@ -0,0 +1,250 @@
1
+ import { Command } from "commander";
2
+ import chalk from "chalk";
3
+ import fs from "fs-extra";
4
+ import path from "path";
5
+ import { getConfig } from "../utils/get-config.js";
6
+ import { COMPONENT_FILES, COMPONENT_DEPS } from "../lib/component-registry.js";
7
+ async function getInstalledDeps(cwd) {
8
+ const installed = /* @__PURE__ */ new Set();
9
+ const p = path.join(cwd, "package.json");
10
+ if (!await fs.pathExists(p)) return installed;
11
+ try {
12
+ const pkg = await fs.readJSON(p);
13
+ const allDeps = {
14
+ ...pkg.dependencies,
15
+ ...pkg.devDependencies,
16
+ ...pkg.peerDependencies
17
+ };
18
+ Object.keys(allDeps).forEach((d) => installed.add(d));
19
+ } catch {
20
+ }
21
+ return installed;
22
+ }
23
+ const doctor = new Command().name("doctor").description(
24
+ "Check your project for missing dependencies or broken component setup"
25
+ ).action(async () => {
26
+ console.log();
27
+ console.log(chalk.bold("Running docsui doctor...\n"));
28
+ const issues = [];
29
+ const cwd = process.cwd();
30
+ const config = await getConfig();
31
+ if (!config) {
32
+ issues.push({
33
+ level: "error",
34
+ message: "No docsui.json found \u2014 run: npx docsui-cli@latest init"
35
+ });
36
+ printReport(issues);
37
+ return;
38
+ }
39
+ console.log(
40
+ ` ${chalk.green("\u2713")} docsui.json found ${chalk.dim(`(componentsDir: ${config.componentsDir})`)}`
41
+ );
42
+ const compDir = path.join(cwd, config.componentsDir);
43
+ if (!await fs.pathExists(compDir)) {
44
+ issues.push({
45
+ level: "error",
46
+ message: `Components directory not found: ${config.componentsDir}`
47
+ });
48
+ printReport(issues);
49
+ return;
50
+ }
51
+ const files = await fs.readdir(compDir);
52
+ const installed = [];
53
+ for (const [name, compFiles] of Object.entries(COMPONENT_FILES)) {
54
+ const ownFiles = compFiles.filter((f) => !f.startsWith("lib/"));
55
+ if (ownFiles.length > 0 && ownFiles.every((f) => files.includes(f)))
56
+ installed.push(name);
57
+ }
58
+ if (installed.length === 0) {
59
+ console.log(
60
+ chalk.yellow(" No docsui components found in components directory.")
61
+ );
62
+ printReport(issues);
63
+ return;
64
+ }
65
+ console.log(
66
+ ` ${chalk.green("\u2713")} ${installed.length} component${installed.length !== 1 ? "s" : ""} installed ${chalk.dim(`(${installed.join(", ")})`)}
67
+ `
68
+ );
69
+ const libDir = config.componentsDir.startsWith("src/") ? "src/lib" : "lib";
70
+ const utilsPath = path.join(cwd, libDir, "utils.ts");
71
+ if (!await fs.pathExists(utilsPath)) {
72
+ issues.push({
73
+ level: "error",
74
+ message: `lib/utils.ts not found \u2014 run: npx docsui-cli@latest add utils`
75
+ });
76
+ } else {
77
+ console.log(` ${chalk.green("\u2713")} ${libDir}/utils.ts`);
78
+ }
79
+ const installedDeps = await getInstalledDeps(cwd);
80
+ const missingDeps = /* @__PURE__ */ new Set();
81
+ for (const name of installed) {
82
+ for (const dep of COMPONENT_DEPS[name] ?? []) {
83
+ if (!installedDeps.has(dep)) missingDeps.add(dep);
84
+ }
85
+ }
86
+ if (missingDeps.size > 0) {
87
+ for (const dep of missingDeps) {
88
+ issues.push({
89
+ level: "error",
90
+ message: `Missing npm dependency: ${dep}`
91
+ });
92
+ }
93
+ console.log();
94
+ console.log(
95
+ ` ${chalk.red("\u2717")} Missing deps: ${chalk.bold([...missingDeps].join(", "))}`
96
+ );
97
+ console.log(` Fix: npm install ${[...missingDeps].join(" ")}`);
98
+ } else {
99
+ console.log(` ${chalk.green("\u2713")} All npm dependencies present`);
100
+ }
101
+ if (config.cssFile) {
102
+ const cssPath = path.join(cwd, config.cssFile);
103
+ if (!await fs.pathExists(cssPath)) {
104
+ issues.push({
105
+ level: "warn",
106
+ message: `CSS file not found: ${config.cssFile}`
107
+ });
108
+ } else {
109
+ const cssContent = await fs.readFile(cssPath, "utf-8");
110
+ if (!cssContent.includes("--mdxui-info-bg")) {
111
+ issues.push({
112
+ level: "warn",
113
+ message: `Missing docsui semantic tokens in ${config.cssFile} \u2014 re-run: npx docsui-cli@latest init`
114
+ });
115
+ console.log(
116
+ ` ${chalk.yellow("~")} --mdxui-* tokens missing from ${config.cssFile}`
117
+ );
118
+ } else {
119
+ console.log(
120
+ ` ${chalk.green("\u2713")} docsui CSS tokens in ${config.cssFile}`
121
+ );
122
+ }
123
+ }
124
+ }
125
+ if (config.tailwindConfig) {
126
+ const twPath = path.join(cwd, config.tailwindConfig);
127
+ if (await fs.pathExists(twPath)) {
128
+ const twContent = await fs.readFile(twPath, "utf-8");
129
+ if (!twContent.includes("--mdxui-info-border")) {
130
+ issues.push({
131
+ level: "warn",
132
+ message: `docsui semantic colors missing from ${config.tailwindConfig} \u2014 re-run: npx docsui-cli@latest init`
133
+ });
134
+ console.log(
135
+ ` ${chalk.yellow("~")} docsui colors missing from ${config.tailwindConfig}`
136
+ );
137
+ } else {
138
+ console.log(
139
+ ` ${chalk.green("\u2713")} docsui colors in ${config.tailwindConfig}`
140
+ );
141
+ }
142
+ }
143
+ }
144
+ const mdxPath = path.join(cwd, config.componentsDir, "mdx-components.tsx");
145
+ if (!await fs.pathExists(mdxPath)) {
146
+ issues.push({
147
+ level: "warn",
148
+ message: "mdx-components.tsx not found \u2014 component auto-mapping unavailable"
149
+ });
150
+ } else {
151
+ const mdxContent = await fs.readFile(mdxPath, "utf-8");
152
+ const notMapped = [];
153
+ for (const name of installed) {
154
+ if (!mdxContent.includes(`from "./${name}"`)) notMapped.push(name);
155
+ }
156
+ if (notMapped.length > 0) {
157
+ issues.push({
158
+ level: "warn",
159
+ message: `Not imported in mdx-components.tsx: ${notMapped.join(", ")} \u2014 re-run add for these components`
160
+ });
161
+ console.log();
162
+ console.log(
163
+ ` ${chalk.yellow("~")} Not mapped in mdx-components.tsx: ${notMapped.join(", ")}`
164
+ );
165
+ } else {
166
+ console.log(` ${chalk.green("\u2713")} mdx-components.tsx looks good`);
167
+ }
168
+ }
169
+ const remarkPkg = "@docsui-io/remark-plugin";
170
+ if (!installedDeps.has(remarkPkg)) {
171
+ issues.push({
172
+ level: "warn",
173
+ message: `${remarkPkg} not installed \u2014 markdown won't auto-upgrade to components. Run: npm install ${remarkPkg}`
174
+ });
175
+ console.log(` ${chalk.yellow("~")} ${remarkPkg} not installed`);
176
+ } else {
177
+ const pipeline = config.mdxPipeline ?? "unknown";
178
+ const wired = await checkRemarkPluginWired(pipeline, cwd);
179
+ if (wired === null) {
180
+ console.log(` ${chalk.green("\u2713")} ${remarkPkg} installed`);
181
+ } else if (!wired) {
182
+ issues.push({
183
+ level: "warn",
184
+ message: `remarkMdxUi not found in ${pipeline} config \u2014 add it to remarkPlugins`
185
+ });
186
+ console.log(
187
+ ` ${chalk.yellow("~")} remarkMdxUi not wired in ${pipeline} config`
188
+ );
189
+ } else {
190
+ console.log(
191
+ ` ${chalk.green("\u2713")} remarkMdxUi wired in ${pipeline} config`
192
+ );
193
+ }
194
+ }
195
+ printReport(issues);
196
+ });
197
+ async function checkRemarkPluginWired(pipeline, cwd) {
198
+ const CONFIG_CANDIDATES = {
199
+ contentlayer: ["contentlayer.config.ts", "contentlayer.config.js"],
200
+ "next-mdx": [
201
+ "next.config.ts",
202
+ "next.config.mjs",
203
+ "next.config.js",
204
+ "next.config.cjs"
205
+ ],
206
+ "astro-mdx": ["astro.config.ts", "astro.config.mjs"],
207
+ "mdx-rollup": ["vite.config.ts", "vite.config.js", "vite.config.mts"]
208
+ };
209
+ const candidates = CONFIG_CANDIDATES[pipeline];
210
+ if (!candidates) return null;
211
+ for (const candidate of candidates) {
212
+ const p = path.join(cwd, candidate);
213
+ if (!await fs.pathExists(p)) continue;
214
+ const content = await fs.readFile(p, "utf-8");
215
+ const uncommented = content.split("\n").filter((line) => !/^\s*(\/\/|\/\*|\*)/.test(line)).join("\n");
216
+ return uncommented.includes("remarkMdxUi") || uncommented.includes("@docsui-io/remark-plugin");
217
+ }
218
+ return false;
219
+ }
220
+ function printReport(issues) {
221
+ console.log();
222
+ if (issues.length === 0) {
223
+ console.log(chalk.green(chalk.bold("All checks passed.")));
224
+ console.log();
225
+ return;
226
+ }
227
+ const errors = issues.filter((i) => i.level === "error");
228
+ const warns = issues.filter((i) => i.level === "warn");
229
+ if (errors.length > 0) {
230
+ console.log(
231
+ chalk.red(
232
+ chalk.bold(`${errors.length} error${errors.length !== 1 ? "s" : ""}:`)
233
+ )
234
+ );
235
+ for (const e of errors) console.log(` ${chalk.red("\u2717")} ${e.message}`);
236
+ console.log();
237
+ }
238
+ if (warns.length > 0) {
239
+ console.log(
240
+ chalk.yellow(
241
+ chalk.bold(`${warns.length} warning${warns.length !== 1 ? "s" : ""}:`)
242
+ )
243
+ );
244
+ for (const w of warns) console.log(` ${chalk.yellow("~")} ${w.message}`);
245
+ console.log();
246
+ }
247
+ }
248
+ export {
249
+ doctor
250
+ };
@@ -0,0 +1,5 @@
1
+ import { Command } from 'commander';
2
+
3
+ declare const init: Command;
4
+
5
+ export { init };