diff --git a/client/coral-framework/components/Slot.js b/client/coral-framework/components/Slot.js index 850c86835..1f5e5829d 100644 --- a/client/coral-framework/components/Slot.js +++ b/client/coral-framework/components/Slot.js @@ -1,5 +1,6 @@ import React, {Component} from 'react'; import {importer as injectPlugins} from 'coral-framework/helpers/importer'; +import actions from 'coral-framework/actions'; class Slot extends Component { render() { diff --git a/client/coral-framework/helpers/importer.js b/client/coral-framework/helpers/importer.js index f152757c2..96adc799e 100644 --- a/client/coral-framework/helpers/importer.js +++ b/client/coral-framework/helpers/importer.js @@ -1,5 +1,3 @@ -import asd from 'coral-framework'; -console.log(asd) import {client as clientPlugins} from 'pluginsConfig'; function importer (fill) { @@ -34,25 +32,23 @@ function importer (fill) { }, {}); } - function filterByUserConfig (list) { - - /** - * filterByUserConfig will filter the imported files and will only keep the allowed plugins - */ - return list - .filter(plugin => clientPlugins.indexOf(plugin.name) > -1); - } - function addProps (plugin) { /** * addProps add properties to the injected plugins */ - plugin.props = {...getConfig(plugin.name), plugin: 'true'}; + plugin.props = { + ...actionsImporter(), + ...getConfig(plugin.name) + }; + return plugin; } function filterBySlot (plugin) { + /** + * filterBySlot + */ return plugin.props.slot === fill; } @@ -64,12 +60,13 @@ function importer (fill) { */ buildContext(); - return filterByUserConfig(importedFiles) + return importedFiles + .filter(filterByUserConfig) .filter(key => key.format === 'js') .map(addProps) .filter(filterBySlot) .reduce((entry, plugin, i) => { - entry.push(context(plugin.key)({...plugin.props, key: i})); + entry = [...entry, context(plugin.key)({...plugin.props, key: i})]; return entry; }, []); } @@ -91,16 +88,44 @@ function shapeData(test) { }; } +function filterByUserConfig (plugin) { + + /** + * filterByUserConfig will filter the imported files and will only keep the allowed plugins + */ + return clientPlugins.indexOf(plugin.name) > -1; +} + function importAll(context) { + /** + * importAll builds the map to import + */ return context .keys() .map(key => shapeData(key)) + .filter(filterByUserConfig) .reduce((entry, actionsPlugin) => { - entry[actionsPlugin.name] = context(actionsPlugin.key); - return entry; + const input = context(actionsPlugin.key); + return {...entry, ...input}; }, {}); } +function importAllAsArr(context) { + /** + * importAllAsArr builds the array to import + */ + return context + .keys() + .map(key => shapeData(key)) + .filter(filterByUserConfig) + .reduce((entry, graphPlugin) => { + const input = context(graphPlugin.key); + const res = Object.keys(input) + .map(key => input[key]); + return [...entry, ...res]; + }, []); +} + function actionsImporter () { return importAll(require.context('plugins', true, /\.\/(.*)\/client\/actions.js$/)); } @@ -110,16 +135,7 @@ function reducersImporter () { } function graphImporter () { - const context = require.context('plugins', true, /\.\/(.*)\/client\/(queries|mutations)\/index.js$/); - return context - .keys() - .map(key => shapeData(key)) - .reduce((entry, graphPlugin) => { - const input = context(graphPlugin.key); - const res = Object.keys(input) - .map(key => input[key]); - return [...entry, ...res]; - }, []); + return importAllAsArr(require.context('plugins', true, /\.\/(.*)\/client\/(queries|mutations)\/index.js$/)); } export default { diff --git a/client/coral-framework/index.js b/client/coral-framework/index.js index 081de80cd..3b653b043 100644 --- a/client/coral-framework/index.js +++ b/client/coral-framework/index.js @@ -4,7 +4,6 @@ import I18n from './modules/i18n/i18n'; import actions from './actions'; import Slot from './components/Slot'; -console.log(actions); export default { pym, Slot, diff --git a/plugins/coral-plugin-respect/client/index.js b/plugins/coral-plugin-respect/client/index.js index 9db812fcc..2ea5751a8 100644 --- a/plugins/coral-plugin-respect/client/index.js +++ b/plugins/coral-plugin-respect/client/index.js @@ -3,7 +3,6 @@ import styles from './style.css'; export default (props) => (