Skip to content

Commit

Permalink
fix(material): add componentsMap to app Schema after material build (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
chilingling authored and hexqi committed Sep 21, 2024
1 parent 1c7d9c3 commit 67c91a7
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion scripts/buildMaterials.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ const materialsDir = 'materials'
const bundlePath = path.join(process.cwd(), '/packages/design-core/public/mock/bundle.json')
// mockServer应用数据
const appInfoPath = path.join(process.cwd(), '/mockServer/src/services/appinfo.json')
const appSchemaPath = path.join(process.cwd(), 'mockServer/src/mock/get/app-center/v1/apps/schema/918.json')

const appInfo = fsExtra.readJSONSync(appInfoPath)
const appSchema = fsExtra.readJSONSync(appSchemaPath)

const connection = new MysqlConnection()

Expand All @@ -22,6 +25,7 @@ const connection = new MysqlConnection()
const write = (bundle) => {
fsExtra.outputJSONSync(bundlePath, bundle, { spaces: 2 })
fsExtra.outputJSONSync(appInfoPath, appInfo, { spaces: 2 })
fsExtra.outputJSONSync(appSchemaPath, appSchema, { spaces: 2 })
}

/**
Expand Down Expand Up @@ -95,6 +99,7 @@ const generateComponents = () => {
}
const { components = [], snippets = [], blocks = [] } = bundle.data.materials
const componentsMap = []
const packagesMap = []
const appInfoBlocksLabels = appInfo.blockHistories.map((item) => item.label)

files.forEach((file) => {
Expand Down Expand Up @@ -151,8 +156,26 @@ const generateComponents = () => {

appInfo.materialHistory.components = componentsMap

write(bundle)
const { package: packageName = '', version = '', exportName = '' } = npm || {}

const mapItem = {
componentName: component,
package: packageName,
version,
exportName
}

if (typeof npm.destructuring === 'boolean') {
mapItem.destructuring = npm.destructuring
}

if (npm.package) {
packagesMap.push(mapItem)
}
})

appSchema.data.componentsMap = packagesMap
write(bundle)
})

logger.success('物料资产包构建成功')
Expand Down

0 comments on commit 67c91a7

Please sign in to comment.