Skip to content

Commit 5e7f890

Browse files
committed
Update to match final course demo
1 parent 842e86b commit 5e7f890

14 files changed

+123
-362
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#JavaScript Development Environment
22

3-
This is a generic JavaScript development environment. This isn't tied to any specific JS framework.
3+
This is a generic JavaScript development environment that I build from scratch in ["Building a JavaScript Development Environment" on Pluralsight](https://app.pluralsight.com/library/courses/javascript-development-environment/table-of-contents). This isn't tied to any specific JS framework.
44

55
## Get Started
66
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)
@@ -13,9 +13,11 @@ This will run the automated build process, start up a webserver, and open the ap
1313

1414
## Having Issues? Try these things first:
1515
1. Run `npm install` - If you forget to do this, you'll see this: `babel-node: command not found`.
16-
2. Make sure you're running the latest version of Node.
17-
3. 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.
16+
2. Make sure you're running the latest version of Node. Or, use [Node 6.9.1](https://nodejs.org/en/download/releases/) if you're having issues on Windows. Node 7 has issues on some Windows machines.
17+
3. Make sure files with names that begin with a dot (.babelrc, .editorconfig, .eslintrc) are copied to the project directory root. This is easy to overlook if you copy this repository manually.
1818
4. Don't run the project from a symbolic link. It will cause issues with file watches.
19+
5. Having linting issues? Delete any .eslintrc that you're storing in your user directory. Also, disable any ESLint plugin / custom rules that you've enabled within your editor. These will conflict with the ESLint rules defined in the course.
20+
6. Nothing above work? Delete your node_modules folder and re-run npm install.
1921

2022
###Development Dependencies
2123
| **Dependency** | **Use** |

buildScripts/mockDataSchema.js

