Skip to content

Commit 66f8eb3

Browse files
committed
Initial commit
1 parent 2126f6b commit 66f8eb3

15 files changed

+442
-0
lines changed

.babelrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"es2015"
4+
]
5+
}

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.eslintrc

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"extends": [
3+
"eslint:recommended",
4+
"plugin:import/errors",
5+
"plugin:import/warnings"
6+
],
7+
"parserOptions": {
8+
"ecmaVersion": 7,
9+
"sourceType": "module"
10+
},
11+
"env": {
12+
"es6": true,
13+
"browser": true,
14+
"node": true,
15+
"mocha": true
16+
},
17+
"rules": {
18+
"quotes": 0,
19+
"no-console": 1,
20+
"no-debugger": 1,
21+
"no-var": 1,
22+
"semi": [1, "always"],
23+
"no-trailing-spaces": 0,
24+
"eol-last": 0,
25+
"no-unused-vars": 0,
26+
"no-underscore-dangle": 0,
27+
"no-alert": 0,
28+
"no-lone-blocks": 0
29+
}
30+
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ jspm_packages
3535

3636
# Optional REPL history
3737
.node_repl_history
38+
39+
#Webstorm
40+
.idea

README.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#Starter Kit for [Building Applications in React and Redux in ES6](http://www.pluralsight.com/author/cory-house) on Pluralsight
2+
3+
## Get Started
4+
1. **Install [Node 6](https://nodejs.org)**. Need to run multiple versions of Node? Use [nvm](https://github.com/creationix/nvm) or [nvm-windows](https://github.com/coreybutler/nvm-windows)
5+
2. **Clone this repository.** - `git clone https://github.com/coryhouse/pluralsight-redux-starter.git` or [download the zip](https://github.com/coryhouse/pluralsight-redux-starter/archive/master.zip)
6+
3. **Make sure you're in the directory you just created.** - `cd pluralsight-redux-starter`
7+
4. **Install Node Packages.** - `npm install`
8+
5. **Run the app.** - `npm start -s`
9+
This will run the automated build process, start up a webserver, and open the application in your default browser. When doing development with this kit, this command will continue watching files all your files. Every time you hit save the code is rebuilt, linting runs, and tests run automatically. Note: The -s flag is optional. It enables silent mode which suppresses unnecessary messages during the build.
10+
6. **Install [React developer tools](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en) and [Redux Dev Tools](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=en)** in Chrome.
11+
7. Having issues? See below.
12+
13+
## Having Issues? Try these things first:
14+
1. Run `npm install` - If you forget to do this, you'll see this: `babel-node: command not found`.
15+
2. Make sure the path doesn't include any spaces, or install the latest version of eslint-watch which adds support for paths containing spaces: `npm install [email protected]`
16+
3. Make sure you're running the latest version of Node.
17+
4. Use [Node 5.12.0](https://nodejs.org/download/release/v5.12.0/) if you're having issues on Windows. Node 6 has issues on some Windows machines.
18+
5. Don't run the project from a symbolic link. It will cause issues with file watches.
19+
20+
###Production Dependencies
21+
| **Dependency** | **Use** |
22+
|----------|-------|
23+
|babel-polyfill | Polyfill for Babel features that cannot be transpiled |
24+
|bootstrap|CSS Framework|
25+
|jquery|Only used to support toastr|
26+
|react|React library |
27+
|react-dom|React library for DOM rendering |
28+
|react-redux|Redux library for connecting React components to Redux |
29+
|react-router|React library for routing |
30+
|react-router-redux|Keep React Router in sync with Redux application state|
31+
|redux|Library for unidirectional data flows |
32+
|redux-thunk|Async redux library|
33+
|toastr|Display messages to the user|
34+
35+
###Development Dependencies
36+
| **Dependency** | **Use** |
37+
|----------|-------|
38+
|babel-cli|Babel Command line interface |
39+
|babel-core|Babel Core for transpiling the new JavaScript to old |
40+
|babel-loader|Adds Babel support to Webpack |
41+
|babel-plugin-react-display-name| Add displayName to React.createClass calls |
42+
|babel-preset-es2015|Babel preset for ES2015|
43+
|babel-preset-react| Add JSX support to Babel |
44+
|babel-preset-react-hmre|Hot reloading preset for Babel|
45+
|babel-register|Register Babel to transpile our Mocha tests|
46+
|cheerio|Supports querying DOM with jQuery like syntax - Useful in testing and build process for HTML manipulation|
47+
|colors|Adds color support to terminal |
48+
|compression|Add gzip support to Express|
49+
|cross-env|Cross-environment friendly way to handle environment variables|
50+
|css-loader|Add CSS support to Webpack|
51+
|enzyme|Simplified JavaScript Testing utilities for React|
52+
|eslint|Lints JavaScript |
53+
|eslint-plugin-import|Advanced linting of ES6 imports|
54+
|eslint-plugin-react|Adds additional React-related rules to ESLint|
55+
|eslint-watch|Add watch functionality to ESLint |
56+
|eventsource-polyfill|Polyfill to support hot reloading in IE|
57+
|expect|Assertion library for use with Mocha|
58+
|express|Serves development and production builds|
59+
|extract-text-webpack-plugin| Extracts CSS into separate file for production build |
60+
|file-loader| Adds file loading support to Webpack |
61+
|jsdom|In-memory DOM for testing|
62+
|mocha| JavaScript testing library |
63+
|nock| Mock HTTP requests for testing |
64+
|npm-run-all| Display results of multiple commands on single command line |
65+
|open|Open app in default browser|
66+
|react-addons-test-utils| Adds React TestUtils |
67+
|redux-immutable-state-invariant|Warn when Redux state is mutated|
68+
|redux-mock-store|Mock Redux store for testing|
69+
|rimraf|Delete files |
70+
|style-loader| Add Style support to Webpack |
71+
|url-loader| Add url loading support to Webpack |
72+
|webpack| Bundler with plugin system and integrated development server |
73+
|webpack-dev-middleware| Adds middleware support to webpack |
74+
|webpack-hot-middleware| Adds hot reloading to webpack |

buildTools/build.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// More info on Webpack's Node API here: https://webpack.github.io/docs/node.js-api.html
2+
// Allowing console calls below since this is a build file.
3+
/*eslint-disable no-console */
4+
import webpack from 'webpack';
5+
import webpackConfig from '../webpack.config.prod';
6+
import colors from 'colors';
7+
8+
process.env.NODE_ENV = 'production'; // this assures the Babel dev config (for hot reloading) doesn't apply.
9+
10+
console.log('Generating minified bundle for production via Webpack. This will take a moment...'.blue);
11+
12+
webpack(webpackConfig).run((err, stats) => {
13+
if (err) { // so a fatal error occurred. Stop here.
14+
console.log(err.bold.red);
15+
return 1;
16+
}
17+
18+
const jsonStats = stats.toJson();
19+
20+
if (jsonStats.hasErrors) {
21+
return jsonStats.errors.map(error => console.log(error.red));
22+
}
23+
24+
if (jsonStats.hasWarnings) {
25+
console.log('Webpack generated the following warnings: '.bold.yellow);
26+
jsonStats.warnings.map(warning => console.log(warning.yellow));
27+
}
28+
29+
console.log(`Webpack stats: ${stats}`);
30+
31+
// if we got this far, the build succeeded.
32+
console.log('Your app has been compiled in production mode and written to /dist. It\'s ready to roll!'.green);
33+
34+
return 0;
35+
});

buildTools/buildHtml.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// This script copies src/index.html into /dist/index.html
2+
// This is a good example of using Node and cheerio to do a simple file transformation.
3+
// In this case, the transformation is useful since we only use a separate css file in prod.
4+
import fs from 'fs';
5+
import cheerio from 'cheerio';
6+
import colors from 'colors';
7+
8+
/*eslint-disable no-console */
9+
10+
fs.readFile('src/index.html', 'utf8', (err, markup) => {
11+
if (err) {
12+
return console.log(err);
13+
}
14+
15+
const $ = cheerio.load(markup);
16+
17+
// since a separate spreadsheet is only utilized for the production build, need to dynamically add this here.
18+
$('head').prepend('<link rel="stylesheet" href="styles.css">');
19+
20+
fs.writeFile('dist/index.html', $.html(), 'utf8', function (err) {
21+
if (err) {
22+
return console.log(err);
23+
}
24+
console.log('index.html written to /dist'.green);
25+
});
26+
});

buildTools/distServer.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import express from 'express';
2+
import path from 'path';
3+
import open from 'open';
4+
import compression from 'compression';
5+
6+
/*eslint-disable no-console */
7+
8+
const port = 3000;
9+
const app = express();
10+
11+
app.use(compression());
12+
app.use(express.static('dist'));
13+
14+
app.get('*', function(req, res) {
15+
res.sendFile(path.join(__dirname, '../dist/index.html'));
16+
});
17+
18+
app.listen(port, function(err) {
19+
if (err) {
20+
console.log(err);
21+
} else {
22+
open(`http://localhost:${port}`);
23+
}
24+
});

buildTools/srcServer.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import express from 'express';
2+
import webpack from 'webpack';
3+
import path from 'path';
4+
import config from '../webpack.config.dev';
5+
import open from 'open';
6+
7+
/* eslint-disable no-console */
8+
9+
const port = 3000;
10+
const app = express();
11+
const compiler = webpack(config);
12+
13+
app.use(require('webpack-dev-middleware')(compiler, {
14+
noInfo: true,
15+
publicPath: config.output.publicPath
16+
}));
17+
18+
app.use(require('webpack-hot-middleware')(compiler));
19+
20+
app.get('*', function(req, res) {
21+
res.sendFile(path.join( __dirname, '../src/index.html'));
22+
});
23+
24+
app.listen(port, function(err) {
25+
if (err) {
26+
console.log(err);
27+
} else {
28+
open(`http://localhost:${port}`);
29+
}
30+
});

buildTools/startMessage.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import colors from 'colors';
2+
3+
/*eslint-disable no-console */
4+
5+
console.log('Starting app in dev mode...'.green);

buildTools/testSetup.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Tests are placed alongside files under test.
2+
// This file does the following:
3+
// 1. Registers babel for transpiling our code for testing
4+
// 2. Disables Webpack-specific features that Mocha doesn't understand.
5+
// 3. Requires jsdom so we can test via an in-memory DOM in Node
6+
// 4. Sets up global vars that mimic a browser.
7+
8+
/*eslint-disable no-var*/
9+
10+
// This assures the .babelrc dev config (which includes
11+
// hot module reloading code) doesn't apply for tests.
12+
process.env.NODE_ENV = 'test';
13+
14+
// Register babel so that it will transpile ES6 to ES5
15+
// before our tests run.
16+
require('babel-register')();
17+
18+
// Disable webpack-specific features for tests since
19+
// Mocha doesn't know what to do with them.
20+
require.extensions['.css'] = function () {return null;};
21+
require.extensions['.png'] = function () {return null;};
22+
require.extensions['.jpg'] = function () {return null;};
23+
24+
// Configure JSDOM and set global variables
25+
// to simulate a browser environment for tests.
26+
var jsdom = require('jsdom').jsdom;
27+
28+
var exposedProperties = ['window', 'navigator', 'document'];
29+
30+
global.document = jsdom('');
31+
global.window = document.defaultView;
32+
Object.keys(document.defaultView).forEach((property) => {
33+
if (typeof global[property] === 'undefined') {
34+
exposedProperties.push(property);
35+
global[property] = document.defaultView[property];
36+
}
37+
});
38+
39+
global.navigator = {
40+
userAgent: 'node.js'
41+
};
42+
43+
documentRef = document; //eslint-disable-line no-undef

package.json

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"name": "javascript-development-environment",
3+
"version": "1.0.0",
4+
"description": "JavaScript development environment Pluralsight course by Cory House",
5+
"scripts": {
6+
"prestart": "babel-node tools/startMessage.js",
7+
"start": "npm-run-all --parallel test:watch open:src lint:watch",
8+
"open:src": "babel-node tools/srcServer.js",
9+
"lint": "node_modules/.bin/esw webpack.config.* src tools",
10+
"lint:watch": "npm run lint -- --watch",
11+
"test": "mocha --reporter progress tools/testSetup.js src/**/*.test.js src/components/**/*.test.js",
12+
"test:watch": "npm run test -- --watch",
13+
"clean-dist": "npm run remove-dist && mkdir dist",
14+
"remove-dist": "node_modules/.bin/rimraf ./dist",
15+
"build:html": "babel-node tools/buildHtml.js",
16+
"prebuild": "npm-run-all clean-dist test lint build:html",
17+
"build": "babel-node tools/build.js",
18+
"postbuild": "babel-node tools/distServer.js"
19+
},
20+
"author": "Cory House",
21+
"license": "MIT",
22+
"dependencies": {
23+
"babel-polyfill": "6.8.0",
24+
"bootstrap": "3.3.6",
25+
"jquery": "2.2.3",
26+
"react": "15.0.2",
27+
"react-dom": "15.0.2",
28+
"react-redux": "4.4.5",
29+
"react-router": "2.4.0",
30+
"react-router-redux": "4.0.4",
31+
"redux": "3.5.2",
32+
"redux-thunk": "2.0.1",
33+
"toastr": "2.1.2"
34+
},
35+
"devDependencies": {
36+
"babel-cli": "6.8.0",
37+
"babel-core": "6.8.0",
38+
"babel-loader": "6.2.4",
39+
"babel-plugin-react-display-name": "2.0.0",
40+
"babel-preset-es2015": "6.6.0",
41+
"babel-preset-react": "6.5.0",
42+
"babel-preset-react-hmre": "1.1.1",
43+
"babel-register": "6.8.0",
44+
"colors": "1.1.2",
45+
"compression": "^1.6.1",
46+
"cross-env": "1.0.7",
47+
"css-loader": "0.23.1",
48+
"enzyme": "2.2.0",
49+
"eslint": "2.9.0",
50+
"eslint-plugin-import": "1.6.1",
51+
"eslint-plugin-react": "5.0.1",
52+
"eslint-watch": "2.1.11",
53+
"eventsource-polyfill": "0.9.6",
54+
"expect": "1.19.0",
55+
"express": "4.13.4",
56+
"extract-text-webpack-plugin": "1.0.1",
57+
"file-loader": "0.8.5",
58+
"jsdom": "8.5.0",
59+
"mocha": "2.4.5",
60+
"nock": "8.0.0",
61+
"npm-run-all": "1.8.0",
62+
"open": "0.0.5",
63+
"react-addons-test-utils": "15.0.2",
64+
"redux-immutable-state-invariant": "1.2.3",
65+
"redux-mock-store": "1.0.2",
66+
"rimraf": "2.5.2",
67+
"style-loader": "0.13.1",
68+
"url-loader": "0.5.7",
69+
"webpack": "1.13.0",
70+
"webpack-dev-middleware": "1.6.1",
71+
"webpack-hot-middleware": "2.10.0"
72+
},
73+
"repository": {
74+
"type": "git",
75+
"url": "https://github.com/coryhouse/pluralsight-redux-starter"
76+
}
77+
}

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('Hello world!');

0 commit comments

Comments
 (0)