forked from tsai/budibase
12 changed files with 224 additions and 140 deletions
@ -1,44 +1,41 @@ |
|||||
const CouchDB = require("../../db") |
const CouchDB = require("../../db") |
||||
const { resolve, join } = require("../../utilities/centralPath") |
const { join } = require("../../utilities/centralPath") |
||||
const { |
const { budibaseTempDir } = require("../../utilities/budibaseDir") |
||||
budibaseTempDir, |
const fileSystem = require("../../utilities/fileSystem") |
||||
budibaseAppsDir, |
|
||||
} = require("../../utilities/budibaseDir") |
|
||||
|
|
||||
exports.fetchAppComponentDefinitions = async function(ctx) { |
exports.fetchAppComponentDefinitions = async function(ctx) { |
||||
const appId = ctx.params.appId || ctx.appId |
const appId = ctx.params.appId || ctx.appId |
||||
const db = new CouchDB(appId) |
const db = new CouchDB(appId) |
||||
const app = await db.get(appId) |
const app = await db.get(appId) |
||||
|
|
||||
ctx.body = app.componentLibraries.reduce((acc, componentLibrary) => { |
let componentManifests = await Promise.all( |
||||
let appDirectory = resolve(budibaseAppsDir(), appId, "node_modules") |
app.componentLibraries.map(async library => { |
||||
|
let manifest |
||||
if (ctx.isDev) { |
if (ctx.isDev) { |
||||
appDirectory = budibaseTempDir() |
manifest = require(join( |
||||
} |
budibaseTempDir(), |
||||
|
library, |
||||
const componentJson = require(join( |
ctx.isDev ? "" : "package", |
||||
appDirectory, |
"manifest.json" |
||||
componentLibrary, |
)) |
||||
ctx.isDev ? "" : "package", |
} else { |
||||
"manifest.json" |
manifest = await fileSystem.getComponentLibraryManifest(appId, library) |
||||
)) |
} |
||||
|
return { |
||||
const result = {} |
manifest, |
||||
|
library, |
||||
// 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}`.toLowerCase() |
const definitions = {} |
||||
result[fullComponentName] = { |
for (let { manifest, library } of componentManifests) { |
||||
|
for (let key of Object.keys(manifest)) { |
||||
|
const fullComponentName = `${library}/${key}`.toLowerCase() |
||||
|
definitions[fullComponentName] = { |
||||
component: fullComponentName, |
component: fullComponentName, |
||||
...componentJson[key], |
...manifest[key], |
||||
} |
} |
||||
} |
} |
||||
|
} |
||||
return { |
ctx.body = definitions |
||||
...acc, |
|
||||
...result, |
|
||||
} |
|
||||
}, {}) |
|
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue