2018-02-28 15:45:16 -05:00
|
|
|
import React from 'react';
|
|
|
|
import { render } from 'react-dom';
|
|
|
|
import { Provider } from 'react-redux';
|
|
|
|
import { Route } from 'react-router-dom';
|
|
|
|
import { ConnectedRouter } from 'react-router-redux';
|
|
|
|
import history from 'Routing/history';
|
2018-08-30 16:24:28 -04:00
|
|
|
import store from 'Redux';
|
2018-02-28 15:45:16 -05:00
|
|
|
import { mergeConfig } from 'Actions/config';
|
2018-11-02 14:19:49 -03:00
|
|
|
import { getPhrases } from 'Constants/defaultPhrases';
|
|
|
|
import { I18n } from 'react-polyglot';
|
2019-03-15 10:19:57 -04:00
|
|
|
import { GlobalStyles } from 'netlify-cms-ui-default';
|
2018-08-07 14:46:54 -06:00
|
|
|
import { ErrorBoundary } from 'UI';
|
2018-02-28 15:45:16 -05:00
|
|
|
import App from 'App/App';
|
|
|
|
import 'EditorWidgets';
|
2019-03-16 15:44:29 -07:00
|
|
|
import 'coreSrc/mediaLibrary';
|
2018-07-06 18:56:28 -04:00
|
|
|
import 'what-input';
|
2018-02-28 15:45:16 -05:00
|
|
|
|
2018-03-28 15:52:57 -04:00
|
|
|
const ROOT_ID = 'nc-root';
|
2018-03-06 17:14:09 -05:00
|
|
|
|
2018-03-28 15:52:57 -04:00
|
|
|
function bootstrap(opts = {}) {
|
2018-03-06 17:14:09 -05:00
|
|
|
const { config } = opts;
|
|
|
|
|
2018-02-28 15:45:16 -05:00
|
|
|
/**
|
|
|
|
* Log the version number.
|
|
|
|
*/
|
2018-07-27 14:26:03 -04:00
|
|
|
if (NETLIFY_CMS_VERSION) {
|
|
|
|
console.log(`netlify-cms ${NETLIFY_CMS_VERSION}`);
|
|
|
|
} else if (NETLIFY_CMS_CORE_VERSION) {
|
|
|
|
console.log(`netlify-cms-core ${NETLIFY_CMS_CORE_VERSION}`);
|
|
|
|
}
|
2018-02-28 15:45:16 -05:00
|
|
|
|
|
|
|
/**
|
2018-03-28 15:52:57 -04:00
|
|
|
* Get DOM element where app will mount.
|
2018-02-28 15:45:16 -05:00
|
|
|
*/
|
2018-03-28 15:52:57 -04:00
|
|
|
function getRoot() {
|
|
|
|
/**
|
|
|
|
* Return existing root if found.
|
|
|
|
*/
|
|
|
|
const existingRoot = document.getElementById(ROOT_ID);
|
|
|
|
if (existingRoot) {
|
|
|
|
return existingRoot;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If no existing root, create and return a new root.
|
|
|
|
*/
|
|
|
|
const newRoot = document.createElement('div');
|
|
|
|
newRoot.id = ROOT_ID;
|
|
|
|
document.body.appendChild(newRoot);
|
|
|
|
return newRoot;
|
|
|
|
}
|
2018-02-28 15:45:16 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatch config to store if received. This config will be merged into
|
|
|
|
* config.yml if it exists, and any portion that produces a conflict will be
|
|
|
|
* overwritten.
|
|
|
|
*/
|
|
|
|
if (config) {
|
|
|
|
store.dispatch(mergeConfig(config));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create connected root component.
|
|
|
|
*/
|
|
|
|
const Root = () => (
|
2019-03-15 10:19:57 -04:00
|
|
|
<>
|
|
|
|
<GlobalStyles />
|
|
|
|
<I18n locale={'en'} messages={getPhrases()}>
|
|
|
|
<ErrorBoundary showBackup>
|
|
|
|
<Provider store={store}>
|
|
|
|
<ConnectedRouter history={history}>
|
|
|
|
<Route component={App} />
|
|
|
|
</ConnectedRouter>
|
|
|
|
</Provider>
|
|
|
|
</ErrorBoundary>
|
|
|
|
</I18n>
|
|
|
|
</>
|
2018-02-28 15:45:16 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render application root.
|
|
|
|
*/
|
2018-03-28 15:52:57 -04:00
|
|
|
render(<Root />, getRoot());
|
2018-02-28 15:45:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export default bootstrap;
|