Skip to content

Commit

Permalink
feat: add meta.json file describe material package
Browse files Browse the repository at this point in the history
  • Loading branch information
chilingling committed Feb 6, 2025
1 parent 7b429a2 commit 0aeda52
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
25 changes: 22 additions & 3 deletions packages/materials/buildMaterials.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,34 @@ const validateComponent = (file, component) => {

const generateComponents = async (entry) => {
const files = await fg('*.json', { cwd: entry })

if (!files.length) {
return
}

const bundle = {
componentsMap: [],
components: [],
snippets: []
snippets: [],
packages: []
}

const metaInfo = fsExtra.readJsonSync(path.resolve(entry, 'meta.json'), { throws: false })

if (metaInfo?.package) {
bundle.packages.push(metaInfo.package)
}

files.forEach((file) => {
const componentFiles = files.filter((fileName) => {
if (fileName === 'meta.json') {
return false
}

// 下划线开头的组件文件不导出
return !fileName.startsWith('_')
})

componentFiles.forEach((file) => {
const material = fsExtra.readJsonSync(path.resolve(entry, file), { throws: false })

if (!material) {
Expand Down Expand Up @@ -127,7 +144,8 @@ const buildComponents = async (config = {}) => {
const allBundles = {
components: [],
snippets: [],
componentsMap: []
componentsMap: [],
packages: []
}

for (const entry of entries) {
Expand All @@ -139,6 +157,7 @@ const buildComponents = async (config = {}) => {
allBundles.components = allBundles.components.concat(res.components)
allBundles.snippets = allBundles.snippets.concat(res.snippets)
allBundles.componentsMap = allBundles.componentsMap.concat(res.componentsMap)
allBundles.packages = allBundles.packages.concat(res.packages)
}
}

Expand Down
4 changes: 0 additions & 4 deletions packages/materials/src/ElementPlus/ElButton.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
"dev_mode": "proCode",
"npm": {
"package": "element-plus",
"version": "2.4.2",
"script": "https://npm.onmicrosoft.cn/[email protected]/dist/index.full.mjs",
"css": "https://npm.onmicrosoft.cn/[email protected]/dist/index.css",
"dependencies": null,
"exportName": "ElButton",
"destructuring": true
},
Expand Down
9 changes: 9 additions & 0 deletions packages/materials/src/ElementPlus/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"package": {
"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"
}
}
10 changes: 10 additions & 0 deletions packages/materials/src/TinyVue/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"package": {
"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"
}
}
1 change: 1 addition & 0 deletions packages/materials/src/html/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit 0aeda52

Please sign in to comment.