From 09229a59983f245deaac0d1f57a818f6faa8b022 Mon Sep 17 00:00:00 2001 From: Buck DeFore Date: Thu, 26 Nov 2015 08:09:09 -0800 Subject: [PATCH 01/54] update paths to npm module --- api/__tests__/api-test.js | 67 ------- api/actions/index.js | 5 - api/actions/loadAuth.js | 3 - api/actions/loadInfo.js | 8 - api/actions/login.js | 7 - api/actions/logout.js | 8 - api/actions/widget/index.js | 2 - api/actions/widget/load.js | 28 --- api/actions/widget/update.js | 24 --- api/api.js | 89 ---------- api/utils/url.js | 26 --- bin/api.js | 11 -- bin/server.js | 28 --- docs/Ducks.md | 3 - docs/InlineStyles.md | 40 ----- karma.conf.js | 66 ------- package.json | 51 ++++-- server.babel.js | 15 -- src/client.js | 72 -------- src/components/__tests__/InfoBar-test.js | 54 ------ src/config.js | 2 - src/containers/About/About.js | 2 +- src/containers/App/App.js | 14 +- src/containers/DevTools/DevTools.js | 11 -- src/containers/Home/Home.js | 164 +----------------- src/containers/Login/Login.js | 2 +- src/containers/Survey/Survey.js | 2 +- src/containers/Widgets/Widgets.js | 2 +- src/helpers/ApiClient.js | 47 ----- src/helpers/Html.js | 53 ------ src/helpers/__tests__/connectData-test.js | 29 ---- .../__tests__/getDataDependencies-test.js | 64 ------- .../__tests__/getStatusFromRoutes-test.js | 53 ------ .../__tests__/makeRouteHooksSafe-test.js | 111 ------------ src/helpers/getDataDependencies.js | 18 -- src/helpers/getStatusFromRoutes.js | 9 - src/helpers/makeRouteHooksSafe.js | 43 ----- src/redux/create.js | 33 ---- src/redux/middleware/clientMiddleware.js | 24 --- src/redux/middleware/transitionMiddleware.js | 45 ----- src/server.js | 130 -------------- src/theme/bootstrap.config.js | 9 +- webpack-overrides-config.js | 26 +++ webpack/dev.config.js | 99 ----------- webpack/prod.config.js | 89 ---------- webpack/webpack-dev-server.js | 33 ---- webpack/webpack-isomorphic-tools.js | 98 ----------- 47 files changed, 83 insertions(+), 1736 deletions(-) delete mode 100644 api/__tests__/api-test.js delete mode 100644 api/actions/index.js delete mode 100644 api/actions/loadAuth.js delete mode 100644 api/actions/loadInfo.js delete mode 100644 api/actions/login.js delete mode 100644 api/actions/logout.js delete mode 100644 api/actions/widget/index.js delete mode 100644 api/actions/widget/load.js delete mode 100644 api/actions/widget/update.js delete mode 100644 api/api.js delete mode 100644 api/utils/url.js delete mode 100644 bin/api.js delete mode 100644 bin/server.js delete mode 100644 docs/Ducks.md delete mode 100644 docs/InlineStyles.md delete mode 100644 karma.conf.js delete mode 100755 server.babel.js delete mode 100755 src/client.js delete mode 100644 src/components/__tests__/InfoBar-test.js delete mode 100644 src/containers/DevTools/DevTools.js delete mode 100644 src/helpers/ApiClient.js delete mode 100644 src/helpers/Html.js delete mode 100644 src/helpers/__tests__/connectData-test.js delete mode 100644 src/helpers/__tests__/getDataDependencies-test.js delete mode 100644 src/helpers/__tests__/getStatusFromRoutes-test.js delete mode 100644 src/helpers/__tests__/makeRouteHooksSafe-test.js delete mode 100755 src/helpers/getDataDependencies.js delete mode 100644 src/helpers/getStatusFromRoutes.js delete mode 100644 src/helpers/makeRouteHooksSafe.js delete mode 100644 src/redux/create.js delete mode 100644 src/redux/middleware/clientMiddleware.js delete mode 100644 src/redux/middleware/transitionMiddleware.js delete mode 100755 src/server.js create mode 100644 webpack-overrides-config.js delete mode 100755 webpack/dev.config.js delete mode 100755 webpack/prod.config.js delete mode 100755 webpack/webpack-dev-server.js delete mode 100644 webpack/webpack-isomorphic-tools.js diff --git a/api/__tests__/api-test.js b/api/__tests__/api-test.js deleted file mode 100644 index 610f4421d..000000000 --- a/api/__tests__/api-test.js +++ /dev/null @@ -1,67 +0,0 @@ -import {expect} from 'chai'; -import {mapUrl} from '../utils/url'; - -describe('mapUrl', () => { - - it('extracts nothing if both params are undefined', () => { - expect(mapUrl(undefined, undefined)).to.deep.equal({ - action: null, - params: [] - }); - }); - - it('extracts nothing if the url is empty', () => { - const url = ''; - const splittedUrlPath = url.split('?')[0].split('/').slice(1); - const availableActions = {a: 1, widget: {c: 1, load: () => 'baz'}}; - - expect(mapUrl(availableActions, splittedUrlPath)).to.deep.equal({ - action: null, - params: [] - }); - }); - - it('extracts nothing if nothing was found', () => { - const url = '/widget/load/?foo=bar'; - const splittedUrlPath = url.split('?')[0].split('/').slice(1); - const availableActions = {a: 1, info: {c: 1, load: () => 'baz'}}; - - expect(mapUrl(availableActions, splittedUrlPath)).to.deep.equal({ - action: null, - params: [] - }); - }); - it('extracts the available actions and the params from an relative url string with GET params', () => { - - const url = '/widget/load/param1/xzy?foo=bar'; - const splittedUrlPath = url.split('?')[0].split('/').slice(1); - const availableActions = {a: 1, widget: {c: 1, load: () => 'baz'}}; - - expect(mapUrl(availableActions, splittedUrlPath)).to.deep.equal({ - action: availableActions.widget.load, - params: ['param1', 'xzy'] - }); - }); - - it('extracts the available actions from an url string without GET params', () => { - const url = '/widget/load/?foo=bar'; - const splittedUrlPath = url.split('?')[0].split('/').slice(1); - const availableActions = {a: 1, widget: {c: 1, load: () => 'baz'}}; - - expect(mapUrl(availableActions, splittedUrlPath)).to.deep.equal({ - action: availableActions.widget.load, - params: [''] - }); - }); - - it('does not find the avaialble action if deeper nesting is required', () => { - const url = '/widget'; - const splittedUrlPath = url.split('?')[0].split('/').slice(1); - const availableActions = {a: 1, widget: {c: 1, load: () => 'baz'}}; - - expect(mapUrl(availableActions, splittedUrlPath)).to.deep.equal({ - action: null, - params: [] - }); - }); -}); diff --git a/api/actions/index.js b/api/actions/index.js deleted file mode 100644 index bc53bd1cb..000000000 --- a/api/actions/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export loadInfo from './loadInfo'; -export loadAuth from './loadAuth'; -export login from './login'; -export logout from './logout'; -export * as widget from './widget/index'; diff --git a/api/actions/loadAuth.js b/api/actions/loadAuth.js deleted file mode 100644 index 34cc97ecb..000000000 --- a/api/actions/loadAuth.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function loadAuth(req) { - return Promise.resolve(req.session.user || null); -} diff --git a/api/actions/loadInfo.js b/api/actions/loadInfo.js deleted file mode 100644 index 073d80dab..000000000 --- a/api/actions/loadInfo.js +++ /dev/null @@ -1,8 +0,0 @@ -export default function loadInfo() { - return new Promise((resolve) => { - resolve({ - message: 'This came from the api server', - time: Date.now() - }); - }); -} diff --git a/api/actions/login.js b/api/actions/login.js deleted file mode 100644 index 6c9a6a113..000000000 --- a/api/actions/login.js +++ /dev/null @@ -1,7 +0,0 @@ -export default function login(req) { - const user = { - name: req.body.name - }; - req.session.user = user; - return Promise.resolve(user); -} diff --git a/api/actions/logout.js b/api/actions/logout.js deleted file mode 100644 index a6a69f8be..000000000 --- a/api/actions/logout.js +++ /dev/null @@ -1,8 +0,0 @@ -export default function logout(req) { - return new Promise((resolve) => { - req.session.destroy(() => { - req.session = null; - return resolve(null); - }); - }); -} diff --git a/api/actions/widget/index.js b/api/actions/widget/index.js deleted file mode 100644 index f92acd6fb..000000000 --- a/api/actions/widget/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export update from './update'; -export load from './load'; diff --git a/api/actions/widget/load.js b/api/actions/widget/load.js deleted file mode 100644 index c4b5ff2a6..000000000 --- a/api/actions/widget/load.js +++ /dev/null @@ -1,28 +0,0 @@ -const initialWidgets = [ - {id: 1, color: 'Red', sprocketCount: 7, owner: 'John'}, - {id: 2, color: 'Taupe', sprocketCount: 1, owner: 'George'}, - {id: 3, color: 'Green', sprocketCount: 8, owner: 'Ringo'}, - {id: 4, color: 'Blue', sprocketCount: 2, owner: 'Paul'} -]; - -export function getWidgets(req) { - let widgets = req.session.widgets; - if (!widgets) { - widgets = initialWidgets; - req.session.widgets = widgets; - } - return widgets; -} - -export default function load(req) { - return new Promise((resolve, reject) => { - // make async call to database - setTimeout(() => { - if (Math.random() < 0.33) { - reject('Widget load fails 33% of the time. You were unlucky.'); - } else { - resolve(getWidgets(req)); - } - }, 1000); // simulate async load - }); -} diff --git a/api/actions/widget/update.js b/api/actions/widget/update.js deleted file mode 100644 index 3d50834e6..000000000 --- a/api/actions/widget/update.js +++ /dev/null @@ -1,24 +0,0 @@ -import load from './load'; - -export default function update(req) { - return new Promise((resolve, reject) => { - // write to database - setTimeout(() => { - if (Math.random() < 0.2) { - reject('Oh no! Widget save fails 20% of the time. Try again.'); - } else { - const widgets = load(req); - const widget = req.body; - if (widget.color === 'Green') { - reject({ - color: 'We do not accept green widgets' // example server-side validation error - }); - } - if (widget.id) { - widgets[widget.id - 1] = widget; // id is 1-based. please don't code like this in production! :-) - } - resolve(widget); - } - }, 2000); // simulate async db write - }); -} diff --git a/api/api.js b/api/api.js deleted file mode 100644 index ea936deb9..000000000 --- a/api/api.js +++ /dev/null @@ -1,89 +0,0 @@ -import express from 'express'; -import session from 'express-session'; -import bodyParser from 'body-parser'; -import config from '../src/config'; -import * as actions from './actions/index'; -import {mapUrl} from 'utils/url.js'; -import PrettyError from 'pretty-error'; -import http from 'http'; -import SocketIo from 'socket.io'; - -const pretty = new PrettyError(); -const app = express(); - -const server = new http.Server(app); - -const io = new SocketIo(server); -io.path('/ws'); - -app.use(session({ - secret: 'react and redux rule!!!!', - resave: false, - saveUninitialized: false, - cookie: { maxAge: 60000 } -})); -app.use(bodyParser.json()); - - -app.use((req, res) => { - - const splittedUrlPath = req.url.split('?')[0].split('/').slice(1); - - const {action, params} = mapUrl(actions, splittedUrlPath); - - if (action) { - action(req, params) - .then((result) => { - res.json(result); - }, (reason) => { - if (reason && reason.redirect) { - res.redirect(reason.redirect); - } else { - console.error('API ERROR:', pretty.render(reason)); - res.status(reason.status || 500).json(reason); - } - }); - } else { - res.status(404).end('NOT FOUND'); - } -}); - - -const bufferSize = 100; -const messageBuffer = new Array(bufferSize); -let messageIndex = 0; - -if (config.apiPort) { - const runnable = app.listen(config.apiPort, (err) => { - if (err) { - console.error(err); - } - console.info('----\n==> 🌎 API is running on port %s', config.apiPort); - console.info('==> πŸ’» Send requests to http://%s:%s', config.apiHost, config.apiPort); - }); - - io.on('connection', (socket) => { - socket.emit('news', {msg: `'Hello World!' from server`}); - - socket.on('history', () => { - for (let index = 0; index < bufferSize; index++) { - const msgNo = (messageIndex + index) % bufferSize; - const msg = messageBuffer[msgNo]; - if (msg) { - socket.emit('msg', msg); - } - } - }); - - socket.on('msg', (data) => { - data.id = messageIndex; - messageBuffer[messageIndex % bufferSize] = data; - messageIndex++; - io.emit('msg', data); - }); - }); - io.listen(runnable); - -} else { - console.error('==> ERROR: No PORT environment variable has been specified'); -} diff --git a/api/utils/url.js b/api/utils/url.js deleted file mode 100644 index 6e3e78ca8..000000000 --- a/api/utils/url.js +++ /dev/null @@ -1,26 +0,0 @@ -export function mapUrl(availableActions = {}, url = []) { - - const notFound = {action: null, params: []}; - - // test for empty input - if (url.length === 0 || Object.keys(availableActions).length === 0) { - return notFound; - } - /*eslint-disable */ - const reducer = (next, current) => { - if (next.action && next.action[current]) { - return {action: next.action[current], params: []}; // go deeper - } else { - if (typeof next.action === 'function') { - return {action: next.action, params: next.params.concat(current)}; // params are found - } else { - return notFound; - } - } - }; - /*eslint-enable */ - - const actionAndParams = url.reduce(reducer, {action: availableActions, params: []}); - - return (typeof actionAndParams.action === 'function') ? actionAndParams : notFound; -} diff --git a/bin/api.js b/bin/api.js deleted file mode 100644 index 9498ee5eb..000000000 --- a/bin/api.js +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env node -if (process.env.NODE_ENV !== 'production') { - if (!require('piping')({ - hook: true, - ignore: /(\/\.|~$|\.json$)/i - })) { - return; - } -} -require('../server.babel'); // babel registration (runtime transpilation for node) -require('../api/api'); diff --git a/bin/server.js b/bin/server.js deleted file mode 100644 index d4792622e..000000000 --- a/bin/server.js +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env node -require('../server.babel'); // babel registration (runtime transpilation for node) -var path = require('path'); -var rootDir = path.resolve(__dirname, '..'); -/** - * Define isomorphic constants. - */ -global.__CLIENT__ = false; -global.__SERVER__ = true; -global.__DISABLE_SSR__ = false; // <----- DISABLES SERVER SIDE RENDERING FOR ERROR DEBUGGING -global.__DEVELOPMENT__ = process.env.NODE_ENV !== 'production'; - -if (__DEVELOPMENT__) { - if (!require('piping')({ - hook: true, - ignore: /(\/\.|~$|\.json|\.scss$)/i - })) { - return; - } -} - -// https://github.com/halt-hammerzeit/webpack-isomorphic-tools -var WebpackIsomorphicTools = require('webpack-isomorphic-tools'); -global.webpackIsomorphicTools = new WebpackIsomorphicTools(require('../webpack/webpack-isomorphic-tools')) - .development(__DEVELOPMENT__) - .server(rootDir, function() { - require('../src/server'); - }); diff --git a/docs/Ducks.md b/docs/Ducks.md deleted file mode 100644 index 69cffa405..000000000 --- a/docs/Ducks.md +++ /dev/null @@ -1,3 +0,0 @@ -This document has found [another, hopefully permanent, home](https://github.com/erikras/ducks-modular-redux). - -Quack. diff --git a/docs/InlineStyles.md b/docs/InlineStyles.md deleted file mode 100644 index 01925883d..000000000 --- a/docs/InlineStyles.md +++ /dev/null @@ -1,40 +0,0 @@ -# Inline Styles - -In the long term, CSS, LESS and SASS are dead. To keep this project on the bleeding edge, we should drop SASS support in favor of inline styles. - -## Why? - -I think the case is made pretty strongly in these three presentations. - -Christopher Chedeau | Michael Chan | Colin Megill ---- | --- | --- -[![CSS In Your JS by Christopher Chedeau](https://i.vimeocdn.com/video/502495328_295x166.jpg)](http://blog.vjeux.com/2014/javascript/react-css-in-js-nationjs.html) | [![Michael Chan - Inline Styles: themes, media queries, contexts, & when it's best to use CSS](https://i.ytimg.com/vi/ERB1TJBn32c/mqdefault.jpg)](https://www.youtube.com/watch?v=ERB1TJBn32c) | [![Colin Megill - Inline Styles are About to Kill CSS](https://i.ytimg.com/vi/NoaxsCi13yQ/mqdefault.jpg)](https://www.youtube.com/watch?v=NoaxsCi13yQ) - -Clearly this is the direction in which web development is moving. - -## Why not? - -At the moment, all the inline CSS libraries suffer from some or all of these problems: - -* Client side only -* No vendor auto prefixing (requires `User-Agent` checking on server side) -* No server side media queries, resulting in a flicker on load to adjust to client device width - -Ideally, a library would allow for all the benefits of inline calculable styles, but, in production, would allow some generation of a CSS block, with media queries to handle device width conditionals, to be inserted into the page with a `