mirror of
https://github.com/strapi/strapi.git
synced 2025-08-07 16:29:18 +00:00
Ignore dotfiles at the api folder level
This commit is contained in:
parent
bd2b1d53ad
commit
c33bf9b50e
@ -6,32 +6,36 @@ const _ = require('lodash');
|
||||
const fse = require('fs-extra');
|
||||
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 = {
|
||||
schema: {},
|
||||
actions: {},
|
||||
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 => {
|
||||
if (!existsSync(strapi.dirs.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 = {};
|
||||
|
||||
// only load folders
|
||||
for (const apiFD of apisFDs) {
|
||||
if (apiFD.isDirectory()) {
|
||||
const apiName = normalizeName(apiFD.name);
|
||||
const api = await loadAPI(join(strapi.dirs.api, apiFD.name));
|
||||
|
||||
apis[apiName] = api;
|
||||
}
|
||||
}
|
||||
|
||||
validateContentTypesUnicity(apis);
|
||||
|
||||
@ -126,7 +130,7 @@ const loadContentTypes = async dir => {
|
||||
};
|
||||
|
||||
const loadDir = async dir => {
|
||||
if (!(await fse.pathExists(dir)) || fse.stat(dir).isFile()) {
|
||||
if (!(await fse.pathExists(dir))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user