Skip to content

Commit 98cbac2

Browse files
fristoniogupta-utkarsh
authored andcommitted
refactor(package.json): update package.json dev environment scripts (#145)
* refactor(package.json): update package.json dev environment scripts * feat(production-build): add and configure production build - refactor webpack config files - refactored package.json - add production build script * feat(eslint): add eslint config to .eslintrc * fix(frontend-tests): add dummy test script to Origami and package.json * Add endline to eslintrc
1 parent f43d238 commit 98cbac2

8 files changed

Lines changed: 155 additions & 36 deletions

File tree

.eslintrc

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"extends": [
3+
"eslint:recommended",
4+
],
5+
"plugins": [
6+
"react",
7+
"prettier"
8+
],
9+
"parserOptions": {
10+
"ecmaVersion": 6,
11+
"sourceType": "module",
12+
"ecmaFeatures": {
13+
"jsx": true,
14+
"experimentalObjectRestSpread": true
15+
}
16+
},
17+
"env": {
18+
"es6": true,
19+
"browser": true,
20+
"node": true,
21+
"jquery": true,
22+
"mocha": true
23+
},
24+
"rules": {
25+
"prettier/prettier": 1,
26+
"object-curly-spacing": [1, "always"],
27+
"no-dupe-class-members": 1,
28+
"no-iterator": 1,
29+
"one-var": [1, "never"],
30+
"no-nested-ternary": 1,
31+
"no-restricted-syntax": [1, "WithStatement"],
32+
"no-duplicate-imports": 1,
33+
"no-unneeded-ternary": 1,
34+
"no-case-declarations": 1,
35+
"dot-notation": 1,
36+
"no-useless-constructor": 1,
37+
"eqeqeq": 1,
38+
"object-shorthand": 1,
39+
"prefer-rest-params": 1,
40+
"no-array-constructor": 1,
41+
"array-callback-return": 0,
42+
"no-param-reassign": 1,
43+
"prefer-arrow-callback": 1,
44+
"no-useless-concat": 1,
45+
"prefer-template": 1,
46+
"no-console": 1,
47+
"no-debugger": 1,
48+
"no-var": 1,
49+
"no-trailing-spaces": 0,
50+
"eol-last": 0,
51+
"no-unused-vars": 0,
52+
"no-underscore-dangle": 0,
53+
"no-alert": 0,
54+
"no-lone-blocks": 0,
55+
"react/display-name": [1, {"ignoreTranspilerName": false }],
56+
"react/forbid-prop-types": [1, {"forbid": ["any"]}],
57+
"react/jsx-boolean-value": 1,
58+
"react/prefer-stateless-function": 1,
59+
"react/jsx-indent-props": 0,
60+
"react/jsx-key": 1,
61+
"react/jsx-max-props-per-line": 0,
62+
"react/jsx-no-bind": 0,
63+
"react/jsx-no-duplicate-props": 1,
64+
"react/jsx-no-literals": 0,
65+
"react/jsx-no-undef": 1,
66+
"react/jsx-pascal-case": 1,
67+
"react/jsx-sort-prop-types": 0,
68+
"react/jsx-sort-props": 0,
69+
"react/jsx-uses-react": 1,
70+
"react/jsx-uses-vars": 1,
71+
"react/no-danger": 1,
72+
"react/no-did-mount-set-state": 1,
73+
"react/no-did-update-set-state": 1,
74+
"react/no-direct-mutation-state": 1,
75+
"react/no-multi-comp": 1,
76+
"react/no-is-mounted": 1,
77+
"react/no-set-state": 0,
78+
"react/no-unknown-property": 1,
79+
"react/prefer-es6-class": 1,
80+
"react/prop-types": 1,
81+
"react/react-in-jsx-scope": 1,
82+
"react/self-closing-comp": 1,
83+
"react/sort-comp": 1
84+
}
85+
}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ api/migrations/*
3636
!api/migrations/__init__.py
3737

3838
# Bundle
39-
django_server/static/bundles/local/*.js
39+
django_server/static/bundles/local
4040

4141
# Python
4242
*.pyc

Origami/scripts/build.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*eslint-disable no-console*/
2+
3+
import webpack from "webpack";
4+
import webpackConfig from "../../webpack.prod.config";
5+
import colors from "colors";
6+
7+
process.env.NODE_ENV = "production";
8+
9+
console.log(
10+
"Generating minified bundle for production. This will take a moment...".blue
11+
);
12+
13+
webpack(webpackConfig).run((err, stats) => {
14+
if (err) {
15+
console.log(err.bold.red);
16+
return 1;
17+
}
18+
19+
const jsonStats = stats.toJson();
20+
21+
if (jsonStats.hasErrors) {
22+
return jsonStats.errors.map(error => console.log(error.red));
23+
}
24+
25+
if (jsonStats.hasWarnings) {
26+
console.log("Webpack generate the following warnings".bold.yellow);
27+
jsonStats.warnings.map(warning => console.log(warning.yellow));
28+
}
29+
30+
console.log("App compiled in production mode. Ready to roll!".green);
31+
32+
return 0;
33+
});

