From 9c93f2139253d904b1b090274e292bc8bf1a862e Mon Sep 17 00:00:00 2001 From: mjzhu4 Date: Fri, 7 Mar 2025 15:10:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E6=8B=86=E5=8C=85=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E4=B8=80=E4=B8=AA=E7=BB=84=E4=BB=B6=E5=9C=A8=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E5=88=86=E7=BB=84=E9=87=8C=E9=9D=A2=E4=B9=9Fk?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E4=B8=80=E4=B8=AA=E5=88=86=E7=BB=84=E9=87=8C?= =?UTF-8?q?=E9=9D=A2=E5=AD=98=E5=9C=A8=E4=B8=A4=E4=B8=AA=E7=BB=84=E4=BB=B6?= =?UTF-8?q?(componentName=E7=9B=B8=E5=90=8C,=20snippetName=E4=B8=8D?= =?UTF-8?q?=E5=90=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/splitMaterials.mjs | 52 +++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/scripts/splitMaterials.mjs b/scripts/splitMaterials.mjs index b09b4379e9..001c32cfe1 100644 --- a/scripts/splitMaterials.mjs +++ b/scripts/splitMaterials.mjs @@ -1,3 +1,9 @@ +/* + * @Description: + * @Date: 2025-03-07 14:29:56 + * @LastEditors: xiaopang + * @LastEditTime: 2025-03-07 14:35:20 + */ import fs from 'fs-extra' import path from 'node:path' import Logger from './logger.mjs' @@ -11,8 +17,8 @@ const materialsDir = 'materials' const bundle = fs.readJSONSync(bundlePath) const { components, snippets, blocks } = bundle.data.materials -const capitalize = (str) => `${str.charAt(0).toUpperCase()}${str.slice(1)}` -const toPascalCase = (str) => str.split('-').map(capitalize).join('') +const capitalize = (str) => str ? `${str.charAt(0).toUpperCase()}${str.slice(1)}` : '' +const toPascalCase = (str) => str ? str.split('-').map(capitalize).join('') : '' /** * 将物料资产包拆分为单个组件 @@ -20,24 +26,40 @@ const toPascalCase = (str) => str.split('-').map(capitalize).join('') const splitMaterials = () => { try { components.forEach((comp) => { - snippets.some((child) => { - const snippet = child.children.find((item) => { + const matchedSnippets = []; + let category = null; + + snippets.forEach((child) => { + // 修改这里:检查 children 中的 schema.componentName || snippetName + const matched = child.children.filter((item) => { + const snippetComponentName = item?.schema?.componentName || item.snippetName; + if (!snippetComponentName) return false; + if (Array.isArray(comp.component)) { - return toPascalCase(comp.component[0]) === toPascalCase(item.snippetName) + return toPascalCase(comp.component[0]) === toPascalCase(snippetComponentName); } + return toPascalCase(comp.component) === toPascalCase(snippetComponentName); + }); - return toPascalCase(comp.component) === toPascalCase(item.snippetName) - }) - - if (snippet) { - comp.snippets = [snippet] - comp.category = child.group - - return true + if (matched.length > 0) { + // 为每个 snippet 添加 category + const enrichedSnippets = matched.map(snippet => ({ + ...snippet, + category: child.group, + })); + + matchedSnippets.push(...enrichedSnippets); + // 使用第一个匹配的分组作为组件级别的类别 + if (!category) { + category = child.group; + } } + }); - return false - }) + if (matchedSnippets.length > 0) { + comp.snippets = matchedSnippets; + comp.category = category; + } const fileName = Array.isArray(comp.component) ? comp.component[0] : comp.component const componentPath = path.join(process.cwd(), materialsDir, 'components', `${toPascalCase(fileName)}.json`) From c0756436ac689e1434a693084c28d63cb2e106e2 Mon Sep 17 00:00:00 2001 From: mjzhu4 Date: Fri, 7 Mar 2025 15:13:45 +0800 Subject: [PATCH 2/2] delete Comment --- scripts/splitMaterials.mjs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/splitMaterials.mjs b/scripts/splitMaterials.mjs index 001c32cfe1..f01273b249 100644 --- a/scripts/splitMaterials.mjs +++ b/scripts/splitMaterials.mjs @@ -1,9 +1,3 @@ -/* - * @Description: - * @Date: 2025-03-07 14:29:56 - * @LastEditors: xiaopang - * @LastEditTime: 2025-03-07 14:35:20 - */ import fs from 'fs-extra' import path from 'node:path' import Logger from './logger.mjs'