MCPcopy Index your code
hub / github.com/simstudioai/sim / mergeWithManualContent

Function mergeWithManualContent

scripts/generate-docs.ts:2663–2706  ·  view source on GitHub ↗
(
  generatedMarkdown: string,
  existingContent: string | null,
  manualSections: Record<string, string>
)

Source from the content-addressed store, hash-verified

2661}
2662
2663function mergeWithManualContent(
2664 generatedMarkdown: string,
2665 existingContent: string | null,
2666 manualSections: Record<string, string>
2667): string {
2668 if (!existingContent || Object.keys(manualSections).length === 0) {
2669 return generatedMarkdown
2670 }
2671
2672 let mergedContent = generatedMarkdown
2673
2674 Object.entries(manualSections).forEach(([sectionName, content]) => {
2675 const insertionPoints: Record<string, { regex: RegExp }> = {
2676 intro: {
2677 regex: /<BlockInfoCard[\s\S]*?(\/>|<\/svg>`}\s*\/>)/,
2678 },
2679 usage: {
2680 regex: /## Usage Instructions/,
2681 },
2682 outputs: {
2683 regex: /## Outputs/,
2684 },
2685 notes: {
2686 regex: /## Notes/,
2687 },
2688 }
2689
2690 const insertionPoint = insertionPoints[sectionName]
2691 const wrapped = `{/* MANUAL-CONTENT-START:${sectionName} */}\n${content}\n{/* MANUAL-CONTENT-END */}`
2692
2693 const match = insertionPoint ? mergedContent.match(insertionPoint.regex) : null
2694 if (match && match.index !== undefined) {
2695 const insertPosition = match.index + match[0].length
2696 mergedContent = `${mergedContent.slice(0, insertPosition)}\n\n${wrapped}\n${mergedContent.slice(insertPosition)}`
2697 } else {
2698 // Never drop manual content: when the anchor is missing (e.g. a `notes`
2699 // section with no generated "## Notes" heading), append at the end.
2700 console.log(`No insertion anchor for manual section "${sectionName}" — appending at end`)
2701 mergedContent = `${mergedContent.replace(/\s*$/, '')}\n\n${wrapped}\n`
2702 }
2703 })
2704
2705 return mergedContent
2706}
2707
2708async function generateBlockDoc(blockPath: string) {
2709 try {

Callers 2

generateBlockDocFunction · 0.85
generateAllTriggerDocsFunction · 0.85

Calls 2

logMethod · 0.80
replaceMethod · 0.65

Tested by

no test coverage detected