(content: string, includeSourceCode: boolean)
| 218 | } |
| 219 | |
| 220 | function convertComponentSourceToMarkdown(content: string, includeSourceCode: boolean): string { |
| 221 | if (!includeSourceCode) { |
| 222 | return content.replace(/<ComponentSource[^>]*\/>/g, "") |
| 223 | } |
| 224 | |
| 225 | return content.replace( |
| 226 | /<ComponentSource\s+name="([^"]+)"[^>]*\/>/g, |
| 227 | (match, name) => { |
| 228 | try { |
| 229 | // Try to load the source code from the registry |
| 230 | const registryPath = path.join(baseDir, "public", "r", `${name}.json`) |
| 231 | if (fs.existsSync(registryPath)) { |
| 232 | const registry = JSON.parse(fs.readFileSync(registryPath, "utf8")) |
| 233 | const mainFile = registry.files.find( |
| 234 | (file: any) => file.path.split("/").pop().replace(/\.(tsx|ts)$/, "") === name |
| 235 | ) |
| 236 | |
| 237 | if (mainFile) { |
| 238 | return `#### ${name}\n\n\`\`\`tsx\n${mainFile.content}\n\`\`\`\n\n` |
| 239 | } |
| 240 | } |
| 241 | return `#### ${name}\n\nSource code for \`${name}\` component.\n\n` |
| 242 | } catch (error) { |
| 243 | return `#### ${name}\n\nSource code for \`${name}\` component.\n\n` |
| 244 | } |
| 245 | } |
| 246 | ) |
| 247 | } |
| 248 | |
| 249 | function convertInstallTabsToMarkdown(content: string, includeInstructions: boolean): string { |
| 250 | if (!includeInstructions) { |
no outgoing calls
no test coverage detected