diff --git a/packages/core/src/gather.js b/packages/core/src/gather.js index aeae7b3..3e2de00 100644 --- a/packages/core/src/gather.js +++ b/packages/core/src/gather.js @@ -13,7 +13,7 @@ const debug = D('@latus/core/gather'); export const hotGathered = new Map(); -const transformPath = (transformer, path) => { +export const transformPath = (transformer, path) => { const parts = dirname(path).split('/'); if ('.' === parts[0]) { parts.shift(); diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 08417f2..cc5363e 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -16,6 +16,7 @@ export { gatherFlat, gatherWithLatus, default as gather, + transformPath, } from './gather'; export {default as Middleware} from './middleware'; export {default as Latus} from './latus'; diff --git a/packages/react/src/gather-components.js b/packages/react/src/gather-components.js new file mode 100644 index 0000000..14542e6 --- /dev/null +++ b/packages/react/src/gather-components.js @@ -0,0 +1,24 @@ +import { + camelCase, + transformPath, +} from '@latus/core'; + +export default ( + context, + { + transformer = camelCase, + } = {}, +) => () => ( + Object.fromEntries( + context.keys() + .map( + (path) => { + const {default: Component} = context(path); + return [ + transformPath(transformer, path), + Component, + ]; + }, + ), + ) +); diff --git a/packages/react/src/index.js b/packages/react/src/index.js index 8648f98..3f63f2c 100644 --- a/packages/react/src/index.js +++ b/packages/react/src/index.js @@ -1,10 +1,12 @@ export {default as React} from 'react'; export * from 'react'; export {default as ReactDom} from 'react-dom'; +export {hot} from 'react-hot-loader'; export {default as PropTypes} from 'prop-types'; // eslint-disable-next-line import/no-extraneous-dependencies export {LatusContext} from '@latus/react/client'; +export {default as gatherComponents} from './gather-components'; export {default as useEvent} from './hooks/use-event'; export {default as useLatus} from './hooks/use-latus'; export {default as usePrevious} from './hooks/use-previous';