refactor: gather config
This commit is contained in:
parent
0a020b63d2
commit
8ffcc2e7bb
|
@ -2,10 +2,16 @@ import D from 'debug';
|
|||
|
||||
import {basename, extname} from 'path';
|
||||
|
||||
const capitalize = (token) => token.substring(0, 1).toUpperCase() + token.substring(1);
|
||||
import {camelCase, capitalize} from './string';
|
||||
|
||||
const debug = D('@latus/core/gather');
|
||||
|
||||
export const gatherWithLatus = (context) => (latus) => (
|
||||
export const gatherWithLatus = (
|
||||
context,
|
||||
{
|
||||
transformer = camelCase,
|
||||
},
|
||||
) => (latus) => (
|
||||
Object.fromEntries(context.keys().map((path) => {
|
||||
const M = context(path).default;
|
||||
if ('function' !== typeof M) {
|
||||
|
@ -14,13 +20,21 @@ export const gatherWithLatus = (context) => (latus) => (
|
|||
);
|
||||
}
|
||||
return [
|
||||
basename(path, extname(path)).split('-').map(capitalize).join(''),
|
||||
transformer(basename(path, extname(path))),
|
||||
M(latus),
|
||||
];
|
||||
}))
|
||||
);
|
||||
|
||||
export default (latus, type, idAttribute = 'id', typeAttribute = 'type', check = () => {}) => {
|
||||
export default (
|
||||
latus,
|
||||
{
|
||||
type,
|
||||
idAttribute = 'id',
|
||||
typeAttribute = 'type',
|
||||
check = () => {},
|
||||
},
|
||||
) => {
|
||||
const gathered = latus.invokeReduce(type);
|
||||
check(gathered, type);
|
||||
const composed = latus.invokeComposed(`${type}.decorate`, gathered);
|
||||
|
|
|
@ -11,6 +11,7 @@ export {compose, fastApply} from './function';
|
|||
export {gatherWithLatus, default as gather} from './gather';
|
||||
export {default as Middleware} from './middleware';
|
||||
export {default as Latus} from './latus';
|
||||
export * from './string';
|
||||
|
||||
export const Class = class {};
|
||||
|
||||
|
|
3
packages/core/src/string.js
Normal file
3
packages/core/src/string.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
export const capitalize = (string) => string.substring(0, 1).toUpperCase() + string.substring(1);
|
||||
|
||||
export const camelCase = (string) => string.split(/[_-]/).map(capitalize).join('');
|
|
@ -30,6 +30,7 @@
|
|||
"dependencies": {
|
||||
"@latus/core": "2.0.0",
|
||||
"@latus/http": "2.0.0",
|
||||
"@latus/react": "2.0.0",
|
||||
"buffer": "^6.0.3",
|
||||
"debug": "4.3.1",
|
||||
"msgpack-lite": "^0.1.26",
|
||||
|
@ -39,7 +40,6 @@
|
|||
"socket.io-client": "2.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@latus/react": "2.0.0",
|
||||
"@neutrinojs/airbnb-base": "^9.4.0",
|
||||
"@neutrinojs/copy": "9.4.0",
|
||||
"@neutrinojs/mocha": "^9.4.0",
|
||||
|
@ -52,8 +52,5 @@
|
|||
"neutrino": "^9.4.0",
|
||||
"webpack": "^4",
|
||||
"webpack-cli": "^3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@latus/react": "2.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@ export default {
|
|||
// eslint-disable-next-line no-param-reassign
|
||||
latus.config['%packets'] = gather(
|
||||
latus,
|
||||
'@latus/socket/packets',
|
||||
'id',
|
||||
'type',
|
||||
badPacketsCheck,
|
||||
{
|
||||
type: '@latus/socket/packets',
|
||||
check: badPacketsCheck,
|
||||
},
|
||||
);
|
||||
},
|
||||
'@latus/socket/packets': (latus) => ({
|
||||
|
|
Loading…
Reference in New Issue
Block a user