@fumadocs/cli 0.0.3 → 0.0.5

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.
@@ -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
- declare function createComponentBuilder(registry: Registry, packageJson: PackageJson | undefined, registryDir: string, rootDir: string): ComponentBuilder;
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
  /**
@@ -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, rootDir) {
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("../") || path2.isAbsolute(relativePath))
148
- continue;
149
- return `${registry.namespaces[namespace]}:${relativePath}`;
149
+ if (!relativePath.startsWith("../") && !path2.isAbsolute(relativePath)) {
150
+ return `${registry.namespaces[namespace]}:${relativePath}`;
151
+ }
150
152
  }
151
- return path2.relative(rootDir, file);
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
- const packageJson = typeof registry.packageJson !== "string" && registry.packageJson ? registry.packageJson : await fs.readFile(
176
- registry.packageJson ? path3.join(registryDir, registry.packageJson) : path3.join(rootDir, "package.json")
177
- ).then((res) => JSON.parse(res.toString())).catch(() => void 0);
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((file) => path3.join(registryDir, file)).map(async (file) => {
205
- const content = await fs.readFile(file);
206
- const sourceFile = project.createSourceFile(file, content.toString(), {
207
- overwrite: true
208
- });
209
- const outputPath = builder.resolveOutputPath(sourceFile.getFilePath());
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) {
@@ -619,7 +619,7 @@ function runTransform(sourceFile) {
619
619
  if (parent) {
620
620
  const inner = parent.getJsxChildren().map((v) => v.getFullText()).filter((v) => v.length > 0).join("\n");
621
621
  parent.setBodyText(
622
- `<I18nProvider locale={params.lang} locales={[
622
+ `<I18nProvider locale={(await params).lang} locales={[
623
623
  { locale: 'en', name: 'English' }
624
624
  ]}>
625
625
  ${inner.trim()}
@@ -632,8 +632,9 @@ function runTransform(sourceFile) {
632
632
  });
633
633
  }
634
634
  const func = sourceFile.getDescendantsOfKind(SyntaxKind3.FunctionDeclaration).find((v) => v.isDefaultExport());
635
+ func?.toggleModifier("async", true);
635
636
  const param = func?.getParameters().at(0);
636
- param?.setType(`{ params: { lang: string }, children: ReactNode }`);
637
+ param?.setType(`{ params: Promise<{ lang: string }>, children: ReactNode }`);
637
638
  param?.set({
638
639
  name: `{ params, children }`
639
640
  });
@@ -894,7 +895,7 @@ async function runTree(args) {
894
895
  // package.json
895
896
  var package_default = {
896
897
  name: "@fumadocs/cli",
897
- version: "0.0.3",
898
+ version: "0.0.5",
898
899
  description: "The CLI tool for Fumadocs",
899
900
  keywords: [
900
901
  "NextJs",
@@ -928,21 +929,21 @@ var package_default = {
928
929
  "types:check": "tsc --noEmit"
929
930
  },
930
931
  dependencies: {
931
- "@clack/prompts": "^0.7.0",
932
+ "@clack/prompts": "^0.9.0",
932
933
  commander: "^12.1.0",
933
- execa: "^9.4.1",
934
- "package-manager-detector": "^0.2.2",
934
+ execa: "^9.5.2",
935
+ "package-manager-detector": "^0.2.8",
935
936
  picocolors: "^1.1.1",
936
937
  "ts-morph": "^24.0.0"
937
938
  },
938
939
  devDependencies: {
939
940
  "@types/cross-spawn": "^6.0.6",
940
- "@types/node": "22.7.8",
941
- "@types/react": "^18.3.11",
941
+ "@types/node": "22.10.2",
942
+ "@types/react": "^19.0.2",
942
943
  "eslint-config-custom": "workspace:*",
943
944
  "fast-glob": "^3.3.1",
944
945
  tsconfig: "workspace:*",
945
- tsx: "^4.19.1"
946
+ tsx: "^4.19.2"
946
947
  },
947
948
  publishConfig: {
948
949
  access: "public"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fumadocs/cli",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
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.7.0",
29
+ "@clack/prompts": "^0.9.0",
30
30
  "commander": "^12.1.0",
31
- "execa": "^9.4.1",
32
- "package-manager-detector": "^0.2.2",
31
+ "execa": "^9.5.2",
32
+ "package-manager-detector": "^0.2.8",
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.7.8",
39
- "@types/react": "^18.3.11",
38
+ "@types/node": "22.10.2",
39
+ "@types/react": "^19.0.2",
40
40
  "fast-glob": "^3.3.1",
41
- "tsx": "^4.19.1",
41
+ "tsx": "^4.19.2",
42
42
  "eslint-config-custom": "0.0.0",
43
43
  "tsconfig": "0.0.0"
44
44
  },