/** * 从标品 diy-group 快照解析 addon 微页面 componentName 映射(不依赖 src 内注释 registry) */ const fs = require('fs') const path = require('path') const ADDON_DIY_IMPORT_RE = /(?:\/\/\s*)?import\s+(\w+)(?:[\s\S]*?)from\s+['"]@\/addon\/([\w_]+)\/components\/diy\/([\w-]+)\/index\.vue['"];?\s*/g function unwrapHtmlComments(text) { return text.replace(//g, '') } function folderToTag(folder) { return `diy-${folder.replace(/\//g, '-')}` } function varNameToKebabTag(varName) { return varName.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase() } function resolveTag(entry, template) { const haystack = unwrapHtmlComments(template) const candidates = [ varNameToKebabTag(entry.varName), folderToTag(entry.diyFolder), folderToTag(entry.diyFolder).toLowerCase() ] for (const tag of candidates) { if (haystack.includes(`<${tag}`)) return tag } return null } function findTemplateBlockForTag(template, tag) { const haystack = unwrapHtmlComments(template) const blockRe = /[\s\S]*?<\/template>/g let m while ((m = blockRe.exec(haystack))) { if (m[0].includes(`<${tag}`)) return m[0] } return null } function extractVueComponentName(block) { const m = block.match(/component\.componentName\s*={1,3}\s*['"]([^'"]+)['"]/) return m ? m[1] : null } function parseDiyGroupRegistryFile(filePath) { const src = fs.readFileSync(filePath, 'utf-8') const templateMatch = src.match(/