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:
Alexandre BODIN 2022-05-20 09:02:03 +02:00 committed by GitHub
commit 75be9323ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);