119 lines
3.1 KiB
JavaScript
Raw Normal View History

2017-01-17 13:40:59 +01:00
/**
* app.js
*
* This is the entry file for the application,
* only setup and plugin code.
*/
2019-04-03 19:02:19 +02:00
/* eslint-disable */
2018-06-06 14:18:23 +02:00
// Don't move this line!
// import './public-path.js'; // eslint-disable-line import/extensions
2018-06-06 14:18:23 +02:00
import React from 'react';
2019-04-03 19:02:19 +02:00
// import Loadable from 'react-loadable';
// import LoadingIndicatorPage from './components/LoadingIndicatorPage';
import { translationMessages } from './i18n';
2019-04-03 19:02:19 +02:00
import App from 'containers/App';
2017-01-17 13:40:59 +01:00
2019-04-03 19:02:19 +02:00
// const LoadableApp = Loadable({
// loader: () => import('containers/App'),
// loading: LoadingIndicatorPage,
// });
2018-06-12 17:27:40 +02:00
2019-04-03 17:26:31 +02:00
// const tryRequireRoot = source => {
// try {
// return require('../../../../admin/src/' + source + '.js').default; // eslint-disable-line prefer-template
// } catch (err) {
// return null;
// }
// };
2017-12-04 14:29:16 +01:00
const layout = (() => {
try {
return require('../../../../config/layout.js'); // eslint-disable-line import/no-unresolved
} catch (err) {
return null;
}
2017-12-04 14:29:16 +01:00
})();
const injectedComponents = (() => {
try {
return require('injectedComponents').default; // eslint-disable-line import/no-unresolved
} catch (err) {
return [];
}
})();
2017-05-11 15:52:22 +02:00
// Plugin identifier based on the package.json `name` value
const pluginPkg = require('../../../../package.json');
const pluginId = pluginPkg.name.replace(/^strapi-plugin-/i, '');
2017-06-08 17:16:20 +01:00
const pluginName = pluginPkg.strapi.name;
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
const apiUrl = `${strapi.backendURL}/${pluginId}`;
const router = strapi.router;
2017-05-11 15:52:22 +02:00
// Create redux store with Strapi admin history
// const store = configureStore({}, strapi.router, pluginName);
const store = strapi.store;
2017-05-10 11:41:53 +02:00
2017-05-11 15:52:22 +02:00
// Define the plugin root component
function Comp(props) {
2019-04-03 19:02:19 +02:00
return <App {...props} />;
2017-03-18 17:34:00 +01: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', () => {
if (strapi) {
System.import('./i18n').then(result => {
const translationMessagesUpdated = result.translationMessages;
2019-04-03 17:26:31 +02:00
strapi
.refresh(pluginId)
.translationMessages(translationMessagesUpdated);
});
}
});
}
2019-04-02 20:11:31 +02:00
// Require the Initializer component
const initializer = (() => {
try {
return require('../../../../admin/src/initializer.js'); // eslint-disable-line import/no-unresolved
} catch (err) {
return null;
}
})();
// Require the plugin's lifecycle
const lifecycles = (() => {
try {
return require('../../../../admin/src/lifecycles.js'); // eslint-disable-line import/no-unresolved
} catch (err) {
return null;
}
})();
// Register the plugin.
strapi.registerPlugin({
blockerComponent: null,
blockerComponentProps: {},
description: pluginDescription,
icon: pluginPkg.strapi.icon,
id: pluginId,
2019-04-02 20:11:31 +02:00
initializer,
injectedComponents,
layout,
2019-04-02 20:11:31 +02:00
lifecycles,
leftMenuLinks: [],
2019-04-16 16:55:53 +02:00
leftMenuSections: [],
mainComponent: Comp,
name: pluginPkg.strapi.name,
preventComponentRendering: false,
translationMessages,
});
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 };