* Extract block config from a specific block's content * If the block uses spread inheritance (e.g., ...GitHubBlock), attempts to resolve * missing properties from the base block in the file content.
( blockContent: string, blockName: string, fileContent?: string )
| 1012 | * missing properties from the base block in the file content. |
| 1013 | */ |
| 1014 | function extractBlockConfigFromContent( |
| 1015 | blockContent: string, |
| 1016 | blockName: string, |
| 1017 | fileContent?: string |
| 1018 | ): BlockConfig | null { |
| 1019 | try { |
| 1020 | // Check for spread inheritance |
| 1021 | const spreadBase = extractSpreadBase(blockContent) |
| 1022 | let baseConfig: BlockConfig | null = null |
| 1023 | |
| 1024 | if (spreadBase && fileContent) { |
| 1025 | // Extract the base block's content from the file |
| 1026 | const baseBlockRegex = new RegExp( |
| 1027 | `export\\s+const\\s+${spreadBase}\\s*:\\s*BlockConfig[^=]*=\\s*\\{`, |
| 1028 | 'g' |
| 1029 | ) |
| 1030 | const baseMatch = baseBlockRegex.exec(fileContent) |
| 1031 | |
| 1032 | if (baseMatch) { |
| 1033 | const startIndex = baseMatch.index + baseMatch[0].length - 1 |
| 1034 | const endIndex = findMatchingClose(fileContent, startIndex) |
| 1035 | |
| 1036 | if (endIndex !== -1) { |
| 1037 | const baseBlockContent = fileContent.substring(startIndex, endIndex) |
| 1038 | // Recursively extract base config (but don't pass fileContent to avoid infinite loops) |
| 1039 | baseConfig = extractBlockConfigFromContent( |
| 1040 | baseBlockContent, |
| 1041 | spreadBase.replace('Block', '') |
| 1042 | ) |
| 1043 | } |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | // Extract properties from this block, using topLevelOnly=true for main properties |
| 1048 | const blockType = |
| 1049 | extractStringPropertyFromContent(blockContent, 'type', true) || blockName.toLowerCase() |
| 1050 | const name = |
| 1051 | extractStringPropertyFromContent(blockContent, 'name', true) || |
| 1052 | baseConfig?.name || |
| 1053 | `${blockName} Block` |
| 1054 | const description = |
| 1055 | extractStringPropertyFromContent(blockContent, 'description', true) || |
| 1056 | baseConfig?.description || |
| 1057 | '' |
| 1058 | const longDescription = |
| 1059 | extractStringPropertyFromContent(blockContent, 'longDescription', true) || |
| 1060 | baseConfig?.longDescription || |
| 1061 | '' |
| 1062 | const category = |
| 1063 | extractStringPropertyFromContent(blockContent, 'category', true) || baseConfig?.category || '' |
| 1064 | const bgColor = |
| 1065 | extractStringPropertyFromContent(blockContent, 'bgColor', true) || |
| 1066 | baseConfig?.bgColor || |
| 1067 | '#F5F5F5' |
| 1068 | const iconName = extractIconNameFromContent(blockContent) || (baseConfig as any)?.iconName || '' |
| 1069 | |
| 1070 | const outputs = extractOutputsFromContent(blockContent) |
| 1071 | const toolsAccess = extractToolsAccessFromContent(blockContent) |
no test coverage detected