1
0
Fork 0
mirror of synced 2024-07-02 13:01:09 +12:00
budibase/packages/builder/src/builderStore/loadComponentLibraries.js

30 lines
1 KiB
JavaScript
Raw Normal View History

2020-06-04 07:44:35 +12:00
import { get } from "builderStore/api"
2020-06-04 07:35:30 +12:00
/**
* Fetches the definitions for component library components. This includes
* their props and other metadata from components.json.
* @param {string} appId - ID of the currently running app
*/
export const fetchComponentLibDefinitions = async appId => {
const LIB_DEFINITION_URL = `/${appId}/components/definitions`
try {
2020-06-04 07:35:30 +12:00
const libDefinitionResponse = await get(LIB_DEFINITION_URL)
2020-05-07 21:53:34 +12:00
return await libDefinitionResponse.json()
} catch (err) {
2020-05-07 21:53:34 +12:00
console.error(`Error fetching component definitions for ${appId}`, err)
}
2020-05-07 21:53:34 +12:00
}
/**
* Loads the JavaScript files for app component libraries and returns a map of their modules.
* @param {object} application - package definition
*/
export const fetchComponentLibModules = async application => {
const allLibraries = {}
for (let libraryName of application.componentLibraries) {
2020-05-07 21:53:34 +12:00
const LIBRARY_URL = `/${application._id}/componentlibrary?library=${libraryName}`
allLibraries[libraryName] = await import(LIBRARY_URL)
}
return allLibraries
2019-08-20 08:18:23 +12:00
}