added dynamic imports of components

This commit is contained in:
bill bittner 2018-03-21 17:35:51 -07:00
parent 6713d660b3
commit 94d4626ccf
10 changed files with 798 additions and 1032 deletions

View file

@ -0,0 +1,22 @@
const { lstatSync, readdirSync } = require('fs');
const { join } = require('path');
const getSubDirectoryNames = (root) => {
console.log('getting sub directories for:', root);
return readdirSync(root)
.filter(name => {
console.log('module found:', name);
let fullPath = join(root, name);
return lstatSync(fullPath).isDirectory();
});
};
module.exports = (root) => {
let allModules = {};
getSubDirectoryNames(root)
.forEach((name) => {
console.log('importing module:', name);
allModules[name] = require(`./${name}`).default;
});
return allModules;
};

View file

@ -1,25 +1,4 @@
import ActiveStatusBar from './ActiveStatusBar'; const Path = require('path');
import AssetPreview from './AssetPreview'; const importSubModules = require('build/utils/importSubModules');
import ExpandingTextArea from './ExpandingTextArea'; const thisFolder = Path.resolve(__dirname, 'client/components/');
import GAListener from './GAListener'; module.exports = importSubModules(thisFolder);
import InactiveStatusBar from './InactiveStatusBar';
import Logo from './Logo';
import NavBarChannelOptionsDropdown from './NavBarChannelOptionsDropdown';
import ProgressBar from './ProgressBar';
import PublishPreview from './PublishPreview';
import PublishUrlMiddleDisplay from './PublishUrlMiddleDisplay';
import SEO from './SEO';
module.exports = {
ActiveStatusBar,
AssetPreview,
ExpandingTextArea,
GAListener,
InactiveStatusBar,
Logo,
NavBarChannelOptionsDropdown,
ProgressBar,
PublishPreview,
PublishUrlMiddleDisplay,
SEO,
};

View file

@ -0,0 +1,4 @@
const Path = require('path');
const importSubModules = require('build/utils/importSubModules');
const thisFolder = Path.resolve(__dirname, 'client/containers/');
module.exports = importSubModules(thisFolder);

4
client/pages/index.js Normal file
View file

@ -0,0 +1,4 @@
const Path = require('path');
const importSubModules = require('build/utils/importSubModules');
const thisFolder = Path.resolve(__dirname, 'client/pages/');
module.exports = importSubModules(thisFolder);

1743
index.js

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
const db = require('../models/index'); const db = require('../models');
const logger = require('winston'); const logger = require('winston');
module.exports = { module.exports = {

View file

@ -1,11 +1,11 @@
import React from 'react'; import React from 'react';
import { renderToString } from 'react-dom/server'; import { renderToString } from 'react-dom/server';
import { createStore } from 'redux'; import { createStore } from 'redux';
import Reducer from '../../client/reducers/index'; import Reducer from 'client/reducers';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { StaticRouter } from 'react-router-dom'; import { StaticRouter } from 'react-router-dom';
import GAListener from '../../client/components/GAListener/index'; import GAListener from 'client/components/GAListener/';
import App from '../../client/app'; import App from 'client/app';
import renderFullPage from './renderFullPage.js'; import renderFullPage from './renderFullPage.js';
import Helmet from 'react-helmet'; import Helmet from 'react-helmet';

View file

@ -1,7 +1,7 @@
const PassportLocalStrategy = require('passport-local').Strategy; const PassportLocalStrategy = require('passport-local').Strategy;
const lbryApi = require('../helpers/lbryApi.js'); const lbryApi = require('../helpers/lbryApi.js');
const logger = require('winston'); const logger = require('winston');
const db = require('../models/index'); const db = require('../models');
module.exports = new PassportLocalStrategy( module.exports = new PassportLocalStrategy(
{ {

View file

@ -1,6 +1,6 @@
// load dependencies // load dependencies
const logger = require('winston'); const logger = require('winston');
const db = require('../models/index'); // require our models for syncing const db = require('../models'); // require our models for syncing
// configure logging // configure logging
require('../helpers/configureLogger.js')(logger); require('../helpers/configureLogger.js')(logger);

View file

@ -1,13 +1,13 @@
const Server = require('server/server.js'); const Server = require('./server/server.js');
const Components = require('client/components'); const Components = require('./client/components');
// const containers = require('client/containers'); const Containers = require('./client/containers');
// const pages = require('client/pages'); const Pages = require('./client/pages');
const exports = { const exports = {
Server, Server,
Components, Components,
// containers, Containers,
// pages, Pages,
}; };
module.exports = exports; module.exports = exports;