* Generate icon mapping from block definitions. * Docs need hidden historical version keys so old BlockInfoCard references and * versioned docs links still render icons, while landing only needs visible blocks.
(options: {
includeHidden: boolean
})
| 265 | * versioned docs links still render icons, while landing only needs visible blocks. |
| 266 | */ |
| 267 | async function generateIconMapping(options: { |
| 268 | includeHidden: boolean |
| 269 | }): Promise<Record<string, string>> { |
| 270 | try { |
| 271 | console.log('Generating icon mapping from block definitions...') |
| 272 | |
| 273 | const iconMapping: Record<string, string> = {} |
| 274 | const blockFiles = (await glob(`${BLOCKS_PATH}/*.ts`)).sort() |
| 275 | |
| 276 | for (const blockFile of blockFiles) { |
| 277 | const fileContent = fs.readFileSync(blockFile, 'utf-8') |
| 278 | |
| 279 | // For icon mapping, we need ALL blocks including hidden ones |
| 280 | // because V2 blocks inherit icons from legacy blocks via spread |
| 281 | // First, extract the primary icon from the file (usually the legacy block's icon) |
| 282 | const primaryIcon = extractIconNameFromContent(fileContent) |
| 283 | |
| 284 | // Find all block exports and their types |
| 285 | const exportRegex = /export\s+const\s+(\w+)Block\s*:\s*BlockConfig[^=]*=\s*\{/g |
| 286 | let match |
| 287 | |
| 288 | while ((match = exportRegex.exec(fileContent)) !== null) { |
| 289 | const blockName = match[1] |
| 290 | const startIndex = match.index + match[0].length - 1 |
| 291 | |
| 292 | // Extract the block content |
| 293 | const endIndex = findMatchingClose(fileContent, startIndex) |
| 294 | |
| 295 | if (endIndex !== -1) { |
| 296 | const blockContent = fileContent.substring(startIndex, endIndex) |
| 297 | |
| 298 | // Check hideFromToolbar - skip hidden blocks for docs but NOT for icon mapping |
| 299 | const hideFromToolbar = /hideFromToolbar\s*:\s*true/.test(blockContent) |
| 300 | |
| 301 | // Get block type |
| 302 | const blockType = |
| 303 | extractStringPropertyFromContent(blockContent, 'type') || blockName.toLowerCase() |
| 304 | |
| 305 | // Get icon - either from this block or inherited from primary |
| 306 | const iconName = extractIconNameFromContent(blockContent) || primaryIcon |
| 307 | |
| 308 | if (!blockType || !iconName) { |
| 309 | continue |
| 310 | } |
| 311 | |
| 312 | // Skip trigger/webhook/rss blocks |
| 313 | if ( |
| 314 | blockType.includes('_trigger') || |
| 315 | blockType.includes('_webhook') || |
| 316 | blockType.includes('rss') |
| 317 | ) { |
| 318 | continue |
| 319 | } |
| 320 | |
| 321 | // Get category for additional filtering |
| 322 | const category = extractStringPropertyFromContent(blockContent, 'category') || 'misc' |
| 323 | |
| 324 | // Exclude first-party `blocks`-category primitives (except the small |
no test coverage detected