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

Function writeIconMapping

scripts/generate-docs.ts:370–417  ·  view source on GitHub ↗
(iconMapping: Record<string, string>)

Source from the content-addressed store, hash-verified

368}
369
370function writeIconMapping(iconMapping: Record<string, string>): void {
371 try {
372 const iconMappingPath = path.join(rootDir, 'apps/docs/components/ui/icon-mapping.ts')
373
374 // Add bare-name aliases for versioned block types so trigger provider names resolve correctly.
375 // e.g. github_v2 → github, fireflies_v2 → fireflies, gmail_v2 → gmail
376 const withAliases: Record<string, string> = { ...iconMapping }
377 for (const [blockType, iconName] of Object.entries(iconMapping)) {
378 const baseType = stripVersionSuffix(blockType)
379 if (baseType !== blockType && !withAliases[baseType]) {
380 withAliases[baseType] = iconName
381 }
382 }
383
384 // Get unique icon names, sorted to match Biome's organizeImports
385 const iconNames = [...new Set(Object.values(withAliases))].sort(biomeSortCompare)
386
387 // Generate imports
388 const imports = iconNames.map((icon) => ` ${icon},`).join('\n')
389
390 // Generate mapping with direct references (no dynamic access for tree shaking)
391 const mappingEntries = Object.entries(withAliases)
392 .sort(([a], [b]) => a.localeCompare(b))
393 .map(([blockType, iconName]) => ` ${blockType}: ${iconName},`)
394 .join('\n')
395
396 const content = `// Auto-generated file - do not edit manually
397// Generated by scripts/generate-docs.ts
398// Maps block types to their icon component references
399
400import type { ComponentType, SVGProps } from 'react'
401import {
402${imports}
403} from '@/components/icons'
404
405type IconComponent = ComponentType<SVGProps<SVGSVGElement>>
406
407export const blockTypeToIconMap: Record<string, IconComponent> = {
408${mappingEntries}
409}
410`
411
412 fs.writeFileSync(iconMappingPath, content)
413 console.log('✓ Icon mapping file written to docs app')
414 } catch (error) {
415 console.error('Error writing icon mapping:', error)
416 }
417}
418
419/**
420 * Extract operation options from the subBlock with id: 'operation' (if present).

Callers 1

generateAllBlockDocsFunction · 0.85

Calls 4

stripVersionSuffixFunction · 0.90
joinMethod · 0.80
logMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected