2020-05-07 11:53:34 +02:00
|
|
|
const CouchDB = require("../../db")
|
2021-03-23 18:54:02 +01:00
|
|
|
const { join } = require("../../utilities/centralPath")
|
|
|
|
const { budibaseTempDir } = require("../../utilities/budibaseDir")
|
|
|
|
const fileSystem = require("../../utilities/fileSystem")
|
2021-03-24 19:21:23 +01:00
|
|
|
const env = require("../../environment")
|
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 => {
|
|
|
|
let manifest
|
2021-03-25 12:41:41 +01:00
|
|
|
if (env.isDev() && !env.isTest()) {
|
2021-03-24 19:21:23 +01:00
|
|
|
manifest = require(join(budibaseTempDir(), library, "manifest.json"))
|
2021-03-23 18:54:02 +01:00
|
|
|
} else {
|
|
|
|
manifest = await fileSystem.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] = {
|
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
|
|
|
}
|