diff --git a/README.md b/README.md index 5b890af..74dcb2a 100644 --- a/README.md +++ b/README.md @@ -53,14 +53,14 @@ __Note:__ This boilerplate is not to show case how to code in React / Redux, it Features -* React 16 +* React 16.6 * Redux * Saga * ES6 / ES7 * ImmutableJS * PreCSS ( supports SASS-like markup in your CSS ) -* PostCSS ( it support CSS modules, and we recommended B.E.M style ) -* Webpack 3 +* PostCSS ( with CSS modules activated by default ) +* Webpack 4 * Reselect * Lazy Loading component supports * Type Checking with Babel Type Check ( Flow syntax ) @@ -198,8 +198,9 @@ All your javascript code lives in folder `src/js` -- src/ -- js/ -- common/ - -- components/ --> all share components here - -- types/ --> all flow types are here + -- api/ --> all api requests + -- components/ --> all share components + -- types/ --> all flow types -- redux/ -- modules/ --> all redux code -- saga/ --> all redux-saga code diff --git a/bin/commands.js b/bin/commands.js index b8497a0..7e7826b 100644 --- a/bin/commands.js +++ b/bin/commands.js @@ -2,17 +2,22 @@ const shell = require('shelljs'); const config = require('config'); const colors = require('colors'); -const host = config.get('host') || 'localhost'; -const port = config.get('port') || '8080'; - const option = process.argv[2]; +// The following will allow you to add your own +// - pre process +// - post process +// - parallel process +// - logging +// +// You can add your process here and have package.json to proxy your command +// Please look at package.json -> "scripts" section switch (option) { case 'lint': shell.exec('cross-env eslint --fix src/js/** --format node_modules/eslint-friendly-formatter . --ext .js --ext .jsx --cache; exit 0'); break; case 'dev': - shell.exec(`cross-env HOST=${host} PORT=${port} webpack-dev-server --config webpack.config.dev-server.babel.js --hot --progress --no-info --inline --colors --content-base ./docroot`); + shell.exec(`cross-env webpack-dev-server --config webpack.config.dev-server.babel.js --hot --progress --no-info --inline --colors`); break; case 'build': shell.exec(`cross-env rimraf docroot && webpack --config webpack.config.build.babel.js --progress --display-error-details`); diff --git a/package.json b/package.json index b6a5f1e..dc958ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-redux-boilerplate", - "version": "1.2.1", + "version": "1.2.2", "description": "React Redux Boilerplate is a workflow boilerplate that make life easier for developers by providing a virtual development environment and production ready build process framework out of the box.", "scripts": { "dev": "cross-env NODE_ENV=development DASHBOARD_PORT=9901 webpack-dashboard -p 9901 -c red -t dashboard -- node bin/commands.js dev", diff --git a/src/js/README.md b/src/js/README.md new file mode 100644 index 0000000..d43b6e4 --- /dev/null +++ b/src/js/README.md @@ -0,0 +1,15 @@ +## Before Your Start Coding + +This Boilerplate is providing a infrastructure to start your project as quickly as you can. + +__BUT__ before you start developing a real large scale project, please do ask yourself or your team a few questions :- + +* What is your domain layer looks like ? You can pretend redux as a data repository of everything, but it will provide no actual meaning for your application besides a data bag. For example, am I able to describe what a `User` is in the application. Having a domain layer will help yourself from having heart attack of arbitrary data structure that describe the same thing in different places. +* I know you are a smart engineer, but please remember it is better to write code everyone can understand. +* You only need to solve a problem when you have a real problem, don't prematurely making a decision based on preference. +* Strong convention is better for everyone, if you don't have convention today, you will have N+1 conventions the next month. + +If you read to this point, I assumed you are a very serious developer, please help me to read the following links if you haven't! + +[SOLID JavaScript](http://aspiringcraftsman.com/2011/12/08/solid-javascript-single-responsibility-principle/) +[Twelve Factor App](https://12factor.net/) diff --git a/src/js/common/api/README.md b/src/js/common/api/README.md new file mode 100644 index 0000000..4420087 --- /dev/null +++ b/src/js/common/api/README.md @@ -0,0 +1,10 @@ +## Convention + +The following will be convention for this api/ + +* You can only put your api request here, no business logic. +* You should separate your api files by "requested resources" +* Your api should return a "Promise" interface for consistency +* And you use `index.js` to expose your api + +This folder will contain an example using axios, it is not a working api, but show case how you should structure your apis. diff --git a/src/js/common/api/index.js b/src/js/common/api/index.js new file mode 100644 index 0000000..20bd673 --- /dev/null +++ b/src/js/common/api/index.js @@ -0,0 +1,7 @@ +/* +// This is an example will not work +// This is just showing case how I would orangize +export { + getTopTenAvengers, +} from './module/example' +*/ diff --git a/src/js/common/api/module/example.js b/src/js/common/api/module/example.js new file mode 100644 index 0000000..e2cb2ef --- /dev/null +++ b/src/js/common/api/module/example.js @@ -0,0 +1,9 @@ +/* +// This is an example will not work +// Just only show case how I would orangize +const API_ENDPOINT = __CONFIG__.apiUrl.avengers + +export const getTopTenAvengers = (query = {}) => { + return axios.get(`${API_ENDPOINT}?count=10`) +} +*/ diff --git a/src/js/common/components/Example/Example.jsx b/src/js/common/components/Example/Example.jsx index d548e71..d613b46 100644 --- a/src/js/common/components/Example/Example.jsx +++ b/src/js/common/components/Example/Example.jsx @@ -1,6 +1,6 @@ import React, { PureComponent } from 'react'; -import './Example.css'; +import styles from './Example.css'; /** * Example @@ -45,7 +45,7 @@ class Example extends PureComponent { if (result && result.size && result.size > 0) { return ( -