2017-01-17 13:40:59 +01:00
|
|
|
/**
|
|
|
|
* app.js
|
|
|
|
*
|
|
|
|
* This is the entry file for the application,
|
|
|
|
* only setup and plugin code.
|
|
|
|
*/
|
|
|
|
|
2017-09-26 16:36:28 +02:00
|
|
|
import React from 'react';
|
2017-03-18 17:34:00 +01:00
|
|
|
import { Provider } from 'react-redux';
|
2017-08-22 10:51:53 +02:00
|
|
|
|
2017-09-28 12:16:24 +02:00
|
|
|
import App from 'containers/App'; // eslint-disable-line
|
2017-08-22 10:51:53 +02:00
|
|
|
|
2018-03-08 12:56:44 +01:00
|
|
|
import './public-path.js'; // eslint-disabled-line import/extensions
|
2017-08-22 10:51:53 +02:00
|
|
|
import configureStore from './store';
|
2017-06-20 20:55:58 +02:00
|
|
|
import { translationMessages } from './i18n';
|
2017-01-17 13:40:59 +01:00
|
|
|
|
2017-11-28 16:01:50 +01:00
|
|
|
const tryRequireRoot = (source) => {
|
2017-09-27 17:54:18 +02:00
|
|
|
try {
|
2018-03-08 12:56:44 +01:00
|
|
|
return require('../../../../admin/src/' + source + '.js').default; // eslint-disable-line prefer-template
|
2017-09-27 17:54:18 +02:00
|
|
|
} catch(err) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-04 14:29:16 +01:00
|
|
|
const bootstrap = tryRequireRoot('bootstrap');
|
|
|
|
const pluginRequirements = tryRequireRoot('requirements');
|
|
|
|
|
|
|
|
const layout = (() => {
|
2017-11-28 16:01:50 +01:00
|
|
|
try {
|
2018-03-08 12:56:44 +01:00
|
|
|
return require('../../../../config/layout.js'); // eslint-disable-line import/no-unresolved
|
2017-11-28 16:01:50 +01:00
|
|
|
} catch(err) {
|
|
|
|
return null;
|
|
|
|
}
|
2017-12-04 14:29:16 +01:00
|
|
|
})();
|
2017-10-24 14:35:08 +02:00
|
|
|
|
2017-11-28 16:01:50 +01:00
|
|
|
const injectedComponents = (() => {
|
|
|
|
try {
|
2018-03-08 12:56:44 +01:00
|
|
|
return require('injectedComponents').default; // eslint-disable-line import/no-unresolved
|
2017-11-28 16:01:50 +01:00
|
|
|
} catch(err) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
});
|
2017-09-28 12:16:24 +02:00
|
|
|
|
2017-05-11 15:52:22 +02:00
|
|
|
// Plugin identifier based on the package.json `name` value
|
2017-05-17 11:28:54 +02:00
|
|
|
const pluginPkg = require('../../../../package.json');
|
|
|
|
const pluginId = pluginPkg.name.replace(
|
2017-05-11 15:52:22 +02:00
|
|
|
/^strapi-plugin-/i,
|
|
|
|
''
|
|
|
|
);
|
2017-06-08 17:16:20 +01:00
|
|
|
const pluginName = pluginPkg.strapi.name;
|
|
|
|
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
|
2017-11-08 17:40:47 +01:00
|
|
|
const apiUrl = `${strapi.backendURL}/${pluginId}`;
|
|
|
|
const router = strapi.router;
|
2017-05-11 15:52:22 +02:00
|
|
|
|
2017-08-22 10:51:53 +02:00
|
|
|
// Create redux store with Strapi admin history
|
2018-01-05 16:19:53 +01:00
|
|
|
const store = configureStore({}, strapi.router, pluginName);
|
2017-05-10 11:41:53 +02:00
|
|
|
|
2017-05-11 15:52:22 +02:00
|
|
|
// Define the plugin root component
|
|
|
|
function Comp(props) {
|
|
|
|
return (
|
|
|
|
<Provider store={store}>
|
|
|
|
<App {...props} />
|
|
|
|
</Provider>
|
|
|
|
);
|
2017-03-18 17:34:00 +01:00
|
|
|
}
|
|
|
|
|
2017-06-20 20:55:58 +02:00
|
|
|
// Hot reloadable translation json files
|
|
|
|
if (module.hot) {
|
|
|
|
// modules.hot.accept does not accept dynamic dependencies,
|
|
|
|
// have to be constants at compile-time
|
|
|
|
module.hot.accept('./i18n', () => {
|
2017-11-08 17:40:47 +01:00
|
|
|
if (strapi) {
|
2017-06-20 20:55:58 +02:00
|
|
|
System.import('./i18n').then(result => {
|
|
|
|
const translationMessagesUpdated = result.translationMessages;
|
2017-11-08 17:40:47 +01:00
|
|
|
strapi
|
2017-06-20 20:55:58 +02:00
|
|
|
.refresh(pluginId)
|
|
|
|
.translationMessages(translationMessagesUpdated);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-14 11:10:05 +02:00
|
|
|
// Register the plugin.
|
2017-11-08 17:40:47 +01:00
|
|
|
strapi.registerPlugin({
|
2017-12-01 15:45:11 +01:00
|
|
|
blockerComponent: null,
|
|
|
|
blockerComponentProps: {},
|
|
|
|
bootstrap,
|
2017-11-02 11:36:38 +01:00
|
|
|
description: pluginDescription,
|
2017-12-01 15:45:11 +01:00
|
|
|
icon: pluginPkg.strapi.icon,
|
2017-05-17 11:28:54 +02:00
|
|
|
id: pluginId,
|
2017-12-01 15:45:11 +01:00
|
|
|
injectedComponents,
|
|
|
|
layout,
|
2017-05-17 11:28:54 +02:00
|
|
|
leftMenuLinks: [],
|
|
|
|
mainComponent: Comp,
|
2017-12-01 15:45:11 +01:00
|
|
|
name: pluginPkg.strapi.name,
|
2017-09-27 17:54:18 +02:00
|
|
|
pluginRequirements,
|
|
|
|
preventComponentRendering: false,
|
2017-12-01 15:45:11 +01:00
|
|
|
translationMessages,
|
2017-05-17 11:28:54 +02:00
|
|
|
});
|
|
|
|
|
2017-01-17 13:40:59 +01:00
|
|
|
// Export store
|
2017-06-08 17:16:20 +01:00
|
|
|
export { store, apiUrl, pluginId, pluginName, pluginDescription, router };
|