(iconMapping: Record<string, string>)
| 368 | } |
| 369 | |
| 370 | function 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 | |
| 400 | import type { ComponentType, SVGProps } from 'react' |
| 401 | import { |
| 402 | ${imports} |
| 403 | } from '@/components/icons' |
| 404 | |
| 405 | type IconComponent = ComponentType<SVGProps<SVGSVGElement>> |
| 406 | |
| 407 | export 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). |
no test coverage detected