1
0
Fork 0
mirror of synced 2024-06-28 11:00:55 +12:00
budibase/packages/server/src/api/controllers/component.js

32 lines
944 B
JavaScript
Raw Normal View History

2020-05-07 21:53:34 +12:00
const CouchDB = require("../../db")
2021-05-17 08:25:37 +12:00
const { DocumentTypes } = require("../../db/utils")
2021-03-26 02:32:05 +13:00
const { getComponentLibraryManifest } = require("../../utilities/fileSystem")
2021-05-03 19:31:09 +12:00
exports.fetchAppComponentDefinitions = async function (ctx) {
const appId = ctx.params.appId || ctx.appId
const db = new CouchDB(appId)
2021-05-17 08:25:37 +12:00
const app = await db.get(DocumentTypes.APP_METADATA)
let componentManifests = await Promise.all(
2021-05-04 22:32:22 +12:00
app.componentLibraries.map(async library => {
2021-03-26 02:32:05 +13:00
let manifest = await getComponentLibraryManifest(appId, library)
return {
manifest,
library,
}
})
)
const definitions = {}
for (let { manifest, library } of componentManifests) {
for (let key of Object.keys(manifest)) {
const fullComponentName = `${library}/${key}`.toLowerCase()
definitions[fullComponentName] = {
component: fullComponentName,
...manifest[key],
2020-05-07 21:53:34 +12:00
}
}
}
ctx.body = definitions
2020-05-07 21:53:34 +12:00
}