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")
|
2020-05-03 02:29:10 +12:00
|
|
|
|
2021-05-03 19:31:09 +12:00
|
|
|
exports.fetchAppComponentDefinitions = async function (ctx) {
|
2020-11-07 10:13:21 +13:00
|
|
|
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)
|
2020-10-29 09:35:06 +13:00
|
|
|
|
2021-03-24 06:54:02 +13:00
|
|
|
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)
|
|
|
|
|
2021-03-24 06:54:02 +13:00
|
|
|
return {
|
|
|
|
manifest,
|
|
|
|
library,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
const definitions = {}
|
|
|
|
for (let { manifest, library } of componentManifests) {
|
|
|
|
for (let key of Object.keys(manifest)) {
|
2021-07-08 00:53:59 +12:00
|
|
|
if (key === "features") {
|
|
|
|
definitions[key] = manifest[key]
|
|
|
|
} else {
|
|
|
|
const fullComponentName = `${library}/${key}`.toLowerCase()
|
|
|
|
definitions[fullComponentName] = {
|
|
|
|
component: fullComponentName,
|
|
|
|
...manifest[key],
|
|
|
|
}
|
2020-05-07 21:53:34 +12:00
|
|
|
}
|
2020-10-29 09:35:06 +13:00
|
|
|
}
|
2021-03-24 06:54:02 +13:00
|
|
|
}
|
|
|
|
ctx.body = definitions
|
2020-05-07 21:53:34 +12:00
|
|
|
}
|