+10-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const schema = {
22
"type": "object",
33
"properties": {
4-
"calculations": {
4+
"users": {
55
"type": "array",
66
"minItems": 3,
77
"maxItems": 5,
@@ -13,37 +13,22 @@ export const schema = {
1313
"unique": true,
1414
"minimum": 1
1515
},
16-
"country": {
16+
"firstName": {
1717
"type": "string",
18-
"faker": "address.country"
18+
"faker": "name.firstName"
1919
},
20-
"newMpg": {
21-
"type": "number",
22-
"minimum": 12,
23-
"maximum": 55
24-
},
25-
"tradeMpg": {
26-
"type": "number",
27-
"minimum": 12,
28-
"maximum": 55
29-
},
30-
"pricePerGallon": {
20+
"lastName": {
3121
"type": "string",
32-
"chance": {
33-
"dollar": {
34-
"max": 5
35-
}
36-
}
22+
"faker": "name.lastName",
3723
},
38-
"milesDrivenPerMonth": {
39-
"type": "number",
40-
"minimum": 100,
41-
"maximum": 1500
24+
"email": {
25+
"type": "string",
26+
"faker": "internet.email",
4227
}
4328
},
44-
required: ['id', 'country', 'newMpg', 'tradeMpg', 'pricePerGallon', 'milesDrivenPerMonth']
29+
required: ['id', 'firstName', 'lastName', 'email']
4530
}
4631
}
4732
},
48-
required: ['calculations']
33+
required: ['users']
4934
};

package.json

+23-30
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,27 @@
44
"description": "JavaScript development environment Pluralsight course by Cory House",
55
"scripts": {
66
"prestart": "babel-node buildScripts/startMessage.js",
7-
"start": "npm-run-all --parallel security-check test:watch start-mockapi open:src lint:watch",
7+
"start": "npm-run-all --parallel security-check open:src lint:watch test:watch start-mockapi",
88
"open:src": "babel-node buildScripts/srcServer.js",
99
"lint": "esw webpack.config.* src buildScripts --color",
1010
"lint:watch": "npm run lint -- --watch",
11-
"test": "mocha --reporter progress buildScripts/testSetup.js \"src/**/*.test.js\"",
12-
"test:watch": "npm run test -- --watch",
13-
"clean-dist": "npm run remove-dist && mkdir dist",
14-
"remove-dist": "rimraf ./dist",
15-
"build:html": "babel-node buildScripts/buildHtml.js",
16-
"prebuild": "npm-run-all clean-dist test lint build:html",
17-
"build": "babel-node buildScripts/build.js",
18-
"postbuild": "babel-node buildScripts/distServer.js",
1911
"security-check": "nsp check",
2012
"localtunnel": "lt --port 3000",
2113
"share": "npm-run-all --parallel open:src localtunnel",
22-
"deploy": "surge ./dist --domain fuelcalc.surge.sh",
14+
"test": "mocha --reporter progress buildScripts/testSetup.js \"src/**/*.test.js\"",
15+
"test:watch": "npm run test -- --watch",
16+
"generate-mock-data": "babel-node buildScripts/generateMockData",
2317
"prestart-mockapi": "npm run generate-mock-data",
2418
"start-mockapi": "json-server --watch src/api/db.json --port 3001",
25-
"generate-mock-data": "babel-node buildScripts/generateMockData",
19+
"clean-dist": "rimraf ./dist && mkdir dist",
20+
"prebuild": "npm-run-all clean-dist test lint",
21+
"build": "babel-node buildScripts/build.js",
22+
"postbuild": "babel-node buildScripts/distServer.js",
2623
"deploy": "surge ./dist"
2724
},
2825
"author": "Cory House",
2926
"license": "MIT",
3027
"dependencies": {
31-
"numeral": "1.5.3",
3228
"whatwg-fetch": "1.0.0"
3329
},
3430
"devDependencies": {
@@ -40,34 +36,31 @@
4036
"chai": "3.5.0",
4137
"chalk": "1.1.3",
4238
"cheerio": "0.22.0",
43-
"compression": "^1.6.2",
44-
"cross-env": "3.0.0",
39+
"compression": "1.6.2",
40+
"cross-env": "3.1.3",
4541
"css-loader": "0.25.0",
46-
"eslint": "3.7.0",
47-
"eslint-plugin-import": "2.0.0",
42+
"eslint": "3.8.1",
43+
"eslint-plugin-import": "2.0.1",
4844
"eslint-watch": "2.1.14",
4945
"express": "4.14.0",
50-
"extract-text-webpack-plugin": "^1.0.1",
46+
"extract-text-webpack-plugin": "1.0.1",
5147
"html-webpack-plugin": "2.22.0",
52-
"jsdom": "9.6.0",
48+
"jsdom": "9.8.0",
5349
"json-schema-faker": "0.3.6",
54-
"json-server": "0.8.21",
50+
"json-server": "0.8.22",
5551
"localtunnel": "1.8.1",
56-
"mocha": "3.1.0",
57-
"nock": "8.0.0",
58-
"npm-run-all": "3.1.0",
59-
"nsp": "2.6.1",
52+
"mocha": "3.1.2",
53+
"nock": "8.1.0",
54+
"npm-run-all": "3.1.1",
55+
"nsp": "2.6.2",
56+
"numeral": "1.5.3",
6057
"open": "0.0.5",
6158
"rimraf": "2.5.4",
62-
"style-loader": "^0.13.1",
59+
"style-loader": "0.13.1",
6360
"surge": "0.18.0",
6461
"webpack": "1.13.2",
65-
"webpack-dev-middleware": "1.8.3",
66-
"webpack-hot-middleware": "2.12.2",
62+
"webpack-dev-middleware": "1.8.4",
63+
"webpack-hot-middleware": "2.13.0",
6764
"webpack-md5-hash": "0.0.5"
68-
},
69-
"repository": {
70-
"type": "git",
71-
"url": "https://github.com/coryhouse/pluralsight-redux-starter"
7265
}
7366
}

src/api/baseUrl.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
export default function getBaseUrl() {
2-
const inDevelopment = (global.window && global.window.location.hostname === 'localhost');
3-
return inDevelopment ? 'http://localhost:3001/' : '/';
2+
return getQueryStringParameterByName('useMockApi') ? 'http://localhost:3001/' : 'https://mysterious-dawn-16770.herokuapp.com/';
3+
}
4+
5+
function getQueryStringParameterByName(name, url) {
6+
if (!url) url = window.location.href;
7+
name = name.replace(/[\[\]]/g, "\\$&");
8+
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
9+
results = regex.exec(url);
10+
if (!results) return null;
11+
if (!results[2]) return '';
12+
return decodeURIComponent(results[2].replace(/\+/g, " "));
413
}

src/api/api.js renamed to src/api/userApi.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import getBaseUrl from './baseUrl';
33

44
const baseUrl = getBaseUrl();
55

6-
export function getCalculations() {
7-
return get('calculations');
6+
export function getUsers() {
7+
return get('users');
88
}
99

10-
export function deleteCalculation(id) {
11-
return del(`calculations/${id}`);
10+
export function deleteUser(id) {
11+
return del(`users/${id}`);
1212
}
1313

1414
function get(url) {

src/index.ejs

-74
This file was deleted.

src/index.html

+33-48
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,41 @@
1-
<!DOCTYPE html>
1+
<!--
2+
**NOTE:** This is a template for index.html.
3+
It uses ejs and htmlWebpackPlugin to generate a different index.html for each environment.
4+
htmlWebpackPlugin will dynamically add references to the scripts and styles that it bundles
5+
to this file. The generated bundles have hash-based filenames,
6+
so it's necessary to add the references dynamically.
7+
For more info on ejs, see http://www.embeddedjs.com/.
8+
For examples of using it with htmlWebpackPlugin,
9+
see https://github.com/jaketrent/html-webpack-template/blob/master/index.ejs
10+
-->
11+
<!DOCTYPE html>
212
<html lang="en">
313
<head>
14+
<!--
15+
The htmlWebpackPlugin will parse the logic below so that trackJS is only added to the production version of index.html (since only webpack.config.prod.js provides the trackJS token)
16+
This is an example of how to add features to index.html for only one environment.
17+
-->
18+
<% if (htmlWebpackPlugin.options.trackJSToken) { %>
19+
<!-- BEGIN TRACKJS -->
20+
<script type="text/javascript">window._trackJs = { token: '<%=htmlWebpackPlugin.options.trackJSToken%>' };</script>
21+
<script type="text/javascript" src="https://cdn.trackjs.com/releases/current/tracker.js"></script>
22+
<!-- END TRACKJS -->
23+
<% } %>
424
<meta charset="UTF-8">
5-
<title>Fuel Savings Calculator</title>
625
</head>
726
<body>
8-
<h2 id="main-heading">Fuel Savings Calculator</h2>
9-
<table>
10-
<tbody>
11-
<tr>
12-
<td><label for="newMpg">New Vehicle MPG</label></td>
13-
<td><input type="text" id="newMpg">
14-
</td>
15-
</tr>
16-
<tr>
17-
<td><label for="tradeMpg">Trade-in MPG</label></td>
18-
<td><input type="text" id="tradeMpg" />
19-
</td>
20-
</tr>
21-
<tr>
22-
<td><label for="pricePerGallon">Price Per Gallon</label></td>
23-
<td><input type="text" id="pricePerGallon" />
24-
</td>
25-
</tr>
26-
<tr>
27-
<td><label for="milesDrivenPerMonth">Miles Driven per month</label></td>
28-
<td>
29-
<input type="text" id="milesDrivenPerMonth" />
30-
</td>
31-
</tr>
32-
<tr>
33-
<td>Savings / Loss</td>
34-
<td id="result"></td>
35-
</tr>
36-
</tbody>
37-
</table>
27+
<h1>Users</h1>
28+
<table>
29+
<thead>
30+
<th>&nbsp;</th>
31+
<th>Id</th>
32+
<th>First Name</th>
33+
<th>Last Name</th>
34+
<th>Email</th>
35+
</thead>
36+
<tbody id="users">
3837

39-
40-
<h2>Previous Calculations</h2>
41-
<table>
42-
<thead>
43-
<th>&nbsp;</th>
44-
<th>New MPG</th>
45-
<th>Trade MPG</th>
46-
<th>Price Per Gallon</th>
47-
<th>Miles Driven Per Month</th>
48-
</thead>
49-
<tbody id="calculations">
50-
51-
</tbody>
52-
</table>
53-
54-
<script src="bundle.js"></script>
38+
</tbody>
39+
</table>
5540
</body>
5641
</html>

0 commit comments

Comments
 (0)