mirror of
https://github.com/strapi/strapi.git
synced 2025-08-01 05:17:14 +00:00
Change the way we load plugins
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
1106c07795
commit
96e092b300
@ -57,16 +57,20 @@ const { dispatch } = store;
|
|||||||
const MOUNT_NODE =
|
const MOUNT_NODE =
|
||||||
document.getElementById('app') || document.createElement('div');
|
document.getElementById('app') || document.createElement('div');
|
||||||
|
|
||||||
Object.keys(plugins).forEach(plugin => {
|
Object.keys(plugins).forEach(current => {
|
||||||
const currentPlugin = plugins[plugin];
|
const registerPlugin = plugin => {
|
||||||
|
return plugin;
|
||||||
|
};
|
||||||
|
const currentPluginFn = plugins[current];
|
||||||
|
const plugin = currentPluginFn({ registerPlugin });
|
||||||
|
|
||||||
const pluginTradsPrefixed = languages.reduce((acc, lang) => {
|
const pluginTradsPrefixed = languages.reduce((acc, lang) => {
|
||||||
const currentLocale = currentPlugin.trads[lang];
|
const currentLocale = plugin.trads[lang];
|
||||||
|
|
||||||
if (currentLocale) {
|
if (currentLocale) {
|
||||||
const localeprefixedWithPluginId = Object.keys(currentLocale).reduce(
|
const localeprefixedWithPluginId = Object.keys(currentLocale).reduce(
|
||||||
(acc2, current) => {
|
(acc2, current) => {
|
||||||
acc2[`${plugins[plugin].id}.${current}`] = currentLocale[current];
|
acc2[`${plugin.id}.${current}`] = currentLocale[current];
|
||||||
|
|
||||||
return acc2;
|
return acc2;
|
||||||
},
|
},
|
||||||
@ -81,7 +85,7 @@ Object.keys(plugins).forEach(plugin => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
merge(translationMessages, pluginTradsPrefixed);
|
merge(translationMessages, pluginTradsPrefixed);
|
||||||
dispatch(pluginLoaded(currentPlugin));
|
dispatch(pluginLoaded(plugin));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log({ err });
|
console.log({ err });
|
||||||
}
|
}
|
||||||
|
@ -92,8 +92,9 @@ describe('<Admin />', () => {
|
|||||||
it('should render the routes', () => {
|
it('should render the routes', () => {
|
||||||
const renderedComponent = shallow(<Admin {...props} />);
|
const renderedComponent = shallow(<Admin {...props} />);
|
||||||
const { renderRoute } = renderedComponent.instance();
|
const { renderRoute } = renderedComponent.instance();
|
||||||
|
const Compo = () => <div>compo</div>;
|
||||||
|
|
||||||
expect(renderRoute()).not.toBeNull();
|
expect(renderRoute({}, Compo)).not.toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
import pluginPkg from '../../package.json';
|
import pluginPkg from '../../package.json';
|
||||||
import pluginId from './pluginId';
|
import pluginId from './pluginId';
|
||||||
import App from './containers/Main';
|
import App from './containers/Main';
|
||||||
@ -7,13 +5,10 @@ import Initializer from './containers/Initializer';
|
|||||||
import lifecycles from './lifecycles';
|
import lifecycles from './lifecycles';
|
||||||
import trads from './translations';
|
import trads from './translations';
|
||||||
|
|
||||||
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
|
export default strapi => {
|
||||||
|
const pluginDescription =
|
||||||
function Comp(props) {
|
pluginPkg.strapi.description || pluginPkg.description;
|
||||||
return <App {...props} />;
|
const plugin = {
|
||||||
}
|
|
||||||
|
|
||||||
const plugin = {
|
|
||||||
blockerComponent: null,
|
blockerComponent: null,
|
||||||
blockerComponentProps: {},
|
blockerComponentProps: {},
|
||||||
description: pluginDescription,
|
description: pluginDescription,
|
||||||
@ -26,12 +21,13 @@ const plugin = {
|
|||||||
lifecycles,
|
lifecycles,
|
||||||
leftMenuLinks: [],
|
leftMenuLinks: [],
|
||||||
leftMenuSections: [],
|
leftMenuSections: [],
|
||||||
mainComponent: Comp,
|
mainComponent: App,
|
||||||
name: pluginPkg.strapi.name,
|
name: pluginPkg.strapi.name,
|
||||||
preventComponentRendering: false,
|
preventComponentRendering: false,
|
||||||
suffixUrl: () => '/ctm-configurations/models',
|
suffixUrl: () => '/ctm-configurations/models',
|
||||||
suffixUrlToReplaceForLeftMenuHighlight: '/models',
|
suffixUrlToReplaceForLeftMenuHighlight: '/models',
|
||||||
trads,
|
trads,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default plugin;
|
return strapi.registerPlugin(plugin);
|
||||||
|
};
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import React from 'react';
|
|
||||||
import pluginPkg from '../../package.json';
|
import pluginPkg from '../../package.json';
|
||||||
import App from './containers/App';
|
import App from './containers/App';
|
||||||
import Initializer from './containers/Initializer';
|
import Initializer from './containers/Initializer';
|
||||||
@ -8,13 +7,10 @@ import lifecycles from './lifecycles';
|
|||||||
import trads from './translations';
|
import trads from './translations';
|
||||||
import pluginId from './pluginId';
|
import pluginId from './pluginId';
|
||||||
|
|
||||||
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
|
export default strapi => {
|
||||||
|
const pluginDescription =
|
||||||
function Comp(props) {
|
pluginPkg.strapi.description || pluginPkg.description;
|
||||||
return <App {...props} />;
|
const plugin = {
|
||||||
}
|
|
||||||
|
|
||||||
const plugin = {
|
|
||||||
blockerComponent: null,
|
blockerComponent: null,
|
||||||
blockerComponentProps: {},
|
blockerComponentProps: {},
|
||||||
description: pluginDescription,
|
description: pluginDescription,
|
||||||
@ -45,10 +41,11 @@ const plugin = {
|
|||||||
lifecycles,
|
lifecycles,
|
||||||
leftMenuLinks: [],
|
leftMenuLinks: [],
|
||||||
leftMenuSections: [],
|
leftMenuSections: [],
|
||||||
mainComponent: Comp,
|
mainComponent: App,
|
||||||
name: pluginPkg.strapi.name,
|
name: pluginPkg.strapi.name,
|
||||||
preventComponentRendering: false,
|
preventComponentRendering: false,
|
||||||
trads,
|
trads,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default plugin;
|
return strapi.registerPlugin(plugin);
|
||||||
|
};
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import React from 'react';
|
|
||||||
import pluginPkg from '../../package.json';
|
import pluginPkg from '../../package.json';
|
||||||
import pluginId from './pluginId';
|
import pluginId from './pluginId';
|
||||||
import App from './containers/App';
|
import App from './containers/App';
|
||||||
@ -6,13 +5,10 @@ import Initializer from './containers/Initializer';
|
|||||||
import lifecycles from './lifecycles';
|
import lifecycles from './lifecycles';
|
||||||
import trads from './translations';
|
import trads from './translations';
|
||||||
|
|
||||||
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
|
export default strapi => {
|
||||||
|
const pluginDescription =
|
||||||
function Comp(props) {
|
pluginPkg.strapi.description || pluginPkg.description;
|
||||||
return <App {...props} />;
|
const plugin = {
|
||||||
}
|
|
||||||
|
|
||||||
const plugin = {
|
|
||||||
blockerComponent: null,
|
blockerComponent: null,
|
||||||
blockerComponentProps: {},
|
blockerComponentProps: {},
|
||||||
description: pluginDescription,
|
description: pluginDescription,
|
||||||
@ -25,10 +21,11 @@ const plugin = {
|
|||||||
lifecycles,
|
lifecycles,
|
||||||
leftMenuLinks: [],
|
leftMenuLinks: [],
|
||||||
leftMenuSections: [],
|
leftMenuSections: [],
|
||||||
mainComponent: Comp,
|
mainComponent: App,
|
||||||
name: pluginPkg.strapi.name,
|
name: pluginPkg.strapi.name,
|
||||||
preventComponentRendering: false,
|
preventComponentRendering: false,
|
||||||
trads,
|
trads,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default plugin;
|
return strapi.registerPlugin(plugin);
|
||||||
|
};
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import React from 'react';
|
|
||||||
import pluginPkg from '../../package.json';
|
import pluginPkg from '../../package.json';
|
||||||
import pluginId from './pluginId';
|
import pluginId from './pluginId';
|
||||||
import App from './containers/App';
|
import App from './containers/App';
|
||||||
@ -6,13 +5,11 @@ import Initializer from './containers/Initializer';
|
|||||||
import lifecycles from './lifecycles';
|
import lifecycles from './lifecycles';
|
||||||
import trads from './translations';
|
import trads from './translations';
|
||||||
|
|
||||||
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
|
export default strapi => {
|
||||||
|
const pluginDescription =
|
||||||
|
pluginPkg.strapi.description || pluginPkg.description;
|
||||||
|
|
||||||
function Comp(props) {
|
const plugin = {
|
||||||
return <App {...props} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
const plugin = {
|
|
||||||
blockerComponent: null,
|
blockerComponent: null,
|
||||||
blockerComponentProps: {},
|
blockerComponentProps: {},
|
||||||
description: pluginDescription,
|
description: pluginDescription,
|
||||||
@ -24,10 +21,11 @@ const plugin = {
|
|||||||
lifecycles,
|
lifecycles,
|
||||||
leftMenuLinks: [],
|
leftMenuLinks: [],
|
||||||
leftMenuSections: [],
|
leftMenuSections: [],
|
||||||
mainComponent: Comp,
|
mainComponent: App,
|
||||||
name: pluginPkg.strapi.name,
|
name: pluginPkg.strapi.name,
|
||||||
preventComponentRendering: false,
|
preventComponentRendering: false,
|
||||||
trads,
|
trads,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default plugin;
|
return strapi.registerPlugin(plugin);
|
||||||
|
};
|
||||||
|
@ -1,19 +1,14 @@
|
|||||||
import React from 'react';
|
|
||||||
import pluginPkg from '../../package.json';
|
import pluginPkg from '../../package.json';
|
||||||
import App from './containers/App';
|
import App from './containers/App';
|
||||||
import Initializer from './containers/Initializer';
|
import Initializer from './containers/Initializer';
|
||||||
|
|
||||||
import lifecycles from './lifecycles';
|
import lifecycles from './lifecycles';
|
||||||
import trads from './translations';
|
import trads from './translations';
|
||||||
import pluginId from './pluginId';
|
import pluginId from './pluginId';
|
||||||
|
|
||||||
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
|
export default strapi => {
|
||||||
|
const pluginDescription =
|
||||||
function Comp(props) {
|
pluginPkg.strapi.description || pluginPkg.description;
|
||||||
return <App {...props} />;
|
const plugin = {
|
||||||
}
|
|
||||||
|
|
||||||
const plugin = {
|
|
||||||
blockerComponent: null,
|
blockerComponent: null,
|
||||||
blockerComponentProps: {},
|
blockerComponentProps: {},
|
||||||
description: pluginDescription,
|
description: pluginDescription,
|
||||||
@ -25,10 +20,11 @@ const plugin = {
|
|||||||
lifecycles,
|
lifecycles,
|
||||||
leftMenuLinks: [],
|
leftMenuLinks: [],
|
||||||
leftMenuSections: [],
|
leftMenuSections: [],
|
||||||
mainComponent: Comp,
|
mainComponent: App,
|
||||||
name: pluginPkg.strapi.name,
|
name: pluginPkg.strapi.name,
|
||||||
preventComponentRendering: false,
|
preventComponentRendering: false,
|
||||||
trads,
|
trads,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default plugin;
|
return strapi.registerPlugin(plugin);
|
||||||
|
};
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import React from 'react';
|
|
||||||
import pluginPkg from '../../package.json';
|
import pluginPkg from '../../package.json';
|
||||||
import layout from '../../config/layout';
|
import layout from '../../config/layout';
|
||||||
import pluginId from './pluginId';
|
import pluginId from './pluginId';
|
||||||
@ -7,13 +6,11 @@ import Initializer from './containers/Initializer';
|
|||||||
import lifecycles from './lifecycles';
|
import lifecycles from './lifecycles';
|
||||||
import trads from './translations';
|
import trads from './translations';
|
||||||
|
|
||||||
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
|
export default strapi => {
|
||||||
|
const pluginDescription =
|
||||||
|
pluginPkg.strapi.description || pluginPkg.description;
|
||||||
|
|
||||||
function Comp(props) {
|
const plugin = {
|
||||||
return <App {...props} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
const plugin = {
|
|
||||||
blockerComponent: null,
|
blockerComponent: null,
|
||||||
blockerComponentProps: {},
|
blockerComponentProps: {},
|
||||||
description: pluginDescription,
|
description: pluginDescription,
|
||||||
@ -25,12 +22,13 @@ const plugin = {
|
|||||||
lifecycles,
|
lifecycles,
|
||||||
leftMenuLinks: [],
|
leftMenuLinks: [],
|
||||||
leftMenuSections: [],
|
leftMenuSections: [],
|
||||||
mainComponent: Comp,
|
mainComponent: App,
|
||||||
name: pluginPkg.strapi.name,
|
name: pluginPkg.strapi.name,
|
||||||
preventComponentRendering: false,
|
preventComponentRendering: false,
|
||||||
suffixUrl: () => '/roles',
|
suffixUrl: () => '/roles',
|
||||||
suffixUrlToReplaceForLeftMenuHighlight: '/roles',
|
suffixUrlToReplaceForLeftMenuHighlight: '/roles',
|
||||||
trads,
|
trads,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default plugin;
|
return strapi.registerPlugin(plugin);
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user