mirror of
https://github.com/strapi/strapi.git
synced 2025-09-23 15:29:27 +00:00
Merge pull request #12277 from jamidwyer/fix/api-loader-git-config
fix: skip git config file that looks like dir
This commit is contained in:
commit
75be9323ea
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user