@fumadocs/cli 1.2.0 → 1.2.2
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/ast-DFGM1gEn.js +72 -0
- package/dist/ast-DFGM1gEn.js.map +1 -0
- package/dist/build/index.d.ts +142 -137
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +275 -323
- package/dist/build/index.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +557 -760
- package/dist/index.js.map +1 -0
- package/package.json +21 -18
package/dist/index.js
CHANGED
|
@@ -1,829 +1,626 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import path5 from "path";
|
|
2
|
+
import { n as transformSpecifiers, r as typescriptExtensions, t as toImportSpecifier } from "./ast-DFGM1gEn.js";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
6
5
|
import { Command } from "commander";
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import
|
|
6
|
+
import picocolors from "picocolors";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { x } from "tinyexec";
|
|
9
|
+
import { cancel, confirm, group, intro, isCancel, log, multiselect, outro, select, spinner } from "@clack/prompts";
|
|
10
|
+
import { parse } from "oxc-parser";
|
|
11
|
+
import { detect } from "package-manager-detector";
|
|
12
|
+
import MagicString from "magic-string";
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
import fs from "fs/promises";
|
|
14
|
-
import path from "path";
|
|
14
|
+
//#region src/utils/fs.ts
|
|
15
15
|
async function exists(pathLike) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
try {
|
|
17
|
+
await fs.access(pathLike);
|
|
18
|
+
return true;
|
|
19
|
+
} catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/utils/is-src.ts
|
|
25
26
|
async function isSrc() {
|
|
26
|
-
|
|
27
|
+
return exists("./src");
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
function createConfigSchema(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
commands: z.object({
|
|
53
|
-
/**
|
|
54
|
-
* command to format output code automatically
|
|
55
|
-
*/
|
|
56
|
-
format: z.string().optional()
|
|
57
|
-
}).default({})
|
|
58
|
-
});
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/config.ts
|
|
32
|
+
function createConfigSchema(isSrc$1) {
|
|
33
|
+
const defaultAliases = {
|
|
34
|
+
uiDir: "./components/ui",
|
|
35
|
+
componentsDir: "./components",
|
|
36
|
+
blockDir: "./components",
|
|
37
|
+
cssDir: "./styles",
|
|
38
|
+
libDir: "./lib"
|
|
39
|
+
};
|
|
40
|
+
return z.object({
|
|
41
|
+
$schema: z.string().default(isSrc$1 ? "node_modules/@fumadocs/cli/dist/schema/src.json" : "node_modules/@fumadocs/cli/dist/schema/default.json").optional(),
|
|
42
|
+
aliases: z.object({
|
|
43
|
+
uiDir: z.string().default(defaultAliases.uiDir),
|
|
44
|
+
componentsDir: z.string().default(defaultAliases.uiDir),
|
|
45
|
+
blockDir: z.string().default(defaultAliases.blockDir),
|
|
46
|
+
cssDir: z.string().default(defaultAliases.componentsDir),
|
|
47
|
+
libDir: z.string().default(defaultAliases.libDir)
|
|
48
|
+
}).default(defaultAliases),
|
|
49
|
+
baseDir: z.string().default(isSrc$1 ? "src" : ""),
|
|
50
|
+
uiLibrary: z.enum(["radix-ui", "base-ui"]).default("radix-ui"),
|
|
51
|
+
commands: z.object({ format: z.string().optional() }).default({})
|
|
52
|
+
});
|
|
59
53
|
}
|
|
60
54
|
async function createOrLoadConfig(file = "./cli.json") {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const configSchema = createConfigSchema(src);
|
|
66
|
-
return configSchema.parse(JSON.parse(content));
|
|
55
|
+
const inited = await initConfig(file);
|
|
56
|
+
if (inited) return inited;
|
|
57
|
+
const content = (await fs.readFile(file)).toString();
|
|
58
|
+
return createConfigSchema(await isSrc()).parse(JSON.parse(content));
|
|
67
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Write new config, skip if a config already exists
|
|
62
|
+
*
|
|
63
|
+
* @returns the created config, `undefined` if not created
|
|
64
|
+
*/
|
|
68
65
|
async function initConfig(file = "./cli.json", src) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
{}
|
|
74
|
-
);
|
|
75
|
-
await fs2.writeFile(file, JSON.stringify(defaultConfig, null, 2));
|
|
76
|
-
return defaultConfig;
|
|
66
|
+
if (await fs.stat(file).then(() => true).catch(() => false)) return;
|
|
67
|
+
const defaultConfig = createConfigSchema(src ?? await isSrc()).parse({});
|
|
68
|
+
await fs.writeFile(file, JSON.stringify(defaultConfig, null, 2));
|
|
69
|
+
return defaultConfig;
|
|
77
70
|
}
|
|
78
71
|
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/commands/file-tree.ts
|
|
74
|
+
const scanned = [
|
|
75
|
+
"file",
|
|
76
|
+
"directory",
|
|
77
|
+
"link"
|
|
78
|
+
];
|
|
81
79
|
function treeToMdx(input, noRoot = false) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
return `<Folder name=${JSON.stringify(item.name)}>
|
|
80
|
+
function toNode(item) {
|
|
81
|
+
if (item.type === "file" || item.type === "link") return `<File name=${JSON.stringify(item.name)} />`;
|
|
82
|
+
if (item.type === "directory") {
|
|
83
|
+
if (item.contents.length === 1 && "name" in item.contents[0]) {
|
|
84
|
+
const child = item.contents[0];
|
|
85
|
+
return toNode({
|
|
86
|
+
...child,
|
|
87
|
+
name: `${item.name}/${child.name}`
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return `<Folder name=${JSON.stringify(item.name)}>
|
|
95
91
|
${item.contents.map(toNode).filter(Boolean).join("\n")}
|
|
96
92
|
</Folder>`;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
return `<Files>
|
|
93
|
+
}
|
|
94
|
+
return "";
|
|
95
|
+
}
|
|
96
|
+
let children = input.filter((v) => scanned.includes(v.type));
|
|
97
|
+
if (noRoot && children.length === 1 && input[0].type === "directory") children = input[0].contents;
|
|
98
|
+
return `<Files>
|
|
105
99
|
${children.map(toNode).filter(Boolean).join("\n")}
|
|
106
100
|
</Files>`;
|
|
107
101
|
}
|
|
108
102
|
function treeToJavaScript(input, noRoot, importName = "fumadocs-ui/components/files") {
|
|
109
|
-
|
|
103
|
+
return `import { File, Files, Folder } from ${JSON.stringify(importName)}
|
|
110
104
|
|
|
111
105
|
export default (${treeToMdx(input, noRoot)})`;
|
|
112
106
|
}
|
|
113
107
|
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/utils/file-tree/run-tree.ts
|
|
116
110
|
async function runTree(args) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
var package_default = {
|
|
129
|
-
name: "@fumadocs/cli",
|
|
130
|
-
version: "1.2.0",
|
|
131
|
-
description: "The CLI tool for Fumadocs",
|
|
132
|
-
keywords: [
|
|
133
|
-
"NextJs",
|
|
134
|
-
"Docs",
|
|
135
|
-
"Fumadocs"
|
|
136
|
-
],
|
|
137
|
-
homepage: "https://fumadocs.dev",
|
|
138
|
-
repository: "github:fuma-nama/fumadocs",
|
|
139
|
-
license: "MIT",
|
|
140
|
-
author: "Fuma Nama",
|
|
141
|
-
type: "module",
|
|
142
|
-
exports: {
|
|
143
|
-
"./build": {
|
|
144
|
-
import: "./dist/build/index.js",
|
|
145
|
-
types: "./dist/build/index.d.ts"
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
main: "./dist/index.js",
|
|
149
|
-
bin: {
|
|
150
|
-
fumadocs: "./dist/index.js"
|
|
151
|
-
},
|
|
152
|
-
files: [
|
|
153
|
-
"dist/*"
|
|
154
|
-
],
|
|
155
|
-
scripts: {
|
|
156
|
-
build: "tsup",
|
|
157
|
-
clean: "rimraf dist",
|
|
158
|
-
dev: "tsup --watch",
|
|
159
|
-
lint: "eslint .",
|
|
160
|
-
"types:check": "tsc --noEmit"
|
|
161
|
-
},
|
|
162
|
-
dependencies: {
|
|
163
|
-
"@clack/prompts": "^0.11.0",
|
|
164
|
-
commander: "^14.0.2",
|
|
165
|
-
"package-manager-detector": "^1.6.0",
|
|
166
|
-
picocolors: "^1.1.1",
|
|
167
|
-
tinyexec: "^1.0.2",
|
|
168
|
-
"ts-morph": "^27.0.2",
|
|
169
|
-
zod: "^4.2.1"
|
|
170
|
-
},
|
|
171
|
-
devDependencies: {
|
|
172
|
-
"@types/node": "24.10.2",
|
|
173
|
-
"eslint-config-custom": "workspace:*",
|
|
174
|
-
shadcn: "3.6.2",
|
|
175
|
-
tsconfig: "workspace:*"
|
|
176
|
-
},
|
|
177
|
-
publishConfig: {
|
|
178
|
-
access: "public"
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
// src/commands/customise.ts
|
|
183
|
-
import { cancel, group, intro as intro2, log as log4, outro as outro3, select } from "@clack/prompts";
|
|
184
|
-
import picocolors2 from "picocolors";
|
|
185
|
-
|
|
186
|
-
// src/commands/add.ts
|
|
187
|
-
import {
|
|
188
|
-
intro,
|
|
189
|
-
isCancel as isCancel3,
|
|
190
|
-
log as log3,
|
|
191
|
-
multiselect,
|
|
192
|
-
outro as outro2,
|
|
193
|
-
spinner as spinner2
|
|
194
|
-
} from "@clack/prompts";
|
|
195
|
-
import picocolors from "picocolors";
|
|
196
|
-
|
|
197
|
-
// src/registry/installer/index.ts
|
|
198
|
-
import path4 from "path";
|
|
199
|
-
import fs5 from "fs/promises";
|
|
200
|
-
import { confirm as confirm2, isCancel as isCancel2, log as log2, outro } from "@clack/prompts";
|
|
201
|
-
|
|
202
|
-
// src/utils/typescript.ts
|
|
203
|
-
import { Project } from "ts-morph";
|
|
204
|
-
function createEmptyProject() {
|
|
205
|
-
return new Project({
|
|
206
|
-
compilerOptions: {}
|
|
207
|
-
});
|
|
111
|
+
const out = await x("tree", [
|
|
112
|
+
args,
|
|
113
|
+
"--gitignore",
|
|
114
|
+
"--prune",
|
|
115
|
+
"-J"
|
|
116
|
+
]);
|
|
117
|
+
try {
|
|
118
|
+
return JSON.parse(out.stdout);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
throw new Error("failed to run `tree` command", { cause: e });
|
|
121
|
+
}
|
|
208
122
|
}
|
|
209
123
|
|
|
210
|
-
|
|
211
|
-
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region package.json
|
|
126
|
+
var version = "1.2.2";
|
|
212
127
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (removeExt && importPath.endsWith("/index")) {
|
|
223
|
-
importPath = importPath.slice(0, -"/index".length);
|
|
224
|
-
}
|
|
225
|
-
return importPath.startsWith("../") ? importPath : `./${importPath}`;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// src/registry/schema.ts
|
|
229
|
-
import { z as z2 } from "zod";
|
|
230
|
-
var namespaces = [
|
|
231
|
-
"components",
|
|
232
|
-
"lib",
|
|
233
|
-
"css",
|
|
234
|
-
"route",
|
|
235
|
-
"ui",
|
|
236
|
-
"block"
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/registry/schema.ts
|
|
130
|
+
const namespaces = [
|
|
131
|
+
"components",
|
|
132
|
+
"lib",
|
|
133
|
+
"css",
|
|
134
|
+
"route",
|
|
135
|
+
"ui",
|
|
136
|
+
"block"
|
|
237
137
|
];
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
138
|
+
const indexSchema = z.object({
|
|
139
|
+
name: z.string(),
|
|
140
|
+
title: z.string().optional(),
|
|
141
|
+
description: z.string().optional()
|
|
242
142
|
});
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
143
|
+
const fileSchema = z.object({
|
|
144
|
+
type: z.literal(namespaces),
|
|
145
|
+
path: z.string(),
|
|
146
|
+
target: z.string().optional(),
|
|
147
|
+
content: z.string()
|
|
248
148
|
});
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
149
|
+
const httpSubComponent = z.object({
|
|
150
|
+
type: z.literal("http"),
|
|
151
|
+
baseUrl: z.string(),
|
|
152
|
+
component: z.string()
|
|
253
153
|
});
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
* list of sub components, either local (component name) or remote (registry info & component name)
|
|
263
|
-
*/
|
|
264
|
-
subComponents: z2.array(z2.string().or(httpSubComponent)).default([])
|
|
154
|
+
const componentSchema = z.object({
|
|
155
|
+
name: z.string(),
|
|
156
|
+
title: z.string().optional(),
|
|
157
|
+
description: z.string().optional(),
|
|
158
|
+
files: z.array(fileSchema),
|
|
159
|
+
dependencies: z.record(z.string(), z.string().or(z.null())),
|
|
160
|
+
devDependencies: z.record(z.string(), z.string().or(z.null())),
|
|
161
|
+
subComponents: z.array(z.string().or(httpSubComponent)).default([])
|
|
265
162
|
});
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
default: z2.unknown().optional()
|
|
275
|
-
})
|
|
276
|
-
).optional(),
|
|
277
|
-
/**
|
|
278
|
-
* provide variables to sub components
|
|
279
|
-
*/
|
|
280
|
-
env: z2.record(z2.string(), z2.unknown()).optional(),
|
|
281
|
-
indexes: z2.array(indexSchema).default([]),
|
|
282
|
-
registries: z2.array(z2.string()).optional()
|
|
163
|
+
const registryInfoSchema = z.object({
|
|
164
|
+
variables: z.record(z.string(), z.object({
|
|
165
|
+
description: z.string().optional(),
|
|
166
|
+
default: z.unknown().optional()
|
|
167
|
+
})).optional(),
|
|
168
|
+
env: z.record(z.string(), z.unknown()).optional(),
|
|
169
|
+
indexes: z.array(indexSchema).default([]),
|
|
170
|
+
registries: z.array(z.string()).optional()
|
|
283
171
|
});
|
|
284
172
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/utils/cache.ts
|
|
175
|
+
/**
|
|
176
|
+
* cache for async resources, finished promises will be resolved into original value, otherwise wrapped with a promise.
|
|
177
|
+
*/
|
|
178
|
+
function createCache(store = /* @__PURE__ */ new Map()) {
|
|
179
|
+
return {
|
|
180
|
+
cached(key, fn) {
|
|
181
|
+
let cached = store.get(key);
|
|
182
|
+
if (cached) return cached;
|
|
183
|
+
cached = fn((v) => store.set(key, v));
|
|
184
|
+
if (cached instanceof Promise) cached = cached.then((out) => {
|
|
185
|
+
if (store.has(key)) store.set(key, out);
|
|
186
|
+
return out;
|
|
187
|
+
});
|
|
188
|
+
store.set(key, cached);
|
|
189
|
+
return cached;
|
|
190
|
+
},
|
|
191
|
+
invalidate(key) {
|
|
192
|
+
store.delete(key);
|
|
193
|
+
},
|
|
194
|
+
$value() {
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
303
199
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
return new _HttpRegistryClient(`${this.baseUrl}/${name}`, this.config);
|
|
340
|
-
}
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/registry/client.ts
|
|
202
|
+
const fetchCache = createCache();
|
|
203
|
+
var HttpRegistryClient = class HttpRegistryClient {
|
|
204
|
+
constructor(baseUrl, config) {
|
|
205
|
+
this.baseUrl = baseUrl;
|
|
206
|
+
this.config = config;
|
|
207
|
+
this.registryId = baseUrl;
|
|
208
|
+
}
|
|
209
|
+
async fetchRegistryInfo(baseUrl = this.baseUrl) {
|
|
210
|
+
const url = new URL("_registry.json", `${baseUrl}/`);
|
|
211
|
+
return fetchCache.$value().cached(url.href, async () => {
|
|
212
|
+
const res = await fetch(url);
|
|
213
|
+
if (!res.ok) throw new Error(`failed to fetch ${url.href}: ${res.statusText}`);
|
|
214
|
+
return registryInfoSchema.parse(await res.json());
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
async fetchComponent(name) {
|
|
218
|
+
const url = new URL(`${name}.json`, `${this.baseUrl}/`);
|
|
219
|
+
return fetchCache.$value().cached(url.href, async () => {
|
|
220
|
+
const res = await fetch(`${this.baseUrl}/${name}.json`);
|
|
221
|
+
if (!res.ok) {
|
|
222
|
+
log.error(`component ${name} not found at ${url.href}`);
|
|
223
|
+
throw new Error(await res.text());
|
|
224
|
+
}
|
|
225
|
+
return componentSchema.parse(await res.json());
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
async hasComponent(name) {
|
|
229
|
+
const url = new URL(`${name}.json`, `${this.baseUrl}/`);
|
|
230
|
+
return (await fetch(url, { method: "HEAD" })).ok;
|
|
231
|
+
}
|
|
232
|
+
createLinkedRegistryClient(name) {
|
|
233
|
+
return new HttpRegistryClient(`${this.baseUrl}/${name}`, this.config);
|
|
234
|
+
}
|
|
341
235
|
};
|
|
342
|
-
var LocalRegistryClient = class
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
return new _LocalRegistryClient(path3.join(this.dir, name), this.config);
|
|
377
|
-
}
|
|
236
|
+
var LocalRegistryClient = class LocalRegistryClient {
|
|
237
|
+
constructor(dir, config) {
|
|
238
|
+
this.dir = dir;
|
|
239
|
+
this.config = config;
|
|
240
|
+
this.registryId = dir;
|
|
241
|
+
}
|
|
242
|
+
async fetchRegistryInfo(dir = this.dir) {
|
|
243
|
+
if (this.registryInfo) return this.registryInfo;
|
|
244
|
+
const filePath = path.join(dir, "_registry.json");
|
|
245
|
+
const out = await fs.readFile(filePath).then((res) => JSON.parse(res.toString())).catch((e) => {
|
|
246
|
+
throw new Error(`failed to resolve local file "${filePath}"`, { cause: e });
|
|
247
|
+
});
|
|
248
|
+
return this.registryInfo = registryInfoSchema.parse(out);
|
|
249
|
+
}
|
|
250
|
+
async fetchComponent(name) {
|
|
251
|
+
const filePath = path.join(this.dir, `${name}.json`);
|
|
252
|
+
const out = await fs.readFile(filePath).then((res) => JSON.parse(res.toString())).catch((e) => {
|
|
253
|
+
log.error(`component ${name} not found at ${filePath}`);
|
|
254
|
+
throw e;
|
|
255
|
+
});
|
|
256
|
+
return componentSchema.parse(out);
|
|
257
|
+
}
|
|
258
|
+
async hasComponent(name) {
|
|
259
|
+
const filePath = path.join(this.dir, `${name}.json`);
|
|
260
|
+
try {
|
|
261
|
+
await fs.stat(filePath);
|
|
262
|
+
return true;
|
|
263
|
+
} catch {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
createLinkedRegistryClient(name) {
|
|
268
|
+
return new LocalRegistryClient(path.join(this.dir, name), this.config);
|
|
269
|
+
}
|
|
378
270
|
};
|
|
379
271
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
// src/registry/installer/dep-manager.ts
|
|
384
|
-
import fs4 from "fs/promises";
|
|
385
|
-
|
|
386
|
-
// src/utils/get-package-manager.ts
|
|
387
|
-
import { detect } from "package-manager-detector";
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/utils/get-package-manager.ts
|
|
388
274
|
async function getPackageManager() {
|
|
389
|
-
|
|
390
|
-
return result?.name ?? "npm";
|
|
275
|
+
return (await detect())?.name ?? "npm";
|
|
391
276
|
}
|
|
392
277
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
import { x as x2 } from "tinyexec";
|
|
278
|
+
//#endregion
|
|
279
|
+
//#region src/registry/installer/dep-manager.ts
|
|
396
280
|
var DependencyManager = class {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
if (items.length > 0) await x2(manager, ["install", ...items]);
|
|
439
|
-
if (devItems.length > 0) await x2(manager, ["install", ...devItems, "-D"]);
|
|
440
|
-
spin.stop("Dependencies installed.");
|
|
441
|
-
}
|
|
281
|
+
/**
|
|
282
|
+
* Get dependencies from `package.json`
|
|
283
|
+
*/
|
|
284
|
+
async getDeps() {
|
|
285
|
+
if (this.cachedInstalledDeps) return this.cachedInstalledDeps;
|
|
286
|
+
const dependencies = /* @__PURE__ */ new Map();
|
|
287
|
+
if (!await exists("package.json")) return dependencies;
|
|
288
|
+
const content = await fs.readFile("package.json");
|
|
289
|
+
const parsed = JSON.parse(content.toString());
|
|
290
|
+
if ("dependencies" in parsed && typeof parsed.dependencies === "object") {
|
|
291
|
+
const records = parsed.dependencies;
|
|
292
|
+
for (const [k, v] of Object.entries(records)) dependencies.set(k, v);
|
|
293
|
+
}
|
|
294
|
+
if ("devDependencies" in parsed && typeof parsed.devDependencies === "object") {
|
|
295
|
+
const records = parsed.devDependencies;
|
|
296
|
+
for (const [k, v] of Object.entries(records)) dependencies.set(k, v);
|
|
297
|
+
}
|
|
298
|
+
return this.cachedInstalledDeps = dependencies;
|
|
299
|
+
}
|
|
300
|
+
async resolveInstallDependencies(deps) {
|
|
301
|
+
const cachedInstalledDeps = await this.getDeps();
|
|
302
|
+
return Object.entries(deps).filter(([k]) => !cachedInstalledDeps.has(k)).map(([k, v]) => v === null || v.length === 0 ? k : `${k}@${v}`);
|
|
303
|
+
}
|
|
304
|
+
async installDeps(deps, devDeps) {
|
|
305
|
+
const items = await this.resolveInstallDependencies(deps);
|
|
306
|
+
const devItems = await this.resolveInstallDependencies(devDeps);
|
|
307
|
+
if (items.length === 0 && devItems.length === 0) return;
|
|
308
|
+
const manager = await getPackageManager();
|
|
309
|
+
const value = await confirm({ message: `Do you want to install with ${manager}?
|
|
310
|
+
${[...items, ...devItems].map((v) => `- ${v}`).join("\n")}` });
|
|
311
|
+
if (isCancel(value) || !value) return;
|
|
312
|
+
const spin = spinner();
|
|
313
|
+
spin.start("Installing dependencies...");
|
|
314
|
+
if (items.length > 0) await x(manager, ["install", ...items]);
|
|
315
|
+
if (devItems.length > 0) await x(manager, [
|
|
316
|
+
"install",
|
|
317
|
+
...devItems,
|
|
318
|
+
"-D"
|
|
319
|
+
]);
|
|
320
|
+
spin.stop("Dependencies installed.");
|
|
321
|
+
}
|
|
442
322
|
};
|
|
443
323
|
|
|
444
|
-
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region src/registry/installer/index.ts
|
|
445
326
|
var ComponentInstaller = class {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
);
|
|
570
|
-
} else {
|
|
571
|
-
console.warn(`cannot find the referenced file of ${specifier}`);
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
for (const plugin of this.plugins) {
|
|
576
|
-
await plugin.transform?.({
|
|
577
|
-
file: sourceFile,
|
|
578
|
-
componentFile: file,
|
|
579
|
-
component
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
return sourceFile.getFullText();
|
|
583
|
-
}
|
|
584
|
-
resolveOutputPath(file) {
|
|
585
|
-
const config = this.rootClient.config;
|
|
586
|
-
const dir = {
|
|
587
|
-
components: config.aliases.componentsDir,
|
|
588
|
-
block: config.aliases.blockDir,
|
|
589
|
-
ui: config.aliases.uiDir,
|
|
590
|
-
css: config.aliases.cssDir,
|
|
591
|
-
lib: config.aliases.libDir,
|
|
592
|
-
route: "./"
|
|
593
|
-
}[file.type];
|
|
594
|
-
if (file.target) {
|
|
595
|
-
return path4.join(config.baseDir, file.target.replace("<dir>", dir));
|
|
596
|
-
}
|
|
597
|
-
return path4.join(config.baseDir, dir, path4.basename(file.path));
|
|
598
|
-
}
|
|
327
|
+
constructor(rootClient, plugins = []) {
|
|
328
|
+
this.rootClient = rootClient;
|
|
329
|
+
this.plugins = plugins;
|
|
330
|
+
this.installedFiles = /* @__PURE__ */ new Set();
|
|
331
|
+
this.downloadCache = createCache();
|
|
332
|
+
this.dependencies = {};
|
|
333
|
+
this.devDependencies = {};
|
|
334
|
+
this.pathToFileCache = createCache();
|
|
335
|
+
}
|
|
336
|
+
async install(name) {
|
|
337
|
+
let downloaded;
|
|
338
|
+
const info = await this.rootClient.fetchRegistryInfo();
|
|
339
|
+
for (const registry of info.registries ?? []) if (name.startsWith(`${registry}/`)) {
|
|
340
|
+
downloaded = await this.download(name.slice(registry.length + 1), this.rootClient.createLinkedRegistryClient(registry));
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
downloaded ??= await this.download(name, this.rootClient);
|
|
344
|
+
for (const item of downloaded) {
|
|
345
|
+
Object.assign(this.dependencies, item.dependencies);
|
|
346
|
+
Object.assign(this.devDependencies, item.devDependencies);
|
|
347
|
+
}
|
|
348
|
+
for (const comp of downloaded) for (const file of comp.files) {
|
|
349
|
+
const outPath = this.resolveOutputPath(file);
|
|
350
|
+
if (this.installedFiles.has(outPath)) continue;
|
|
351
|
+
this.installedFiles.add(outPath);
|
|
352
|
+
const output = typescriptExtensions.includes(path.extname(outPath)) ? await this.transform(name, file, comp, downloaded) : file.content;
|
|
353
|
+
const status = await fs.readFile(outPath).then((res) => {
|
|
354
|
+
if (res.toString() === output) return "ignore";
|
|
355
|
+
return "need-update";
|
|
356
|
+
}).catch(() => "write");
|
|
357
|
+
if (status === "ignore") continue;
|
|
358
|
+
if (status === "need-update") {
|
|
359
|
+
const override = await confirm({
|
|
360
|
+
message: `Do you want to override ${outPath}?`,
|
|
361
|
+
initialValue: false
|
|
362
|
+
});
|
|
363
|
+
if (isCancel(override)) {
|
|
364
|
+
outro("Ended");
|
|
365
|
+
process.exit(0);
|
|
366
|
+
}
|
|
367
|
+
if (!override) continue;
|
|
368
|
+
}
|
|
369
|
+
await fs.mkdir(path.dirname(outPath), { recursive: true });
|
|
370
|
+
await fs.writeFile(outPath, output);
|
|
371
|
+
log.step(`downloaded ${outPath}`);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
async installDeps() {
|
|
375
|
+
await new DependencyManager().installDeps(this.dependencies, this.devDependencies);
|
|
376
|
+
}
|
|
377
|
+
async onEnd() {
|
|
378
|
+
const config = this.rootClient.config;
|
|
379
|
+
if (config.commands.format) await x(config.commands.format);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* return a list of components, merged with child components & variables.
|
|
383
|
+
*/
|
|
384
|
+
async download(name, client, contextVariables) {
|
|
385
|
+
const hash = `${client.registryId} ${name}`;
|
|
386
|
+
const info = await client.fetchRegistryInfo();
|
|
387
|
+
const variables = {
|
|
388
|
+
...contextVariables,
|
|
389
|
+
...info.env
|
|
390
|
+
};
|
|
391
|
+
for (const [k, v] of Object.entries(info.variables ?? {})) variables[k] ??= v.default;
|
|
392
|
+
return (await this.downloadCache.cached(hash, async (presolve) => {
|
|
393
|
+
const comp = await client.fetchComponent(name);
|
|
394
|
+
const result = [comp];
|
|
395
|
+
presolve(result);
|
|
396
|
+
const child = await Promise.all(comp.subComponents.map((sub) => {
|
|
397
|
+
if (typeof sub === "string") return this.download(sub, client);
|
|
398
|
+
const baseUrl = this.rootClient instanceof HttpRegistryClient ? new URL(sub.baseUrl, `${this.rootClient.baseUrl}/`).href : sub.baseUrl;
|
|
399
|
+
return this.download(sub.component, new HttpRegistryClient(baseUrl, client.config), variables);
|
|
400
|
+
}));
|
|
401
|
+
for (const sub of child) result.push(...sub);
|
|
402
|
+
return result;
|
|
403
|
+
})).map((file) => ({
|
|
404
|
+
...file,
|
|
405
|
+
variables
|
|
406
|
+
}));
|
|
407
|
+
}
|
|
408
|
+
async transform(taskId, file, component, allComponents) {
|
|
409
|
+
const filePath = this.resolveOutputPath(file);
|
|
410
|
+
const parsed = await parse(filePath, file.content);
|
|
411
|
+
const s = new MagicString(file.content);
|
|
412
|
+
const prefix = "@/";
|
|
413
|
+
const variables = Object.entries(component.variables ?? {});
|
|
414
|
+
const pathToFile = await this.pathToFileCache.cached(taskId, () => {
|
|
415
|
+
const map = /* @__PURE__ */ new Map();
|
|
416
|
+
for (const comp of allComponents) for (const file$1 of comp.files) map.set(file$1.target ?? file$1.path, file$1);
|
|
417
|
+
return map;
|
|
418
|
+
});
|
|
419
|
+
transformSpecifiers(parsed.program, s, (specifier) => {
|
|
420
|
+
for (const [k, v] of variables) specifier = specifier.replaceAll(`<${k}>`, v);
|
|
421
|
+
if (specifier.startsWith(prefix)) {
|
|
422
|
+
const lookup = specifier.substring(2);
|
|
423
|
+
const target = pathToFile.get(lookup);
|
|
424
|
+
if (target) specifier = toImportSpecifier(filePath, this.resolveOutputPath(target));
|
|
425
|
+
else console.warn(`cannot find the referenced file of ${specifier}`);
|
|
426
|
+
}
|
|
427
|
+
return specifier;
|
|
428
|
+
});
|
|
429
|
+
for (const plugin of this.plugins) await plugin.transformFile?.({
|
|
430
|
+
s,
|
|
431
|
+
parsed,
|
|
432
|
+
file,
|
|
433
|
+
component
|
|
434
|
+
});
|
|
435
|
+
return s.toString();
|
|
436
|
+
}
|
|
437
|
+
resolveOutputPath(file) {
|
|
438
|
+
const config = this.rootClient.config;
|
|
439
|
+
const dir = {
|
|
440
|
+
components: config.aliases.componentsDir,
|
|
441
|
+
block: config.aliases.blockDir,
|
|
442
|
+
ui: config.aliases.uiDir,
|
|
443
|
+
css: config.aliases.cssDir,
|
|
444
|
+
lib: config.aliases.libDir,
|
|
445
|
+
route: "./"
|
|
446
|
+
}[file.type];
|
|
447
|
+
if (file.target) return path.join(config.baseDir, file.target.replace("<dir>", dir));
|
|
448
|
+
return path.join(config.baseDir, dir, path.basename(file.path));
|
|
449
|
+
}
|
|
599
450
|
};
|
|
600
451
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
452
|
+
//#endregion
|
|
453
|
+
//#region src/commands/shared.ts
|
|
454
|
+
const UIRegistries = {
|
|
455
|
+
"base-ui": "fumadocs/base-ui",
|
|
456
|
+
"radix-ui": "fumadocs/radix-ui"
|
|
605
457
|
};
|
|
606
458
|
|
|
607
|
-
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region src/commands/add.ts
|
|
608
461
|
async function add(input, client) {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
}
|
|
642
|
-
target = value;
|
|
643
|
-
} else {
|
|
644
|
-
target = await Promise.all(
|
|
645
|
-
input.map(
|
|
646
|
-
async (item) => await client.hasComponent(item) ? item : `${registry}/${item}`
|
|
647
|
-
)
|
|
648
|
-
);
|
|
649
|
-
}
|
|
650
|
-
await install(target, installer);
|
|
462
|
+
const config = client.config;
|
|
463
|
+
let target;
|
|
464
|
+
const installer = new ComponentInstaller(client);
|
|
465
|
+
const registry = UIRegistries[config.uiLibrary];
|
|
466
|
+
if (input.length === 0) {
|
|
467
|
+
const spin = spinner();
|
|
468
|
+
spin.start("fetching registry");
|
|
469
|
+
const info = await client.fetchRegistryInfo();
|
|
470
|
+
const options = [];
|
|
471
|
+
for (const item of info.indexes) options.push({
|
|
472
|
+
label: item.title ?? item.name,
|
|
473
|
+
value: item.name,
|
|
474
|
+
hint: item.description
|
|
475
|
+
});
|
|
476
|
+
const { indexes } = await client.createLinkedRegistryClient(registry).fetchRegistryInfo();
|
|
477
|
+
for (const item of indexes) options.push({
|
|
478
|
+
label: item.title ?? item.name,
|
|
479
|
+
value: `${registry}/${item.name}`,
|
|
480
|
+
hint: item.description
|
|
481
|
+
});
|
|
482
|
+
spin.stop(picocolors.bold(picocolors.greenBright("registry fetched")));
|
|
483
|
+
const value = await multiselect({
|
|
484
|
+
message: "Select components to install",
|
|
485
|
+
options
|
|
486
|
+
});
|
|
487
|
+
if (isCancel(value)) {
|
|
488
|
+
outro("Ended");
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
target = value;
|
|
492
|
+
} else target = await Promise.all(input.map(async (item) => await client.hasComponent(item) ? item : `${registry}/${item}`));
|
|
493
|
+
await install(target, installer);
|
|
651
494
|
}
|
|
652
495
|
async function install(target, installer) {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
intro(picocolors.bold("New Dependencies"));
|
|
668
|
-
await installer.installDeps();
|
|
669
|
-
await installer.onEnd();
|
|
670
|
-
outro2(picocolors.bold(picocolors.greenBright("Successful")));
|
|
496
|
+
for (const name of target) {
|
|
497
|
+
intro(picocolors.bold(picocolors.inverse(picocolors.cyanBright(`Add Component: ${name}`))));
|
|
498
|
+
try {
|
|
499
|
+
await installer.install(name);
|
|
500
|
+
outro(picocolors.bold(picocolors.greenBright(`${name} installed`)));
|
|
501
|
+
} catch (e) {
|
|
502
|
+
log.error(String(e));
|
|
503
|
+
throw e;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
intro(picocolors.bold("New Dependencies"));
|
|
507
|
+
await installer.installDeps();
|
|
508
|
+
await installer.onEnd();
|
|
509
|
+
outro(picocolors.bold(picocolors.greenBright("Successful")));
|
|
671
510
|
}
|
|
672
511
|
|
|
673
|
-
|
|
512
|
+
//#endregion
|
|
513
|
+
//#region src/commands/customise.ts
|
|
674
514
|
async function customise(client) {
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
} else {
|
|
732
|
-
targets.push(
|
|
733
|
-
result.mode === "full-default" ? `${registry}/layouts/docs` : `${registry}/layouts/notebook`
|
|
734
|
-
);
|
|
735
|
-
}
|
|
736
|
-
await install(targets, installer);
|
|
737
|
-
const maps = result.mode === "full-notebook" ? [
|
|
738
|
-
["fumadocs-ui/layouts/notebook", "@/components/layout/notebook"],
|
|
739
|
-
[
|
|
740
|
-
"fumadocs-ui/layouts/notebook/page",
|
|
741
|
-
"@/components/layout/notebook/page"
|
|
742
|
-
]
|
|
743
|
-
] : [
|
|
744
|
-
["fumadocs-ui/layouts/docs", "@/components/layout/docs"],
|
|
745
|
-
["fumadocs-ui/layouts/docs/page", "@/components/layout/docs/page"]
|
|
746
|
-
];
|
|
747
|
-
printNext(...maps);
|
|
748
|
-
}
|
|
749
|
-
if (result.target === "home") {
|
|
750
|
-
await install([`${registry}/layouts/home`], installer);
|
|
751
|
-
printNext(["fumadocs-ui/layouts/home", `@/components/layout/home`]);
|
|
752
|
-
}
|
|
753
|
-
outro3(picocolors2.bold("Have fun!"));
|
|
515
|
+
intro(picocolors.bgBlack(picocolors.whiteBright("Customise Fumadocs UI")));
|
|
516
|
+
const config = client.config;
|
|
517
|
+
const installer = new ComponentInstaller(client);
|
|
518
|
+
const result = await group({
|
|
519
|
+
target: () => select({
|
|
520
|
+
message: "What do you want to customise?",
|
|
521
|
+
options: [{
|
|
522
|
+
label: "Docs Layout",
|
|
523
|
+
value: "docs",
|
|
524
|
+
hint: "main UI of your docs"
|
|
525
|
+
}, {
|
|
526
|
+
label: "Home Layout",
|
|
527
|
+
value: "home",
|
|
528
|
+
hint: "the navbar for your other pages"
|
|
529
|
+
}]
|
|
530
|
+
}),
|
|
531
|
+
mode: (v) => {
|
|
532
|
+
if (v.results.target !== "docs") return;
|
|
533
|
+
return select({
|
|
534
|
+
message: "Which variant do you want to start from?",
|
|
535
|
+
options: [
|
|
536
|
+
{
|
|
537
|
+
label: "Start from minimal styles",
|
|
538
|
+
value: "minimal",
|
|
539
|
+
hint: "for those who want to build their own variant from ground up."
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
label: "Start from default layout",
|
|
543
|
+
value: "full-default",
|
|
544
|
+
hint: "useful for adjusting small details."
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
label: "Start from Notebook layout",
|
|
548
|
+
value: "full-notebook",
|
|
549
|
+
hint: "useful for adjusting small details."
|
|
550
|
+
}
|
|
551
|
+
]
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
}, { onCancel: () => {
|
|
555
|
+
cancel("Installation Stopped.");
|
|
556
|
+
process.exit(0);
|
|
557
|
+
} });
|
|
558
|
+
const registry = UIRegistries[config.uiLibrary];
|
|
559
|
+
if (result.target === "docs") {
|
|
560
|
+
const targets = [];
|
|
561
|
+
if (result.mode === "minimal") targets.push("fumadocs/ui/layouts/docs-min");
|
|
562
|
+
else targets.push(result.mode === "full-default" ? `${registry}/layouts/docs` : `${registry}/layouts/notebook`);
|
|
563
|
+
await install(targets, installer);
|
|
564
|
+
printNext(...result.mode === "full-notebook" ? [["fumadocs-ui/layouts/notebook", "@/components/layout/notebook"], ["fumadocs-ui/layouts/notebook/page", "@/components/layout/notebook/page"]] : [["fumadocs-ui/layouts/docs", "@/components/layout/docs"], ["fumadocs-ui/layouts/docs/page", "@/components/layout/docs/page"]]);
|
|
565
|
+
}
|
|
566
|
+
if (result.target === "home") {
|
|
567
|
+
await install([`${registry}/layouts/home`], installer);
|
|
568
|
+
printNext(["fumadocs-ui/layouts/home", `@/components/layout/home`]);
|
|
569
|
+
}
|
|
570
|
+
outro(picocolors.bold("Have fun!"));
|
|
754
571
|
}
|
|
755
572
|
function printNext(...maps) {
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
([from, to]) => picocolors2.greenBright(`"${from}" -> "${to}"`)
|
|
764
|
-
)
|
|
765
|
-
].join("\n")
|
|
766
|
-
);
|
|
573
|
+
intro(picocolors.bold("What is Next?"));
|
|
574
|
+
log.info([
|
|
575
|
+
"You can check the installed components in `components`.",
|
|
576
|
+
picocolors.dim("---"),
|
|
577
|
+
"Open your `layout.tsx` files, replace the imports of components:",
|
|
578
|
+
...maps.map(([from, to]) => picocolors.greenBright(`"${from}" -> "${to}"`))
|
|
579
|
+
].join("\n"));
|
|
767
580
|
}
|
|
768
581
|
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
program
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
console.log(picocolors3.redBright("A config file already exists."));
|
|
776
|
-
}
|
|
582
|
+
//#endregion
|
|
583
|
+
//#region src/index.ts
|
|
584
|
+
const program = new Command().option("--config <string>");
|
|
585
|
+
program.name("fumadocs").description("CLI to setup Fumadocs, init a config").version(version).action(async () => {
|
|
586
|
+
if (await initConfig()) console.log(picocolors.green("Initialized a `./cli.json` config file."));
|
|
587
|
+
else console.log(picocolors.redBright("A config file already exists."));
|
|
777
588
|
});
|
|
778
589
|
program.command("customise").alias("customize").description("simple way to customise layouts with Fumadocs UI").option("--dir <string>", "the root url or directory to resolve registry").action(async (options) => {
|
|
779
|
-
|
|
780
|
-
createClientFromDir(
|
|
781
|
-
options.dir,
|
|
782
|
-
await createOrLoadConfig(options.config)
|
|
783
|
-
)
|
|
784
|
-
);
|
|
590
|
+
await customise(createClientFromDir(options.dir, await createOrLoadConfig(options.config)));
|
|
785
591
|
});
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
592
|
+
const dirShortcuts = {
|
|
593
|
+
":preview": "https://preview.fumadocs.dev/registry",
|
|
594
|
+
":dev": "http://localhost:3000/registry"
|
|
789
595
|
};
|
|
790
|
-
program.command("add").description("add a new component to your docs").argument("[components...]", "components to download").option("--dir <string>", "the root url or directory to resolve registry").action(
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
nodes = JSON.parse(str ?? "");
|
|
813
|
-
} catch {
|
|
814
|
-
nodes = await runTree(str ?? "./");
|
|
815
|
-
}
|
|
816
|
-
const out = js || output && jsExtensions.includes(path5.extname(output)) ? treeToJavaScript(nodes, noRoot, importName) : treeToMdx(nodes, noRoot);
|
|
817
|
-
if (output) {
|
|
818
|
-
await fs6.mkdir(path5.dirname(output), { recursive: true });
|
|
819
|
-
await fs6.writeFile(output, out);
|
|
820
|
-
} else {
|
|
821
|
-
console.log(out);
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
);
|
|
596
|
+
program.command("add").description("add a new component to your docs").argument("[components...]", "components to download").option("--dir <string>", "the root url or directory to resolve registry").action(async (input, options) => {
|
|
597
|
+
await add(input, createClientFromDir(options.dir, await createOrLoadConfig(options.config)));
|
|
598
|
+
});
|
|
599
|
+
program.command("tree").argument("[json_or_args]", "JSON output of `tree` command or arguments for the `tree` command").argument("[output]", "output path of file").option("--js", "output as JavaScript file").option("--no-root", "remove the root node").option("--import-name <name>", "where to import components (JS only)").action(async (str, output, { js, root, importName }) => {
|
|
600
|
+
const jsExtensions = [
|
|
601
|
+
".js",
|
|
602
|
+
".tsx",
|
|
603
|
+
".jsx"
|
|
604
|
+
];
|
|
605
|
+
const noRoot = !root;
|
|
606
|
+
let nodes;
|
|
607
|
+
try {
|
|
608
|
+
nodes = JSON.parse(str ?? "");
|
|
609
|
+
} catch {
|
|
610
|
+
nodes = await runTree(str ?? "./");
|
|
611
|
+
}
|
|
612
|
+
const out = js || output && jsExtensions.includes(path.extname(output)) ? treeToJavaScript(nodes, noRoot, importName) : treeToMdx(nodes, noRoot);
|
|
613
|
+
if (output) {
|
|
614
|
+
await fs.mkdir(path.dirname(output), { recursive: true });
|
|
615
|
+
await fs.writeFile(output, out);
|
|
616
|
+
} else console.log(out);
|
|
617
|
+
});
|
|
825
618
|
function createClientFromDir(dir = "https://fumadocs.dev/registry", config) {
|
|
826
|
-
|
|
827
|
-
|
|
619
|
+
if (dir in dirShortcuts) dir = dirShortcuts[dir];
|
|
620
|
+
return dir.startsWith("http://") || dir.startsWith("https://") ? new HttpRegistryClient(dir, config) : new LocalRegistryClient(dir, config);
|
|
828
621
|
}
|
|
829
622
|
program.parse();
|
|
623
|
+
|
|
624
|
+
//#endregion
|
|
625
|
+
export { };
|
|
626
|
+
//# sourceMappingURL=index.js.map
|