2020-05-07 11:53:34 +02:00
|
|
|
const CouchDB = require("../../db")
|
2021-03-25 14:32:05 +01:00
|
|
|
const { getComponentLibraryManifest } = require("../../utilities/fileSystem")
|
2020-05-02 16:29:10 +02:00
|
|
|
|
|
|
|
exports.fetchAppComponentDefinitions = async function(ctx) {
|
2020-11-06 22:13:21 +01:00
|
|
|
const appId = ctx.params.appId || ctx.appId
|
|
|
|
const db = new CouchDB(appId)
|
|
|
|
const app = await db.get(appId)
|
2020-10-28 21:35:06 +01:00
|
|
|
|
2021-03-23 18:54:02 +01:00
|
|
|
let componentManifests = await Promise.all(
|
|
|
|
app.componentLibraries.map(async library => {
|
2021-03-25 14:32:05 +01:00
|
|
|
let manifest = await getComponentLibraryManifest(appId, library)
|
|
|
|
|
2021-03-23 18:54:02 +01:00
|
|
|
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] = {
|
2021-01-12 21:00:35 +01:00
|
|
|
component: fullComponentName,
|
2021-03-23 18:54:02 +01:00
|
|
|
...manifest[key],
|
2020-05-07 11:53:34 +02:00
|
|
|
}
|
2020-10-28 21:35:06 +01:00
|
|
|
}
|
2021-03-23 18:54:02 +01:00
|
|
|
}
|
|
|
|
ctx.body = definitions
|
2020-05-07 11:53:34 +02:00
|
|
|
}
|