( mdxContent: string, packageName: string, )
| 43 | }; |
| 44 | |
| 45 | const transformMdxToReadme = ( |
| 46 | mdxContent: string, |
| 47 | packageName: string, |
| 48 | ): string => { |
| 49 | let content = mdxContent; |
| 50 | |
| 51 | // Load MDX component content files |
| 52 | const commonSdkConfigPath = workspacePath( |
| 53 | 'apps/public/src/components/common-sdk-config.mdx', |
| 54 | ); |
| 55 | const webSdkConfigPath = workspacePath( |
| 56 | 'apps/public/src/components/web-sdk-config.mdx', |
| 57 | ); |
| 58 | |
| 59 | let commonSdkConfigContent = ''; |
| 60 | let webSdkConfigContent = ''; |
| 61 | |
| 62 | try { |
| 63 | if (fs.existsSync(commonSdkConfigPath)) { |
| 64 | commonSdkConfigContent = fs.readFileSync(commonSdkConfigPath, 'utf-8'); |
| 65 | } |
| 66 | } catch { |
| 67 | // Ignore if file doesn't exist |
| 68 | } |
| 69 | |
| 70 | try { |
| 71 | if (fs.existsSync(webSdkConfigPath)) { |
| 72 | webSdkConfigContent = fs.readFileSync(webSdkConfigPath, 'utf-8'); |
| 73 | } |
| 74 | } catch { |
| 75 | // Ignore if file doesn't exist |
| 76 | } |
| 77 | |
| 78 | // Extract title from frontmatter |
| 79 | const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n/); |
| 80 | let title = packageName; |
| 81 | let description = ''; |
| 82 | |
| 83 | if (frontmatterMatch?.[1]) { |
| 84 | const frontmatter = frontmatterMatch[1]; |
| 85 | const titleMatch = frontmatter.match(/^title:\s*(.+)$/m); |
| 86 | const descMatch = frontmatter.match(/^description:\s*(.+)$/m); |
| 87 | if (titleMatch?.[1]) title = titleMatch[1].trim(); |
| 88 | if (descMatch?.[1]) description = descMatch[1].trim(); |
| 89 | |
| 90 | // Remove frontmatter |
| 91 | content = content.replace(/^---\n[\s\S]*?\n---\n/, ''); |
| 92 | } |
| 93 | |
| 94 | // Replace MDX component references with their actual content |
| 95 | // This must happen before code block protection so component content is also protected |
| 96 | if (commonSdkConfigContent) { |
| 97 | content = content.replace( |
| 98 | /<CommonSdkConfig\s*\/>/g, |
| 99 | `\n${commonSdkConfigContent}\n`, |
| 100 | ); |
| 101 | } |
| 102 | if (webSdkConfigContent) { |
no test coverage detected