UNPKG

@digicms/cms

Version:

An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite

43 lines (33 loc) 1.25 kB
'use strict'; const { join } = require('path'); const _ = require('lodash'); const { pathExists } = require('fs-extra'); const loadFiles = require('../../load/load-files'); module.exports = async (strapi) => { if (!(await pathExists(strapi.dirs.dist.components))) { return {}; } const map = await loadFiles(strapi.dirs.dist.components, '*/*.*(js|json)'); return Object.keys(map).reduce((acc, category) => { Object.keys(map[category]).forEach((key) => { const schema = map[category][key]; if (!schema.collectionName) { // NOTE: We're using the filepath from the app directory instead of the dist for information purpose const filePath = join(strapi.dirs.app.components, category, schema.__filename__); return strapi.stopWithError( `Component ${key} is missing a "collectionName" property.\nVerify file ${filePath}.` ); } const uid = `${category}.${key}`; acc[uid] = Object.assign(schema, { __schema__: _.cloneDeep(schema), uid, category, modelType: 'component', modelName: key, globalId: schema.globalId || _.upperFirst(_.camelCase(`component_${uid}`)), }); }); return acc; }, {}); };