Skip to content

Commit

Permalink
fix: 修复物料合成脚本,支持一个组件多个snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
jieliu52 committed Feb 28, 2025
1 parent cf64f90 commit a694135
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions scripts/buildMaterials.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,24 @@ const generateComponents = () => {
materials: {
components: [],
blocks: [],
snippets: []
snippets: [],
packages: [
{
name: 'TinyVue组件库',
package: '@opentiny/vue',
version: '3.20.0',
destructuring: true,
script: 'https://unpkg.com/@opentiny/vue-runtime@~3.20/dist3/tiny-vue-pc.mjs',
css: 'https://unpkg.com/@opentiny/vue-theme@~3.20/index.css'
},
{
name: 'element-plus组件库',
package: 'element-plus',
version: '2.4.2',
script: 'https://unpkg.com/[email protected]/dist/index.full.mjs',
css: 'https://unpkg.com/[email protected]/dist/index.css'
}
]
}
}
}
Expand Down Expand Up @@ -131,20 +148,23 @@ const generateComponents = () => {

if (!valid) return

const { snippets: componentSnippets, category, ...componentInfo } = material
const { snippets: componentSnippets = [], category, ...componentInfo } = material

components.push(componentInfo)

const snippet = snippets.find((item) => item.group === category)

if (snippet) {
componentSnippets && snippet.children.push(componentSnippets[0])
} else if (category && componentInfo) {
snippets.push({
group: category,
children: componentSnippets || []
})
}
componentSnippets.forEach((c) => {
const componentCategory = c.category || category || '其他'
const snippet = snippets.find((item) => item.group === componentCategory)

if (snippet) {
snippet.children.push(c)
} else {
snippets.push({
group: componentCategory,
children: [c]
})
}
})

const { component, npm = {} } = componentInfo

Expand Down

0 comments on commit a694135

Please sign in to comment.