2020-05-07 11:53:34 +02:00
|
|
|
const CouchDB = require("../../db")
|
2020-05-18 07:40:29 +02:00
|
|
|
const ClientDb = require("../../db/clientDb")
|
2020-05-07 11:53:34 +02:00
|
|
|
const { resolve, join } = require("path")
|
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-06-11 11:12:01 +02:00
|
|
|
const masterDb = new CouchDB("clientAppLookup")
|
2020-06-10 22:39:30 +02:00
|
|
|
const { clientId } = await masterDb.get(ctx.params.appId)
|
|
|
|
const db = new CouchDB(ClientDb.name(clientId))
|
2020-05-02 16:29:10 +02:00
|
|
|
const app = await db.get(ctx.params.appId)
|
|
|
|
|
2020-05-07 11:53:34 +02:00
|
|
|
const componentDefinitions = app.componentLibraries.reduce(
|
|
|
|
(acc, componentLibrary) => {
|
|
|
|
let appDirectory = resolve(
|
2020-05-11 16:42:42 +02:00
|
|
|
budibaseAppsDir(),
|
2020-05-07 11:53:34 +02:00
|
|
|
ctx.params.appId,
|
|
|
|
"node_modules"
|
|
|
|
)
|
|
|
|
|
2020-05-11 17:01:02 +02:00
|
|
|
if (ctx.isDev) {
|
2020-05-11 16:42:42 +02:00
|
|
|
appDirectory = budibaseTempDir()
|
2020-05-07 11:53:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const componentJson = require(join(
|
|
|
|
appDirectory,
|
|
|
|
componentLibrary,
|
|
|
|
"components.json"
|
|
|
|
))
|
|
|
|
|
|
|
|
const result = {}
|
|
|
|
|
|
|
|
// map over the components.json and add the library identifier as a key
|
|
|
|
// button -> @budibase/standard-components/button
|
|
|
|
for (key in componentJson) {
|
|
|
|
const fullComponentName = `${componentLibrary}/${key}`
|
|
|
|
result[fullComponentName] = {
|
|
|
|
_component: fullComponentName,
|
|
|
|
...componentJson[key],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...acc,
|
|
|
|
...result,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
|
|
|
|
ctx.body = componentDefinitions
|
|
|
|
}
|