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