* Resolve a component argument to an absolute .tsx file path. * Accepts: * - A file path (absolute or relative): ./valdi_modules/widgets/src/.../Checkbox.tsx * - An import path: widgets/src/components/button/Checkbox
(component: string, workspaceRoot: string)
| 27 | * - An import path: widgets/src/components/button/Checkbox |
| 28 | */ |
| 29 | function resolveComponentFile(component: string, workspaceRoot: string): string { |
| 30 | // If it already looks like a file path |
| 31 | if (component.endsWith('.tsx') || component.endsWith('.ts')) { |
| 32 | const abs = path.resolve(component); |
| 33 | if (fs.existsSync(abs)) return abs; |
| 34 | throw new CliError(`Component file not found: ${abs}`); |
| 35 | } |
| 36 | |
| 37 | // Treat as an import path — search common module directories |
| 38 | const candidates = [ |
| 39 | // External repos: valdi_modules/<module>/... |
| 40 | path.join(workspaceRoot, 'valdi_modules', component + '.tsx'), |
| 41 | // Valdi repo: src/valdi_modules/src/valdi/<module>/... |
| 42 | path.join(workspaceRoot, 'src/valdi_modules/src/valdi', component + '.tsx'), |
| 43 | ]; |
| 44 | |
| 45 | for (const candidate of candidates) { |
| 46 | if (fs.existsSync(candidate)) return candidate; |
| 47 | } |
| 48 | |
| 49 | throw new CliError( |
| 50 | `Could not find component file for "${component}". Searched:\n` + |
| 51 | candidates.map(c => ` ${c}`).join('\n'), |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Compute the import path from a resolved file path. |
no test coverage detected