Origami/scripts/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
process.env.NODE_ENV = "test";
2+
3+
require("babel-register")();

django_server/static/bundles/local/example-bundle

Whitespace-only changes.

package.json

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
"version": "1.0.0",
44
"description": "Create a demo of your machine learning model with CloudCV",
55
"scripts": {
6-
"clean-dist": "npm run remove-dist && mkdir dist",
7-
"remove-dist": "node_modules/.bin/rimraf ./dist",
8-
"build:html": "babel-node server/buildHTML.js",
9-
"build": "npm-run-all clean-dist test lint:build build:html && babel-node server/build.js",
10-
"build:alias": "babel-node server/build.js",
11-
"start": "node server/start.js",
12-
"open:src": "babel-node server/srcServer.js",
13-
"lint": "esw webpack.config.* src server",
14-
"lint:build": "node_modules/.bin/esw webpack.config.* src server -c ./.eslintrc-build",
6+
"remove:bundle": "node_modules/.bin/rimraf ./django_server/static/bundles/local",
7+
"clean:bundle": "npm-run-all remove:bundle && mkdir ./django_server/static/bundles/local",
8+
"build": "npm-run-all clean:bundle test lint:build && babel-node Origami/scripts/build.js",
9+
"start": "babel-node server.js",
10+
"open:src": "babel-node server.js",
11+
"lint": "esw webpack.* Origami",
12+
"lint:build": "esw webpack.* Origami -c ./.eslintrc",
1513
"lint:watch": "npm run lint -- --watch",
16-
"lint:fix": "eslint src server webpack.config.* --fix",
17-
"test": "mocha --reporter spec server/testSetup.js \"src/**/*.test.js\"",
18-
"test:watch": "npm run test -- --watch",
19-
"dev": "babel-node server/startMessage.js && npm-run-all --parallel open:src lint:watch test:watch"
14+
"lint:fix": "eslint Origami webpack.* --fix",
15+
"dev": "npm-run-all --parallel open:src lint:watch test:watch",
16+
"test": "mocha --reporter spec Origami/scripts/test.js \"Origami/src/**/*.test.js\"",
17+
"test:watch": "npm run test -- --watch"
2018
},
2119
"author": "Ashish Chaudhary",
2220
"license": "AGPL-3.0",
@@ -28,15 +26,13 @@
2826
"babel-preset-es2015": "^6.24.1",
2927
"babel-preset-stage-0": "^6.24.1",
3028
"bcrypt-nodejs": "^0.0.3",
31-
"eslint-plugin-prettier": "^2.3.1",
3229
"external-ip": "^1.3.1",
3330
"jquery": "^3.2.1",
3431
"load-script": "^1.0.0",
3532
"material-ui": "^0.20.0",
3633
"mkdirp": "^0.5.1",
3734
"mongoose": "^4.13.6",
3835
"portfinder": "^1.0.13",
39-
"prettier": "^1.9.1",
4036
"prop-types": "^15.6.0",
4137
"radium": "^0.19.6",
4238
"range_check": "^1.4.0",
@@ -79,6 +75,7 @@
7975
"eslint-plugin-import": "^2.8.0",
8076
"eslint-plugin-jsx-a11y": "^6.0.2",
8177
"eslint-plugin-react": "^7.5.1",
78+
"eslint-plugin-prettier": "^2.3.1",
8279
"eslint-watch": "^3.1.3",
8380
"eventsource-polyfill": "^0.9.6",
8481
"expect": "^21.2.1",
@@ -94,6 +91,7 @@
9491
"open": "^0.0.5",
9592
"passport": "^0.4.0",
9693
"passport-github": "^1.1.0",
94+
"prettier": "^1.9.1",
9795
"react-addons-test-utils": "15.6.2",
9896
"redux-immutable-state-invariant": "^2.1.0",
9997
"redux-mock-store": "^1.3.0",

