/** * 合并 / 框架构建后:将微页面 DIY 组件内联进 diy-group(替换 diy-dynamic-bridge) * 开发期源码仍用 diy-dynamic-bridge;仅 dist/build/mp-core 产物生效。 */ const fs = require('fs') const path = require('path') const DIY_GROUP_REL = 'addon/components/diy/group' /** dev / prod: 或成对标签 */ const DIY_GROUP_BRIDGE_TAG = /]*(?:\/>|>\s*<\/diy-dynamic-bridge>)/ /** 旧版:外层 component.d + 内联行(升级时替换) */ const DIY_GROUP_INLINE_BLOCK_RE = /[\s\S]*?<\/block>/ /** 新版/旧版兼容:内联行可能用 component.q 或 component.d */ const DIY_GROUP_INLINE_LINES_RE = /( <[a-z0-9-]+ wx:if="\{\{component\.(q|d)==='[^']+'\}\}"[\s\S]*?\/>\n?)+/ /** 内联块唯一标记:用于重复 merge 时幂等替换(避免同名组件被累积渲染多次) */ const DIY_GROUP_INLINE_WRAP_RE = /[\s\S]*?/ const DIY_GROUP_BASE_USING = { 'copy-right': '../../../../components/copy-right/copy-right', tabbar: '../../../../components/tabbar/tabbar', 'top-tabbar': '../../../../components/top-tabbar/top-tabbar', 'pop-ads': '../../../../components/pop-ads/pop-ads' } function readJson(filePath) { return JSON.parse(fs.readFileSync(filePath, 'utf-8')) } function writeJson(filePath, data) { fs.mkdirSync(path.dirname(filePath), { recursive: true }) fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n', 'utf-8') } function getDiyComponentUsingPath(meta) { if (!meta?.folder) return null if (meta.scope === 'app' || !meta.addonKey) { return `../../../../app/components/diy/${meta.folder}/index` } return `../../../${meta.addonKey}/components/diy/${meta.folder}/index` } function resolveMpComponentDir(jsonDir, relPath) { return path.normalize(path.join(jsonDir, relPath)) } /** * wx:for-item 上用于路由的内联字段。 * * 取值必须是「组件名」本身。这里用 `d` 而不是 `q`,因为: * - `q` 是源码 `