mirror of
https://github.com/strapi/strapi.git
synced 2025-12-28 07:33:17 +00:00
Update conf and add walk utility
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
960315c066
commit
096f4b0df5
@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const util = require('util');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = (initialConfig = {}) => {
|
||||
@ -26,9 +25,5 @@ module.exports = (initialConfig = {}) => {
|
||||
_.merge(_config, ...args);
|
||||
return this;
|
||||
},
|
||||
|
||||
_dump() {
|
||||
console.log(util.inspect(_config, false, null, true));
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@ -1,22 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const fse = require('fs-extra');
|
||||
|
||||
const walk = require('./walk');
|
||||
|
||||
const loadFunctions = dir => {
|
||||
if (!fs.existsSync(dir)) return {};
|
||||
if (!fse.existsSync(dir)) return {};
|
||||
|
||||
return fs.readdirSync(dir, { withFileTypes: true }).reduce((acc, file) => {
|
||||
const key = path.basename(file.name, path.extname(file.name));
|
||||
|
||||
if (file.isFile()) {
|
||||
acc[key] = loadFunction(path.resolve(dir, file.name));
|
||||
} else if (file.isDirectory()) {
|
||||
acc[key] = loadFunctions(path.resolve(dir, file.name));
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
return walk(dir, { loader: loadFunction });
|
||||
};
|
||||
|
||||
const loadFunction = file => {
|
||||
|
||||
@ -2,21 +2,24 @@
|
||||
|
||||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const fse = require('fs-extra');
|
||||
|
||||
module.exports = dir => {
|
||||
if (!fs.existsSync(dir)) return {};
|
||||
if (!fse.existsSync(dir)) return {};
|
||||
|
||||
return fs
|
||||
.readdirSync(dir, { withFileTypes: true })
|
||||
.filter(file => file.isFile())
|
||||
.reduce((acc, file) => {
|
||||
const key = path.basename(file.name, path.extname(file.name));
|
||||
const root = {};
|
||||
const paths = fse.readdirSync(dir, { withFileTypes: true }).filter(fd => fd.isFile());
|
||||
|
||||
acc[key] = loadPolicy(path.resolve(dir, file.name));
|
||||
for (let fd of paths) {
|
||||
const { name } = fd;
|
||||
const fullPath = dir + path.sep + name;
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
const ext = path.extname(name);
|
||||
const key = path.basename(name, ext);
|
||||
root[key] = loadPolicy(fullPath);
|
||||
}
|
||||
|
||||
return root;
|
||||
};
|
||||
|
||||
const loadPolicy = file => {
|
||||
|
||||
27
packages/strapi/lib/core/walk.js
Normal file
27
packages/strapi/lib/core/walk.js
Normal file
@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const fse = require('fs-extra');
|
||||
|
||||
module.exports = function walk(dir, { loader } = {}) {
|
||||
assert(typeof loader === 'function', 'opts.loader must be a function');
|
||||
|
||||
const root = {};
|
||||
const paths = fse.readdirSync(dir, { withFileTypes: true });
|
||||
|
||||
for (let fd of paths) {
|
||||
const { name } = fd;
|
||||
const fullPath = dir + path.sep + name;
|
||||
|
||||
if (fd.isDirectory()) {
|
||||
root[name] = walk(fullPath, { loader });
|
||||
} else {
|
||||
const ext = path.extname(name);
|
||||
const key = path.basename(name, ext);
|
||||
root[key] = loader(fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
return root;
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const coreStoreModel = config => ({
|
||||
connection: config.get('currentEnvironment.database.defaultConnection'),
|
||||
connection: config.get('database.defaultConnection'),
|
||||
uid: 'strapi::core-store',
|
||||
internal: true,
|
||||
info: {
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
'use strict';
|
||||
|
||||
const webhookModel = config => ({
|
||||
connection: config.get('currentEnvironment.database.defaultConnection'),
|
||||
connection: config.get('database.defaultConnection'),
|
||||
uid: 'strapi::webhooks',
|
||||
internal: true,
|
||||
globalId: 'StrapiWebhooks',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user