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,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user