Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix split materials,Complete the npm information of the component.json file #1154

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions scripts/splitMaterials.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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('')
Expand Down Expand Up @@ -38,7 +38,15 @@ const splitMaterials = () => {

return false
})

// 补全组件的npm 字段
const pack = packages.find((child) => child.package === comp.npm?.package);
if (pack && comp.npm) {
const complete = ['version', 'destructuring', 'script', 'css'];
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`)

Expand Down