2020-05-07 11:53:34 +02:00
|
|
|
const CouchDB = require("../../db")
|
2020-10-09 11:00:57 +02:00
|
|
|
const { resolve, join } = require("../../utilities/centralPath")
|
2020-05-11 16:42:42 +02:00
|
|
|
const {
|
|
|
|
budibaseTempDir,
|
|
|
|
budibaseAppsDir,
|
|
|
|
} = require("../../utilities/budibaseDir")
|
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
|
|
|
|
|
|
|
ctx.body = app.componentLibraries.reduce((acc, componentLibrary) => {
|
2020-11-06 22:13:21 +01:00
|
|
|
let appDirectory = resolve(budibaseAppsDir(), appId, "node_modules")
|
2020-10-28 21:35:06 +01:00
|
|
|
|
|
|
|
if (ctx.isDev) {
|
|
|
|
appDirectory = budibaseTempDir()
|
|
|
|
}
|
|
|
|
|
|
|
|
const componentJson = require(join(
|
|
|
|
appDirectory,
|
|
|
|
componentLibrary,
|
|
|
|
ctx.isDev ? "" : "package",
|
|
|
|
"components.json"
|
|
|
|
))
|
|
|
|
|
|
|
|
const result = {}
|
|
|
|
|
|
|
|
// map over the components.json and add the library identifier as a key
|
|
|
|
// button -> @budibase/standard-components/button
|
|
|
|
for (let key of Object.keys(componentJson)) {
|
|
|
|
const fullComponentName = `${componentLibrary}/${key}`
|
|
|
|
result[fullComponentName] = {
|
|
|
|
_component: fullComponentName,
|
|
|
|
...componentJson[key],
|
2020-05-07 11:53:34 +02:00
|
|
|
}
|
2020-10-28 21:35:06 +01:00
|
|
|
}
|
2020-05-07 11:53:34 +02:00
|
|
|
|
2020-10-28 21:35:06 +01:00
|
|
|
return {
|
|
|
|
...acc,
|
|
|
|
...result,
|
|
|
|
}
|
|
|
|
}, {})
|
2020-05-07 11:53:34 +02:00
|
|
|
}
|