webpack.local.config.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
var path = require("path")
2-
var webpack = require('webpack')
3-
var BundleTracker = require('webpack-bundle-tracker')
4-
var path = require("path")
5-
var webpack = require('webpack')
1+
import path from "path";
2+
import webpack from "webpack";
3+
import BundleTracker from "webpack-bundle-tracker";
64

7-
config = {
5+
const config = {
86
devtool: "cheap-module-eval-source-map",
97
entry: [
10-
'webpack-dev-server/client?http://localhost:3000',
11-
'webpack/hot/only-dev-server',
8+
"webpack-dev-server/client?http://localhost:3000",
9+
"webpack/hot/only-dev-server",
1210
"./Origami/src/index"
1311
],
14-
devServer: {
12+
devServer: {
1513
inline: true,
1614
hot: true
1715
},
1816
target: "web",
1917
output: {
20-
path: path.resolve('./django_server/static/bundles/local/'),
21-
publicPath: 'http://localhost:3000/static/bundles/',
18+
path: path.resolve("./django_server/static/bundles/local/"),
19+
publicPath: "http://localhost:3000/static/bundles/",
2220
filename: "bundle.js"
2321
},
2422
plugins: [
2523
new webpack.HotModuleReplacementPlugin(),
2624
new webpack.NoEmitOnErrorsPlugin(),
27-
new BundleTracker({filename: './webpack-stats-local.json'})
25+
new BundleTracker({ filename: "./webpack-stats-local.json" })
2826
],
2927
module: {
3028
rules: [
@@ -53,4 +51,4 @@ config = {
5351
}
5452
};
5553

56-
module.exports = config
54+
module.exports = config;

webpack.prod.config.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
var path = require("path")
2-
var webpack = require('webpack')
3-
var BundleTracker = require('webpack-bundle-tracker')
1+
import webpack from "webpack";
2+
import path from "path";
3+
import BundleTracker from "webpack-bundle-tracker";
44

55
const GLOBALS = {
66
"process.env.NODE_ENV": JSON.stringify("production")
77
};
88

9-
config = {
9+
const config = {
1010
entry: "./Origami/src/index",
1111
target: "web",
1212
output: {
13-
path: path.resolve('./django_server/static/bundles/local/'),
13+
path: path.resolve(
14+
path.join(__dirname, "django_server/static/bundles/local/")
15+
),
1416
filename: "bundle.js"
1517
},
1618
plugins: [
1719
new webpack.DefinePlugin(GLOBALS),
1820
new webpack.optimize.UglifyJsPlugin(),
1921
new webpack.optimize.AggressiveMergingPlugin(),
20-
new BundleTracker({filename: './webpack-stats-local.json'})
22+
new BundleTracker({ filename: "./webpack-stats-local.json" })
2123
],
2224
module: {
2325
rules: [
@@ -46,4 +48,4 @@ config = {
4648
}
4749
};
4850

49-
module.exports = config
51+
module.exports = config;

0 commit comments

Comments
 (0)