@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
40 lines (31 loc) • 950 B
JavaScript
;
const { resolve } = require('path');
const { statSync, existsSync } = require('fs');
const { yup, importDefault } = require('@strapi/utils');
const srcSchema = yup
.object()
.shape({
bootstrap: yup.mixed().isFunction(),
register: yup.mixed().isFunction(),
destroy: yup.mixed().isFunction(),
})
.noUnknown();
const validateSrcIndex = (srcIndex) => {
return srcSchema.validateSync(srcIndex, { strict: true, abortEarly: false });
};
module.exports = (strapi) => {
if (!existsSync(strapi.dirs.dist.src)) {
return;
}
const pathToSrcIndex = resolve(strapi.dirs.dist.src, 'index.js');
if (!existsSync(pathToSrcIndex) || statSync(pathToSrcIndex).isDirectory()) {
return {};
}
const srcIndex = importDefault(pathToSrcIndex);
try {
validateSrcIndex(srcIndex);
} catch (e) {
strapi.stopWithError({ message: `Invalid file \`./src/index.js\`: ${e.message}` });
}
return srcIndex;
};