(file: RegistryFile)
| 54 | } |
| 55 | |
| 56 | async function getFileContent(file: RegistryFile) { |
| 57 | const raw = await fs.readFile(file.path, "utf-8"); |
| 58 | |
| 59 | const project = new Project({ |
| 60 | compilerOptions: {}, |
| 61 | }); |
| 62 | |
| 63 | const tempFile = await createTempSourceFile(file.path); |
| 64 | const sourceFile = project.createSourceFile(tempFile, raw, { |
| 65 | scriptKind: ScriptKind.TSX, |
| 66 | }); |
| 67 | |
| 68 | // Remove meta variables. |
| 69 | // removeVariable(sourceFile, "iframeHeight") |
| 70 | // removeVariable(sourceFile, "containerClassName") |
| 71 | // removeVariable(sourceFile, "description") |
| 72 | |
| 73 | let code = sourceFile.getFullText(); |
| 74 | |
| 75 | // Some registry items uses default export. |
| 76 | // We want to use named export instead. |
| 77 | // TODO: do we really need this? - @shadcn. |
| 78 | // if (file.type !== "registry:page") { |
| 79 | // code = code.replaceAll("export default", "export") |
| 80 | // } |
| 81 | |
| 82 | // Fix imports. |
| 83 | code = fixImport(code); |
| 84 | |
| 85 | return code; |
| 86 | } |
| 87 | |
| 88 | function getFileTarget(file: RegistryFile) { |
| 89 | let target = file.target; |
no test coverage detected