budibase/packages/server/src/api/controllers/component.js

32 lines
944 B
JavaScript
Raw Normal View History

2020-05-07 11:53:34 +02:00
const CouchDB = require("../../db")
2021-05-16 22:25:37 +02:00
const { DocumentTypes } = require("../../db/utils")
2021-03-25 14:32:05 +01:00
const { getComponentLibraryManifest } = require("../../utilities/fileSystem")
2021-05-03 09:31:09 +02:00
exports.fetchAppComponentDefinitions = async function (ctx) {
const appId = ctx.params.appId || ctx.appId
const db = new CouchDB(appId)
2021-05-16 22:25:37 +02:00
const app = await db.get(DocumentTypes.APP_METADATA)
let componentManifests = await Promise.all(
2021-05-04 12:32:22 +02:00
app.componentLibraries.map(async library => {
2021-03-25 14:32:05 +01: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 11:53:34 +02:00
}
}
}
ctx.body = definitions
2020-05-07 11:53:34 +02:00
}