Speech as a package #416

Merged
bones7242 merged 89 commits from speech-as-a-package into master 2018-04-18 21:47:34 +02:00
12 changed files with 12242 additions and 12209 deletions
Showing only changes of commit 6c2415c11b - Show all commits

View file

@ -1,4 +1,4 @@
node_modules/ node_modules/
public/bundle exports/
index.js index.js
test test/

View file

@ -6,10 +6,11 @@ import { BrowserRouter } from 'react-router-dom';
import Reducer from 'reducers'; import Reducer from 'reducers';
import createSagaMiddleware from 'redux-saga'; import createSagaMiddleware from 'redux-saga';
import rootSaga from 'sagas'; import rootSaga from 'sagas';
import GAListener from 'components/GAListener'; import GAListener from 'components/GAListener';
import App from './app'; import App from './app';
const siteConfig = require('siteConfig.js');
// get the state from a global variable injected into the server-generated HTML // get the state from a global variable injected into the server-generated HTML
const preloadedState = window.__PRELOADED_STATE__ || null; const preloadedState = window.__PRELOADED_STATE__ || null;
@ -21,7 +22,7 @@ const sagaMiddleware = createSagaMiddleware();
const middleware = applyMiddleware(sagaMiddleware); const middleware = applyMiddleware(sagaMiddleware);
const reduxMiddleware = window.__REDUX_DEVTOOLS_EXTENSION__ ? compose(middleware, window.__REDUX_DEVTOOLS_EXTENSION__()) : middleware; const reduxMiddleware = window.__REDUX_DEVTOOLS_EXTENSION__ ? compose(middleware, window.__REDUX_DEVTOOLS_EXTENSION__()) : middleware;
// create teh store // create the store
let store; let store;
if (preloadedState) { if (preloadedState) {
store = createStore(Reducer, preloadedState, reduxMiddleware); store = createStore(Reducer, preloadedState, reduxMiddleware);
@ -29,17 +30,26 @@ if (preloadedState) {
store = createStore(Reducer, reduxMiddleware); store = createStore(Reducer, reduxMiddleware);
} }
// run the saga middlweare function Client () {
sagaMiddleware.run(rootSaga); this.configureSiteDetails = (userConfig) => {
siteConfig.update(userConfig);
};
this.start = () => {
// run the saga middlweare
sagaMiddleware.run(rootSaga);
// render the app // render the app
hydrate( hydrate(
<Provider store={store}> <Provider store={store}>
<BrowserRouter> <BrowserRouter>
<GAListener> <GAListener>
<App /> <App />
</GAListener> </GAListener>
</BrowserRouter> </BrowserRouter>
</Provider>, </Provider>,
document.getElementById('react-app') document.getElementById('react-app')
); );
};
};
module.exports = Client;

View file

@ -2,7 +2,6 @@ const { customComponents } = require('siteConfig.js');
function getDeepestChildValue (parent, childrenKeys) { function getDeepestChildValue (parent, childrenKeys) {
if (!parent[childrenKeys[0]]) { if (!parent[childrenKeys[0]]) {
console.log('NO PAGE FOUND FOR:', childrenKeys[0], 'in', parent);
return null; return null;
} }
let childKey = childrenKeys.shift(); // .shift() retrieves the first element of array and removes it from array let childKey = childrenKeys.shift(); // .shift() retrieves the first element of array and removes it from array
@ -24,6 +23,7 @@ export const dynamicImport = (filePath) => {
throw new Error('file path provided to dynamicImport() must be a string'); throw new Error('file path provided to dynamicImport() must be a string');
} }
if (!customComponents) { if (!customComponents) {
console.log('No customComponents found in siteConfig.js');
return null; return null;
} }
// split out the file folders // filter out any empty or white-space-only strings // split out the file folders // filter out any empty or white-space-only strings
@ -32,8 +32,10 @@ export const dynamicImport = (filePath) => {
// i.e. customComponents[folders[0]][folders[2][...][folders[n]] // i.e. customComponents[folders[0]][folders[2][...][folders[n]]
const component = getDeepestChildValue(customComponents, folders); const component = getDeepestChildValue(customComponents, folders);
if (component) { if (component) {
return component; // return custom component console.log('Found custom component:', component);
return component;
} else { } else {
console.log('Found custom component:', component);
return null; return null;
} }
}; };

File diff suppressed because one or more lines are too long

11928
exports/nodeBundle.js Normal file

File diff suppressed because one or more lines are too long

11931
index.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -6,9 +6,9 @@ module.exports = {
target: 'web', target: 'web',
entry : ['babel-polyfill', 'whatwg-fetch', './client/index.js'], entry : ['babel-polyfill', 'whatwg-fetch', './client/index.js'],
output: { output: {
path : Path.join(__dirname, 'public/bundle/'), path : Path.join(__dirname, 'exports/'),
publicPath: 'public/bundle/', publicPath: 'exports/',
filename : 'bundle.js', filename : 'clientBundle.js',
}, },
module: { module: {
loaders: [ loaders: [

View file

@ -1,7 +1,7 @@
const packageBaseConfig = require('./webpack.package.common.js'); const packageBaseConfig = require('./webpack.package.common.js');
const clientBaseConfig = require('./webpack.client.common.js'); // const clientBaseConfig = require('./webpack.client.common.js');
module.exports = [ module.exports = [
clientBaseConfig, // clientBaseConfig,
packageBaseConfig, packageBaseConfig,
]; ];

View file

@ -10,11 +10,11 @@ module.exports = {
__dirname: false, __dirname: false,
}, },
externals: [nodeExternals()], externals: [nodeExternals()],
entry : ['babel-polyfill', 'whatwg-fetch', './speech.js'], entry : ['babel-polyfill', 'whatwg-fetch', './speechPackage.js'],
output : { output : {
path : Path.join(__dirname, '/'), path : Path.join(__dirname, 'exports/'),
publicPath : '/', publicPath : 'exports/',
filename : 'index.js', filename : 'nodeBundle.js',
library : '', library : '',
libraryTarget: 'commonjs-module', libraryTarget: 'commonjs-module',
}, },