From 6c3ce66eeb4f5d18dc900275176f787d1b749af9 Mon Sep 17 00:00:00 2001 From: webzmj530 Date: Tue, 11 Mar 2025 17:23:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=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=9F=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E4=B8=80=E4=B8=AA=E5=88=86=E7=BB=84=E9=87=8C=E9=9D=A2?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E4=B8=A4=E4=B8=AA=E7=BB=84=E4=BB=B6(componen?= =?UTF-8?q?tName=E7=9B=B8=E5=90=8C,=20snippetName=E4=B8=8D=E5=90=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/splitMaterials.mjs | 54 ++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/scripts/splitMaterials.mjs b/scripts/splitMaterials.mjs index abed48ed8b..5e47078a87 100644 --- a/scripts/splitMaterials.mjs +++ b/scripts/splitMaterials.mjs @@ -1,3 +1,9 @@ +/* + * @Description: + * @Date: 2025-03-11 09:54:10 + * @LastEditors: xiaopang + * @LastEditTime: 2025-03-11 09:54:29 + */ import fs from 'fs-extra' import path from 'node:path' import Logger from './logger.mjs' @@ -19,25 +25,39 @@ const toPascalCase = (str) => str.split('-').map(capitalize).join('') */ const splitMaterials = () => { try { - components.forEach((comp) => { - snippets.some((child) => { - const snippet = child.children.find((item) => { - if (Array.isArray(comp.component)) { - return toPascalCase(comp.component[0]) === toPascalCase(item.snippetName) - } - - return toPascalCase(comp.component) === toPascalCase(item.snippetName) - }) - - if (snippet) { - comp.snippets = [snippet] - comp.category = child.group - - return true + // 预处理 snippets + const snippetsMap = {} + snippets.forEach((snippetItem) => { + if (!Array.isArray(snippetItem?.children)) { + return + } + + snippetItem.children.forEach((item) => { + const key = item?.schema?.componentName || item.snippetName + if (!key) { + return } - - return false + const realKey = toPascalCase(key) + if (!snippetsMap[realKey]) { + snippetsMap[realKey] = [] + } + snippetsMap[realKey].push({ + ...item, + category: snippetItem.group + }) }) + }) + // 处理组件 + components.forEach((comp) => { + const matchKey = Array.isArray(comp.component) + ? toPascalCase(comp.component[0]) + : toPascalCase(comp.component) + + const matchedSnippets = snippetsMap[matchKey] + + if (matchedSnippets?.length) { + comp.snippets = matchedSnippets + } const fileName = Array.isArray(comp.component) ? comp.component[0] : comp.component const componentPath = path.join(process.cwd(), materialsDir, 'components', `${toPascalCase(fileName)}.json`) From b5d67cd2c864019d0cd80a75c70bb290414bced9 Mon Sep 17 00:00:00 2001 From: webzmj530 Date: Tue, 11 Mar 2025 17:26:32 +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 5e47078a87..7c380fe856 100644 --- a/scripts/splitMaterials.mjs +++ b/scripts/splitMaterials.mjs @@ -1,9 +1,3 @@ -/* - * @Description: - * @Date: 2025-03-11 09:54:10 - * @LastEditors: xiaopang - * @LastEditTime: 2025-03-11 09:54:29 - */ import fs from 'fs-extra' import path from 'node:path' import Logger from './logger.mjs'