change project structure to use /src folder

This commit is contained in:
Pierre Noël 2021-09-15 16:41:36 +02:00
parent de3c41d716
commit de4579b25e
69 changed files with 31 additions and 32 deletions

View File

@ -15,7 +15,7 @@ module.exports = ({ env }) => ({
},
myplugin: {
enabled: true,
resolve: `./plugins/myplugin`, // From the root of the project
resolve: `./src/plugins/myplugin`, // From the root of the project
config: {
testConf: 3,
},

View File

@ -10,7 +10,7 @@ const fse = require('fs-extra');
async function clear(uid) {
const { apiName, modelName } = strapi.contentTypes[uid];
const apiFolder = path.join(strapi.dir, 'api', apiName);
const apiFolder = path.join(strapi.dir, 'src', 'api', apiName);
await recursiveRemoveFiles(apiFolder, createDeleteApiFunction(modelName));
await deleteBackup(uid);
@ -23,8 +23,8 @@ async function clear(uid) {
async function backup(uid) {
const { apiName } = strapi.contentTypes[uid];
const apiFolder = path.join(strapi.dir, 'api', apiName);
const backupFolder = path.join(strapi.dir, 'api', '.backup', apiName);
const apiFolder = path.join(strapi.dir, 'src', 'api', apiName);
const backupFolder = path.join(strapi.dir, 'src', 'api', '.backup', apiName);
// backup the api folder
await fse.copy(apiFolder, backupFolder);
@ -37,8 +37,8 @@ async function backup(uid) {
async function deleteBackup(uid) {
const { apiName } = strapi.contentTypes[uid];
const backupFolder = path.join(strapi.dir, 'api', '.backup');
const apiBackupFolder = path.join(strapi.dir, 'api', '.backup', apiName);
const backupFolder = path.join(strapi.dir, 'src', 'api', '.backup');
const apiBackupFolder = path.join(strapi.dir, 'src', 'api', '.backup', apiName);
await fse.remove(apiBackupFolder);
@ -55,8 +55,8 @@ async function deleteBackup(uid) {
async function rollback(uid) {
const { apiName } = strapi.contentTypes[uid];
const apiFolder = path.join(strapi.dir, 'api', apiName);
const backupFolder = path.join(strapi.dir, 'api', '.backup', apiName);
const apiFolder = path.join(strapi.dir, 'src', 'api', apiName);
const backupFolder = path.join(strapi.dir, 'src', 'api', '.backup', apiName);
const exists = await fse.exists(backupFolder);

View File

@ -11,7 +11,7 @@ const createBuilder = require('./schema-builder');
* @param {Object} infos new category data
*/
const editCategory = async (name, infos) => {
const componentsDir = join(strapi.dir, 'components');
const componentsDir = join(strapi.dir, 'src', 'components');
const newName = nameToSlug(infos.name);
// don't do anything the name doesn't change

View File

@ -1,5 +1,6 @@
'use strict';
const { join } = require('path');
const _ = require('lodash');
const { getOr } = require('lodash/fp');
@ -127,7 +128,11 @@ const createContentType = async ({ contentType, components = [] }, options = {})
*/
const generateAPI = ({ name, kind = 'collectionType' }) => {
const strapiGenerators = require('@strapi/generators');
return strapiGenerators.generate('api', { id: nameToSlug(name), kind }, { dir: strapi.dir });
return strapiGenerators.generate(
'api',
{ id: nameToSlug(name), kind },
{ dir: join(strapi.dir, 'src') }
);
};
/**

View File

@ -38,7 +38,7 @@ module.exports = function createComponentBuilder() {
}
const handler = createSchemaHandler({
dir: path.join(strapi.dir, 'components', nameToSlug(infos.category)),
dir: path.join(strapi.dir, 'src', 'components', nameToSlug(infos.category)),
filename: `${nameToSlug(infos.name)}.json`,
});
@ -87,7 +87,7 @@ module.exports = function createComponentBuilder() {
throw new Error('component.edit.alreadyExists');
}
const newDir = path.join(strapi.dir, 'components', newCategory);
const newDir = path.join(strapi.dir, 'src', 'components', newCategory);
const oldAttributes = component.schema.attributes;

View File

@ -80,7 +80,7 @@ module.exports = function createComponentBuilder() {
const modelName = nameToSlug(infos.name);
const contentType = createSchemaHandler({
modelName: modelName,
dir: path.join(strapi.dir, 'api', modelName, 'content-types', modelName),
dir: path.join(strapi.dir, 'src', 'api', modelName, 'content-types', modelName),
filename: `schema.json`,
});

View File

@ -22,7 +22,7 @@ module.exports = function createBuilder() {
plugin: compo.modelName,
uid: compo.uid,
filename: compo.__filename__,
dir: path.join(strapi.dir, 'components', compo.category),
dir: path.join(strapi.dir, 'src', 'components', compo.category),
schema: compo.__schema__,
};
});
@ -30,21 +30,15 @@ module.exports = function createBuilder() {
const contentTypes = Object.keys(strapi.contentTypes).map(key => {
const contentType = strapi.contentTypes[key];
let dir;
let filename;
if (contentType.plugin) {
dir = `./extensions/${contentType.plugin}/content-types/${contentType.info.singularName}`;
filename = 'schema.json';
} else {
dir = `./api/${contentType.apiName}/content-types/${contentType.info.singularName}`;
filename = 'schema.json';
}
const dir = contentType.plugin
? `./src/extensions/${contentType.plugin}/content-types/${contentType.info.singularName}`
: `./src/api/${contentType.apiName}/content-types/${contentType.info.singularName}`;
return {
modelName: contentType.modelName,
plugin: contentType.plugin,
uid: contentType.uid,
filename,
filename: 'schema.json',
dir: path.join(strapi.dir, dir),
schema: contentType.__schema__,
};

View File

@ -124,8 +124,8 @@ function watchFileChanges({ dir, strapiInstance, watchIgnoreFiles, polling }) {
/tmp/,
'**/admin',
'**/admin/**',
'extensions/**/admin',
'extensions/**/admin/**',
'src/extensions/**/admin',
'src/extensions/**/admin/**',
'**/documentation',
'**/documentation/**',
'**/node_modules',

View File

@ -14,10 +14,10 @@ const DEFAULT_CONTENT_TYPE = {
};
module.exports = async strapi => {
const apisDir = join(strapi.dir, 'api');
const apisDir = join(strapi.dir, 'src', 'api');
if (!existsSync(apisDir)) {
throw new Error(`Missing api folder. Please create one in your app root directory`);
throw new Error('Missing api folder. Please create one at `./src/api`');
}
const apisFDs = await fse.readdir(apisDir, { withFileTypes: true });

View File

@ -6,7 +6,7 @@ const { pathExists } = require('fs-extra');
const loadFiles = require('../../load/load-files');
module.exports = async strapi => {
const componentsDir = join(strapi.dir, 'components');
const componentsDir = join(strapi.dir, 'src', 'components');
if (!(await pathExists(componentsDir))) {
return {};

View File

@ -45,7 +45,7 @@ const createLoaders = strapi => {
loadMiddlewaresInDir(path.resolve(__dirname, '..', '..', 'middlewares'), middlewares);
const loadLocalMiddlewares = (appPath, middlewares) =>
loadMiddlewaresInDir(path.resolve(appPath, 'middlewares'), middlewares);
loadMiddlewaresInDir(path.resolve(appPath, 'src', 'middlewares'), middlewares);
const loadMiddlewareDependencies = async (packages, middlewares) => {
for (let packageName of packages) {

View File

@ -25,7 +25,7 @@ const defaultPlugin = {
};
const applyUserExtension = async plugins => {
const extensionsDir = resolve(strapi.dir, 'extensions');
const extensionsDir = resolve(strapi.dir, 'src', 'extensions');
if (!existsSync(extensionsDir)) {
return;
}

View File

@ -5,7 +5,7 @@ const fse = require('fs-extra');
// TODO:: allow folders with index.js inside for bigger policies
module.exports = async function loadPolicies(strapi) {
const dir = join(strapi.dir, 'policies');
const dir = join(strapi.dir, 'src', 'policies');
if (!(await fse.pathExists(dir))) {
return;