@fumadocs/cli 0.0.2 → 0.0.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/dist/build/index.d.ts +8 -3
- package/dist/build/index.js +41 -17
- package/dist/index.js +11 -11
- package/package.json +7 -7
package/dist/build/index.d.ts
CHANGED
|
@@ -79,17 +79,22 @@ interface DependencyInfo {
|
|
|
79
79
|
version?: string;
|
|
80
80
|
}
|
|
81
81
|
interface ComponentBuilder {
|
|
82
|
-
rootDir: string;
|
|
83
82
|
registryDir: string;
|
|
84
83
|
resolveDep: (specifier: string) => DependencyInfo & {
|
|
85
84
|
name: string;
|
|
86
85
|
};
|
|
87
|
-
resolveOutputPath: (path: string) => string;
|
|
86
|
+
resolveOutputPath: (path: string, namespace?: string) => string;
|
|
88
87
|
getSubComponent: (path: string) => {
|
|
89
88
|
component: Component;
|
|
90
89
|
} | undefined;
|
|
91
90
|
}
|
|
92
|
-
|
|
91
|
+
/**
|
|
92
|
+
* @param registry registry object
|
|
93
|
+
* @param packageJson parsed package json object
|
|
94
|
+
* @param registryDir directory of registry config file
|
|
95
|
+
* @param sourceDir source directory of project (e.g. `/src`), used to resolve the output paths of component files
|
|
96
|
+
*/
|
|
97
|
+
declare function createComponentBuilder(registry: Registry, packageJson: PackageJson | undefined, registryDir: string, sourceDir: string): ComponentBuilder;
|
|
93
98
|
|
|
94
99
|
declare function writeOutput(dir: string, out: Output, options?: {
|
|
95
100
|
/**
|
package/dist/build/index.js
CHANGED
|
@@ -102,7 +102,7 @@ function merge(to, from) {
|
|
|
102
102
|
|
|
103
103
|
// src/build/component-builder.ts
|
|
104
104
|
import path2 from "node:path";
|
|
105
|
-
function createComponentBuilder(registry, packageJson, registryDir,
|
|
105
|
+
function createComponentBuilder(registry, packageJson, registryDir, sourceDir) {
|
|
106
106
|
const fileToComponent = /* @__PURE__ */ new Map();
|
|
107
107
|
for (const comp of registry.components) {
|
|
108
108
|
for (const file of comp.files) {
|
|
@@ -115,7 +115,6 @@ function createComponentBuilder(registry, packageJson, registryDir, rootDir) {
|
|
|
115
115
|
}
|
|
116
116
|
return {
|
|
117
117
|
registryDir,
|
|
118
|
-
rootDir,
|
|
119
118
|
resolveDep(specifier) {
|
|
120
119
|
const name = specifier.startsWith("@") ? specifier.split("/").slice(0, 2).join("/") : specifier.split("/")[0];
|
|
121
120
|
if (registry.dependencies && name in registry.dependencies)
|
|
@@ -139,16 +138,19 @@ function createComponentBuilder(registry, packageJson, registryDir, rootDir) {
|
|
|
139
138
|
}
|
|
140
139
|
return { type: "runtime", name };
|
|
141
140
|
},
|
|
142
|
-
resolveOutputPath(file) {
|
|
141
|
+
resolveOutputPath(file, forcedNamespace) {
|
|
143
142
|
const relativeFile = path2.relative(registryDir, file);
|
|
143
|
+
if (forcedNamespace) {
|
|
144
|
+
return `${forcedNamespace}:${path2.relative(sourceDir, file)}`;
|
|
145
|
+
}
|
|
144
146
|
if (registry.namespaces)
|
|
145
147
|
for (const namespace of Object.keys(registry.namespaces)) {
|
|
146
148
|
const relativePath = path2.relative(namespace, relativeFile);
|
|
147
|
-
if (relativePath.startsWith("../")
|
|
148
|
-
|
|
149
|
-
|
|
149
|
+
if (!relativePath.startsWith("../") && !path2.isAbsolute(relativePath)) {
|
|
150
|
+
return `${registry.namespaces[namespace]}:${relativePath}`;
|
|
151
|
+
}
|
|
150
152
|
}
|
|
151
|
-
return path2.relative(
|
|
153
|
+
return path2.relative(sourceDir, file);
|
|
152
154
|
},
|
|
153
155
|
getSubComponent(file) {
|
|
154
156
|
const relativeFile = path2.relative(registryDir, file);
|
|
@@ -161,10 +163,18 @@ function createComponentBuilder(registry, packageJson, registryDir, rootDir) {
|
|
|
161
163
|
};
|
|
162
164
|
}
|
|
163
165
|
|
|
166
|
+
// src/build/get-path-namespace.ts
|
|
167
|
+
function getFileNamespace(file) {
|
|
168
|
+
const parsed = file.split(":", 2);
|
|
169
|
+
if (parsed.length > 1) return { namespace: parsed[0], path: parsed[1] };
|
|
170
|
+
return { path: file };
|
|
171
|
+
}
|
|
172
|
+
|
|
164
173
|
// src/build/build-registry.ts
|
|
165
174
|
async function build(registry) {
|
|
166
175
|
const registryDir = path3.dirname(registry.path);
|
|
167
176
|
const rootDir = path3.join(registryDir, registry.rootDir);
|
|
177
|
+
const useSrc = await exists(path3.join(rootDir, "src"));
|
|
168
178
|
const output = {
|
|
169
179
|
index: [],
|
|
170
180
|
components: []
|
|
@@ -172,14 +182,19 @@ async function build(registry) {
|
|
|
172
182
|
const project = new Project({
|
|
173
183
|
tsConfigFilePath: registry.tsconfigPath ? path3.join(registryDir, registry.tsconfigPath) : path3.join(rootDir, "tsconfig.json")
|
|
174
184
|
});
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
185
|
+
function readPackageJson() {
|
|
186
|
+
if (typeof registry.packageJson !== "string" && registry.packageJson)
|
|
187
|
+
return registry.packageJson;
|
|
188
|
+
return fs.readFile(
|
|
189
|
+
registry.packageJson ? path3.join(registryDir, registry.packageJson) : path3.join(rootDir, "package.json")
|
|
190
|
+
).then((res) => JSON.parse(res.toString())).catch(() => void 0);
|
|
191
|
+
}
|
|
192
|
+
const packageJson = await readPackageJson();
|
|
178
193
|
const builder = createComponentBuilder(
|
|
179
194
|
registry,
|
|
180
195
|
packageJson,
|
|
181
196
|
registryDir,
|
|
182
|
-
rootDir
|
|
197
|
+
useSrc ? path3.join(rootDir, "src") : rootDir
|
|
183
198
|
);
|
|
184
199
|
const buildExtendRegistries = Object.values(registry.on ?? {}).map(
|
|
185
200
|
async (schema) => {
|
|
@@ -201,12 +216,21 @@ async function build(registry) {
|
|
|
201
216
|
devDependencies: /* @__PURE__ */ new Map(),
|
|
202
217
|
dependencies: /* @__PURE__ */ new Map()
|
|
203
218
|
};
|
|
204
|
-
const read = component.files.map(
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
219
|
+
const read = component.files.map(async (sourcePath) => {
|
|
220
|
+
const parsed = getFileNamespace(sourcePath);
|
|
221
|
+
parsed.path = path3.join(registryDir, parsed.path);
|
|
222
|
+
const content = await fs.readFile(parsed.path);
|
|
223
|
+
const sourceFile = project.createSourceFile(
|
|
224
|
+
parsed.path,
|
|
225
|
+
content.toString(),
|
|
226
|
+
{
|
|
227
|
+
overwrite: true
|
|
228
|
+
}
|
|
229
|
+
);
|
|
230
|
+
const outputPath = builder.resolveOutputPath(
|
|
231
|
+
parsed.path,
|
|
232
|
+
parsed.namespace
|
|
233
|
+
);
|
|
210
234
|
if (processedFiles.has(outputPath)) return;
|
|
211
235
|
return buildFile(
|
|
212
236
|
outputPath,
|
package/dist/index.js
CHANGED
|
@@ -125,7 +125,7 @@ function toReferencePath(sourceFile, referenceFile) {
|
|
|
125
125
|
typescriptExtensions.includes(extname) ? extname : void 0
|
|
126
126
|
)
|
|
127
127
|
)
|
|
128
|
-
);
|
|
128
|
+
).replaceAll(path2.sep, "/");
|
|
129
129
|
return importPath.startsWith("../") ? importPath : `./${importPath}`;
|
|
130
130
|
}
|
|
131
131
|
function resolveReference(ref, resolver) {
|
|
@@ -432,7 +432,7 @@ var ogImagePlugin = {
|
|
|
432
432
|
const route = await isI18nEnabled(ctx) ? "app/[lang]/docs-og/[...slug]/route.tsx" : "app/docs-og/[...slug]/route.tsx";
|
|
433
433
|
return {
|
|
434
434
|
"lib/metadata.ts": generated["lib/metadata"],
|
|
435
|
-
[route]: generated["app/docs-og/[...slug]/route"]
|
|
435
|
+
[ctx.src ? `src/${route}` : route]: generated["app/docs-og/[...slug]/route"]
|
|
436
436
|
};
|
|
437
437
|
},
|
|
438
438
|
dependencies: [],
|
|
@@ -641,9 +641,9 @@ function runTransform(sourceFile) {
|
|
|
641
641
|
|
|
642
642
|
// src/plugins/i18n.ts
|
|
643
643
|
var i18nPlugin = {
|
|
644
|
-
files: () => ({
|
|
644
|
+
files: ({ src: src2 }) => ({
|
|
645
645
|
"lib/i18n.ts": generated["lib/i18n"],
|
|
646
|
-
"middleware.ts": generated.middleware
|
|
646
|
+
[src2 ? "src/middleware.ts" : "middleware.ts"]: generated.middleware
|
|
647
647
|
}),
|
|
648
648
|
dependencies: [],
|
|
649
649
|
instructions: () => [
|
|
@@ -894,7 +894,7 @@ async function runTree(args) {
|
|
|
894
894
|
// package.json
|
|
895
895
|
var package_default = {
|
|
896
896
|
name: "@fumadocs/cli",
|
|
897
|
-
version: "0.0.
|
|
897
|
+
version: "0.0.4",
|
|
898
898
|
description: "The CLI tool for Fumadocs",
|
|
899
899
|
keywords: [
|
|
900
900
|
"NextJs",
|
|
@@ -928,21 +928,21 @@ var package_default = {
|
|
|
928
928
|
"types:check": "tsc --noEmit"
|
|
929
929
|
},
|
|
930
930
|
dependencies: {
|
|
931
|
-
"@clack/prompts": "^0.
|
|
931
|
+
"@clack/prompts": "^0.8.2",
|
|
932
932
|
commander: "^12.1.0",
|
|
933
|
-
execa: "^9.
|
|
934
|
-
"package-manager-detector": "^0.2.
|
|
933
|
+
execa: "^9.5.1",
|
|
934
|
+
"package-manager-detector": "^0.2.4",
|
|
935
935
|
picocolors: "^1.1.1",
|
|
936
936
|
"ts-morph": "^24.0.0"
|
|
937
937
|
},
|
|
938
938
|
devDependencies: {
|
|
939
939
|
"@types/cross-spawn": "^6.0.6",
|
|
940
|
-
"@types/node": "22.
|
|
941
|
-
"@types/react": "^18.3.
|
|
940
|
+
"@types/node": "22.9.3",
|
|
941
|
+
"@types/react": "^18.3.12",
|
|
942
942
|
"eslint-config-custom": "workspace:*",
|
|
943
943
|
"fast-glob": "^3.3.1",
|
|
944
944
|
tsconfig: "workspace:*",
|
|
945
|
-
tsx: "^4.19.
|
|
945
|
+
tsx: "^4.19.2"
|
|
946
946
|
},
|
|
947
947
|
publishConfig: {
|
|
948
948
|
access: "public"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fumadocs/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "The CLI tool for Fumadocs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -26,19 +26,19 @@
|
|
|
26
26
|
"dist/*"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@clack/prompts": "^0.
|
|
29
|
+
"@clack/prompts": "^0.8.2",
|
|
30
30
|
"commander": "^12.1.0",
|
|
31
|
-
"execa": "^9.
|
|
32
|
-
"package-manager-detector": "^0.2.
|
|
31
|
+
"execa": "^9.5.1",
|
|
32
|
+
"package-manager-detector": "^0.2.4",
|
|
33
33
|
"picocolors": "^1.1.1",
|
|
34
34
|
"ts-morph": "^24.0.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/cross-spawn": "^6.0.6",
|
|
38
|
-
"@types/node": "22.
|
|
39
|
-
"@types/react": "^18.3.
|
|
38
|
+
"@types/node": "22.9.3",
|
|
39
|
+
"@types/react": "^18.3.12",
|
|
40
40
|
"fast-glob": "^3.3.1",
|
|
41
|
-
"tsx": "^4.19.
|
|
41
|
+
"tsx": "^4.19.2",
|
|
42
42
|
"eslint-config-custom": "0.0.0",
|
|
43
43
|
"tsconfig": "0.0.0"
|
|
44
44
|
},
|