From b2a66fb0df0e9c7d0e139b5ed1ff7b42a76284af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=95=B8?= Date: Thu, 27 Feb 2025 11:21:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=88=86=E7=A6=BB=E6=97=B6=EF=BC=8C=E7=BB=84=E4=BB=B6=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=9A=84=E4=B8=8D=E5=AE=8C=E6=95=B4=EF=BC=8C=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E7=BB=84=E4=BB=B6=E7=9A=84npm=E5=8C=85=EF=BC=8C?= =?UTF-8?q?=E8=A1=A5=E5=85=A8=E7=BB=84=E4=BB=B6npm=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/splitMaterials.mjs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/splitMaterials.mjs b/scripts/splitMaterials.mjs index b09b4379e9..8c70b157ba 100644 --- a/scripts/splitMaterials.mjs +++ b/scripts/splitMaterials.mjs @@ -9,7 +9,7 @@ const bundlePath = path.join(process.cwd(), '/designer-demo/public/mock/bundle.j // 物料文件存放文件夹名称 const materialsDir = 'materials' const bundle = fs.readJSONSync(bundlePath) -const { components, snippets, blocks } = bundle.data.materials +const { components, snippets, blocks, packages } = bundle.data.materials const capitalize = (str) => `${str.charAt(0).toUpperCase()}${str.slice(1)}` const toPascalCase = (str) => str.split('-').map(capitalize).join('') @@ -38,7 +38,12 @@ const splitMaterials = () => { return false }) - + // 补全组件的npm 字段 + const pack = packages.find((child) => child.package === comp.npm?.package); + if (pack) { + const complete = ['version', 'destructuring', 'script', 'css']; + complete.forEach(e => !comp.npm?.[e] && (comp.npm[e] = pack[e])) + } const fileName = Array.isArray(comp.component) ? comp.component[0] : comp.component const componentPath = path.join(process.cwd(), materialsDir, 'components', `${toPascalCase(fileName)}.json`) From 1f684aac3e4efdc0342ece80b6eaefdd39014c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=95=B8?= Date: Thu, 27 Feb 2025 14:35:49 +0800 Subject: [PATCH 2/2] fix: Complete the npm information of the component when running splitMaterials.js --- scripts/splitMaterials.mjs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/splitMaterials.mjs b/scripts/splitMaterials.mjs index 8c70b157ba..d161d1f6a9 100644 --- a/scripts/splitMaterials.mjs +++ b/scripts/splitMaterials.mjs @@ -40,9 +40,12 @@ const splitMaterials = () => { }) // 补全组件的npm 字段 const pack = packages.find((child) => child.package === comp.npm?.package); - if (pack) { + if (pack && comp.npm) { const complete = ['version', 'destructuring', 'script', 'css']; - complete.forEach(e => !comp.npm?.[e] && (comp.npm[e] = pack[e])) + complete.forEach(e => { + if (comp.npm[e] === undefined && pack[e]) + comp.npm[e] = pack[e] + }) } const fileName = Array.isArray(comp.component) ? comp.component[0] : comp.component const componentPath = path.join(process.cwd(), materialsDir, 'components', `${toPascalCase(fileName)}.json`)