Ignore dotfiles at the api folder level

This commit is contained in:
Alexandre Bodin 2022-05-19 22:51:26 +02:00
parent bd2b1d53ad
commit c33bf9b50e

View File

@ -6,31 +6,35 @@ const _ = require('lodash');
const fse = require('fs-extra'); const fse = require('fs-extra');
const { isKebabCase } = require('@strapi/utils'); const { isKebabCase } = require('@strapi/utils');
// to handle names with numbers in it we first check if it is already in kebabCase
const normalizeName = name => (isKebabCase(name) ? name : _.kebabCase(name));
const DEFAULT_CONTENT_TYPE = { const DEFAULT_CONTENT_TYPE = {
schema: {}, schema: {},
actions: {}, actions: {},
lifecycles: {}, lifecycles: {},
}; };
// to handle names with numbers in it we first check if it is already in kebabCase
const normalizeName = name => (isKebabCase(name) ? name : _.kebabCase(name));
const isDirectory = fd => fd.isDirectory();
const isDotFile = fd => fd.name.startsWith('.');
module.exports = async strapi => { module.exports = async strapi => {
if (!existsSync(strapi.dirs.api)) { if (!existsSync(strapi.dirs.api)) {
throw new Error('Missing api folder. Please create one at `./src/api`'); throw new Error('Missing api folder. Please create one at `./src/api`');
} }
const apisFDs = await fse.readdir(strapi.dirs.api, { withFileTypes: true }); const apisFDs = await (await fse.readdir(strapi.dirs.api, { withFileTypes: true }))
.filter(isDirectory)
.filter(_.negate(isDotFile));
const apis = {}; const apis = {};
// only load folders // only load folders
for (const apiFD of apisFDs) { for (const apiFD of apisFDs) {
if (apiFD.isDirectory()) { const apiName = normalizeName(apiFD.name);
const apiName = normalizeName(apiFD.name); const api = await loadAPI(join(strapi.dirs.api, apiFD.name));
const api = await loadAPI(join(strapi.dirs.api, apiFD.name));
apis[apiName] = api; apis[apiName] = api;
}
} }
validateContentTypesUnicity(apis); validateContentTypesUnicity(apis);
@ -126,7 +130,7 @@ const loadContentTypes = async dir => {
}; };
const loadDir = async dir => { const loadDir = async dir => {
if (!(await fse.pathExists(dir)) || fse.stat(dir).isFile()) { if (!(await fse.pathExists(dir))) {
return; return;
} }