( repoRoot: string, extracted: ExtractedDesign, sourceMockup: string, )
| 103 | * If not, creates a new one. |
| 104 | */ |
| 105 | export function updateDesignMd( |
| 106 | repoRoot: string, |
| 107 | extracted: ExtractedDesign, |
| 108 | sourceMockup: string, |
| 109 | ): void { |
| 110 | const designPath = path.join(repoRoot, "DESIGN.md"); |
| 111 | const timestamp = new Date().toISOString().split("T")[0]; |
| 112 | |
| 113 | const section = formatExtractedSection(extracted, sourceMockup, timestamp); |
| 114 | |
| 115 | if (fs.existsSync(designPath)) { |
| 116 | // Append to existing DESIGN.md |
| 117 | const existing = fs.readFileSync(designPath, "utf-8"); |
| 118 | |
| 119 | // Check if there's already an extracted section, replace it |
| 120 | const marker = "## Extracted Design Language"; |
| 121 | if (existing.includes(marker)) { |
| 122 | const before = existing.split(marker)[0]; |
| 123 | fs.writeFileSync(designPath, before.trimEnd() + "\n\n" + section); |
| 124 | } else { |
| 125 | fs.writeFileSync(designPath, existing.trimEnd() + "\n\n" + section); |
| 126 | } |
| 127 | console.error(`Updated DESIGN.md with extracted design language`); |
| 128 | } else { |
| 129 | // Create new DESIGN.md |
| 130 | const content = `# Design System |
| 131 | |
| 132 | ${section}`; |
| 133 | fs.writeFileSync(designPath, content); |
| 134 | console.error(`Created DESIGN.md with extracted design language`); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | function formatExtractedSection( |
| 139 | extracted: ExtractedDesign, |
no test coverage detected