Skip to content

Commit 2d60b35

Browse files
committed
feat: Enhance metadata generation to support @vibe/* imports
1 parent 6c414e6 commit 2d60b35

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

packages/core/src/scripts/generate-metadata.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,17 @@ function resolveExportsRecursively(
167167
const modSpec = decl.getModuleSpecifierValue();
168168
if (!modSpec) continue;
169169

170-
const baseDir = path.dirname(sourceFile.getFilePath());
171-
const matchedPaths = findMatchingPaths(baseDir, modSpec);
170+
// Handle @vibe/* imports (e.g., export * from "@vibe/button")
171+
let matchedPaths: string[] = [];
172+
if (modSpec.startsWith("@vibe/")) {
173+
const pkgName = modSpec.replace("@vibe/", "");
174+
const pkgPath = path.resolve(__dirname, `../../../components/${pkgName}/src/index.ts`);
175+
if (fs.existsSync(pkgPath)) matchedPaths = [pkgPath];
176+
} else {
177+
const baseDir = path.dirname(sourceFile.getFilePath());
178+
matchedPaths = findMatchingPaths(baseDir, modSpec);
179+
}
180+
172181
const exportedSyms = getExportedSymbolsFromDecl(decl);
173182

174183
for (const matched of matchedPaths) {
@@ -205,6 +214,12 @@ function aggregatorMain(): AggregatorRecord[] {
205214
const packageDir = path.resolve(__dirname, "../components");
206215
project.addSourceFilesAtPaths([`${packageDir}/**/*.ts`, `${packageDir}/**/*.tsx`]);
207216

217+
// Also load source files from separate component packages (e.g., @vibe/button)
218+
const componentsDir = path.resolve(__dirname, "../../../components");
219+
if (fs.existsSync(componentsDir)) {
220+
project.addSourceFilesAtPaths([`${componentsDir}/*/src/**/*.{ts,tsx}`]);
221+
}
222+
208223
const coreIndex = path.join(packageDir, "index.ts");
209224
const nextIndex = path.join(packageDir, "next.ts");
210225

@@ -401,14 +416,18 @@ function mergeResults(aggregator: AggregatorRecord[], docgen: DocgenResult[]): F
401416
}
402417
}
403418

419+
// Determine correct import path: if file is from packages/components/{pkg}/, use @vibe/{pkg}
420+
const pkgMatch = agg.filePath.match(/\/components\/([^/]+)\/src\//);
421+
const importPath = pkgMatch ? `@vibe/${pkgMatch[1]}` : `@vibe/core${agg.aggregator === "next" ? "/next" : ""}`;
422+
404423
return {
405424
filePath: toRelativePath(agg.filePath),
406425
aggregator: agg.aggregator,
407426
symbols: agg.symbols,
408427
displayName: component.displayName,
409428
description: component.description,
410429
props: filteredProps,
411-
import: `import { ${component.displayName} } from "@vibe/core${agg.aggregator === "next" ? "/next" : ""}"`,
430+
import: `import { ${component.displayName} } from "${importPath}"`,
412431
parentComponent: getParentComponent(toRelativePath(agg.filePath)),
413432
subComponents: findSubComponents(toRelativePath(agg.filePath), allFilePaths.map(toRelativePath))
414433
};
@@ -472,6 +491,7 @@ async function main() {
472491
console.log(`Final output contains ${finalJson.length} component entries`);
473492

474493
const outPath = path.resolve(__dirname, "../../dist/metadata.json");
494+
fs.mkdirSync(path.dirname(outPath), { recursive: true });
475495
fs.writeFileSync(outPath, JSON.stringify(finalJson, null, 2), "utf-8");
476496
console.log(`Done! Wrote metadata to: ${outPath}`);
477497
} catch (error) {

0 commit comments

Comments
 (0)