Skip to content

Commit 34d38bf

Browse files
authored
V0.1.7 (#16)
* Switch to Fractal pattern with CSS modules based on [redux-starter-kit](https://github.com/davezuko/react-redux-starter-kit) * `redux-firebasev3` updated to v0.1.6 * coverage being sent to Codecov * Outputted `README.md` matches new application format * Deploy section of outputted `README.md` matches choice * Tests updated to match new format
1 parent 77c1b15 commit 34d38bf

File tree

346 files changed

+9820
-5163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

346 files changed

+9820
-5163
lines changed

.codeclimate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ exclude_paths:
1313
- "README.md"
1414
- "config.json"
1515
- "package.json"
16-
- "generators/**/templates"
16+
- "generators/**/templates/**"
1717

1818
engines:
1919
duplication:

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ branches:
77
only:
88
- master
99

10-
script: npm run test && npm run test:cov
10+
script:
11+
- npm run test
12+
1113

1214
addons:
1315
code_climate:
@@ -16,3 +18,4 @@ addons:
1618
after_success:
1719
- npm install -g codeclimate-test-reporter
1820
- codeclimate-test-reporter < coverage/*/lcov.info
21+
- npm run codecov

README.md

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ npm install -g generator-react-firebase
3232
## Project
3333

3434
### Development
35-
Run `npm start` to start live reloading development server
35+
Run `npm run dev` to start live reloading development server
3636

3737
### Production
3838

@@ -81,7 +81,6 @@ To deploy:
8181
* `HEROKU_KEY` - Your Heroku API key
8282
* `HEROKU_APP` - Your Heroku App name
8383

84-
8584
## Sub generators
8685

8786
Sub generators are included to help speed up the application building process. You can run a sub-generator by calling `yo react-firebase:<name of sub-generator> <param1>`.
@@ -108,16 +107,12 @@ A component is best for things that will be reused in multiple places. Our examp
108107

109108
```javascript
110109
import React, { Component, PropTypes } from 'react'
111-
import './Car.scss'
110+
import classes from './Car.scss'
112111

113112
export default class Car extends Component {
114-
constructor (props) {
115-
super(props)
116-
}
117-
118113
render () {
119114
return (
120-
<div className="Car">
115+
<div className={classes['container']}>
121116

122117
</div>
123118
)
@@ -147,41 +142,63 @@ Creates a folder within `/containers` that matches the name provided. Below is t
147142
/app/containers/Cars.js:
148143
```javascript
149144
import React, { Component, PropTypes } from 'react'
150-
import { firebase, helpers } from 'redux-react-firebase'
151-
152-
import './Cars.scss'
153-
154-
const { isLoaded, isEmpty, dataToJS, pathToJS } = helpers
155-
156-
import './Login.scss'
145+
import { connect } from 'react-redux'
146+
import { firebase, helpers } from 'redux-firebasev3'
147+
const { isLoaded, isEmpty, dataToJS } = helpers
157148

158149
// Props decorators
159150
@firebase([
160-
'cars'
151+
// Syncs todos root
152+
'/todos'
161153
])
162154
@connect(
163155
({firebase}) => ({
164-
authError: pathToJS(firebase, 'authError'),
165-
profile: pathToJS(firebase, 'profile')
156+
// Place list of todos into this.props.todos
157+
todos: dataToJS(firebase, '/todos'),
166158
})
167159
)
168-
export default class Cars extends Component {
169-
constructor (props) {
170-
super(props)
171-
}
172-
160+
class Todos extends Component {
173161
static propTypes = {
174-
162+
todos: PropTypes.object,
163+
firebase: PropTypes.object
175164
}
176165

177-
render () {
178-
return (
179-
<div className="Cars">
166+
render() {
167+
const { firebase, todos } = this.props;
168+
169+
// Add a new todo to firebase
170+
const handleAdd = () => {
171+
const {newTodo} = this.refs
172+
firebase.push('/todos', { text:newTodo.value, done:false })
173+
newTodo.value = ''
174+
}
175+
176+
// Build Todos list if todos exist and are loaded
177+
const todosList = !isLoaded(todos)
178+
? 'Loading'
179+
: isEmpty(todos)
180+
? 'Todo list is empty'
181+
: Object.keys(todos).map(
182+
(key, id) => (
183+
<TodoItem key={key} id={id} todo={todos[key]}/>
184+
)
185+
)
180186

187+
return (
188+
<div>
189+
<h1>Todos</h1>
190+
<ul>
191+
{todosList}
192+
</ul>
193+
<input type="text" ref="newTodo" />
194+
<button onClick={handleAdd}>
195+
Add
196+
</button>
181197
</div>
182198
)
183199
}
184200
}
201+
export default Todos
185202
```
186203

187204
## Examples
@@ -196,8 +213,10 @@ In order to enable server-side rendering with React, you must host a NodeJS serv
196213

197214

198215
## In the future
199-
* Container Generator - Prompt for props/state vars (which Firebase location to bind to props)
200216
* Non-decorators implementation for props binding (pure redux and firebase implementations)
217+
* Option to use simple file structure instead of fractal pattern
218+
* Smart Container Generator - Prompt for props/state vars (which Firebase location to bind to props)
219+
* Store previous answers and use them as defaults
201220
* Open to ideas
202221

203222
## License
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
// NOTE: These options are overriden by the babel-loader configuration
2+
// for webpack, which can be found in ~/build/webpack.config.
3+
//
4+
// Why? The react-transform-hmr plugin depends on HMR (and throws if
5+
// module.hot is disabled), so keeping it and related plugins contained
6+
// within webpack helps prevent unexpected errors.
17
{
2-
"presets": ["es2015", "stage-0", "react"],
3-
"plugins": ["lodash", "transform-decorators-legacy"]
8+
"presets": ["es2015", "react", "stage-0"],
9+
"plugins": ["lodash", "transform-decorators-legacy", "transform-runtime"]
410
}

examples/react-firebase-redux/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ npm-debug.log
33
stats.json
44
.DS_Store
55
**/.DS_Store
6+
build
7+
coverage

examples/react-firebase-redux/README.md

Lines changed: 162 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,180 @@
77
[![License][license-image]][license-url]
88
[![Code Style][code-style-image]][code-style-url]
99

10+
11+
## Table of Contents
12+
1. [Features](#features)
13+
1. [Requirements](#requirements)
14+
1. [Getting Started](#getting-started)
15+
1. [Application Structure](#application-structure)
16+
1. [Development](#development)
17+
1. [Developer Tools](#developer-tools)
18+
1. [Routing](#routing)
19+
1. [Testing](#testing)
20+
1. [Deployment](#deployment)
21+
1. [Build System](#build-system)
22+
1. [Configuration](#configuration)
23+
1. [Globals](#globals)
24+
1. [Styles](#styles)
25+
1. [Server](#server)
26+
1. [Production Optimization](#production-optimization)
27+
28+
## Requirements
29+
* node `^4.5.0`
30+
* npm `^3.0.0`
31+
1032
## Getting Started
1133

1234
1. Install dependencies: `npm install`
1335

1436
2. Start Development server: `npm start`
1537

38+
If everything works, you should see the following:
39+
40+
<img src="http://i.imgur.com/zR7VRG6.png?2" />
41+
42+
While developing, you will probably rely mostly on `npm start`; however, there are additional scripts at your disposal:
43+
44+
|`npm run <script>`|Description|
45+
|------------------|-----------|
46+
|`start`|Serves your app at `localhost:3000`. HMR will be enabled in development.|
47+
|`compile`|Compiles the application to disk (`~/dist` by default).|
48+
|`dev`|Same as `npm start`, but enables nodemon for the server as well.|
49+
|`test`|Runs unit tests with Karma and generates a coverage report.|
50+
|`test:dev`|Runs Karma and watches for changes to re-run tests; does not generate coverage reports.|
51+
|`build`|Runs linter, tests, and then, on success, compiles your application to disk.|
52+
|`build:dev`|Same as `build` but overrides `NODE_ENV` to "development".|
53+
|`build:prod`|Same as `build` but overrides `NODE_ENV` to "production".|
54+
|`lint`|Lint all `.js` files.|
55+
|`lint:fix`|Lint and fix all `.js` files. [Read more on this](http://eslint.org/docs/user-guide/command-line-interface.html#fix).|
56+
57+
## Application Structure
58+
59+
The application structure presented in this boilerplate is **fractal**, where functionality is grouped primarily by feature rather than file type. Please note, however, that this structure is only meant to serve as a guide, it is by no means prescriptive. That said, it aims to represent generally accepted guidelines and patterns for building scalable applications. If you wish to read more about this pattern, please check out this [awesome writeup](https://github.com/davezuko/react-redux-starter-kit/wiki/Fractal-Project-Structure) by [Justin Greenberg](https://github.com/justingreenberg).
60+
61+
```
62+
.
63+
├── bin # Build/Start scripts
64+
├── blueprints # Blueprint files for redux-cli
65+
├── build # All build-related configuration
66+
│ └── webpack # Environment-specific configuration files for webpack
67+
├── config # Project configuration settings
68+
├── server # Express application that provides webpack middleware
69+
│ └── main.js # Server application entry point
70+
├── src # Application source code
71+
│ ├── index.html # Main HTML page container for app
72+
│ ├── main.js # Application bootstrap and rendering
73+
│ ├── components # Global Reusable Presentational Components
74+
│ ├── containers # Global Reusable Container Components
75+
│ ├── layouts # Components that dictate major page structure
76+
│ ├── redux # "Ducks" location...
77+
│ │ └── modules # reducer, action, creators not part of a route
78+
│ ├── routes # Main route definitions and async split points
79+
│ │ ├── index.js # Bootstrap main application routes with store
80+
│ │ └── Home # Fractal route
81+
│ │ ├── index.js # Route definitions and async split points
82+
│ │ ├── assets # Assets required to render components
83+
│ │ ├── components # Presentational React Components
84+
│ │ ├── container # Connect components to actions and store
85+
│ │ ├── modules # Collections of reducers/constants/actions
86+
│ │ └── routes ** # Fractal sub-routes (** optional)
87+
│ ├── static # Static assets (not imported anywhere in source code)
88+
│ ├── store # Redux-specific pieces
89+
│ │ ├── createStore.js # Create and instrument redux store
90+
│ │ └── reducers.js # Reducer registry and injection
91+
│ └── styles # Application-wide styles (generally settings)
92+
└── tests # Unit tests
93+
```
94+
95+
## Development
96+
97+
#### Developer Tools
98+
99+
**We recommend using the [Redux DevTools Chrome Extension](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd).**
100+
Using the chrome extension allows your monitors to run on a separate thread and affords better performance and functionality. It comes with several of the most popular monitors, is easy to configure, filters actions, and doesn’t require installing any packages.
101+
102+
However, adding the DevTools components to your project is simple. First, grab the packages from npm:
103+
104+
```bash
105+
npm i --save-dev redux-devtools redux-devtools-log-monitor redux-devtools-dock-monitor
106+
```
107+
108+
Then follow the [manual integration walkthrough](https://github.com/gaearon/redux-devtools/blob/master/docs/Walkthrough.md).
109+
110+
### Routing
111+
We use `react-router` [route definitions](https://github.com/reactjs/react-router/blob/master/docs/API.md#plainroute) (`<route>/index.js`) to define units of logic within our application. See the [application structure](#application-structure) section for more information.
112+
113+
## Testing
114+
To add a unit test, simply create a `.spec.js` file anywhere in `~/tests`. Karma will pick up on these files automatically, and Mocha and Chai will be available within your test without the need to import them. Coverage reports will be compiled to `~/coverage` by default. If you wish to change what reporters are used and where reports are compiled, you can do so by modifying `coverage_reporters` in `~/config/index.js`.
115+
116+
## Deployment
117+
Out of the box, this starter kit is deployable by serving the `~/dist` folder generated by `npm run deploy` (make sure to specify your target `NODE_ENV` as well). This project does not concern itself with the details of server-side rendering or API structure, since that demands an opinionated structure that makes it difficult to extend the starter kit. However, if you do need help with more advanced deployment strategies, here are a few tips:
118+
119+
### Static Deployments
120+
If you are serving the application via a web server such as nginx, make sure to direct incoming routes to the root `~/dist/index.html` file and let react-router take care of the rest. If you are unsure of how to do this, you might find [this documentation](https://github.com/reactjs/react-router/blob/master/docs/guides/Histories.md#configuring-your-server) helpful. The Express server that comes with the starter kit is able to be extended to serve as an API or whatever else you need, but that's entirely up to you.
121+
122+
## Build System
123+
124+
### Configuration
125+
126+
Default project configuration can be found in `~/config/index.js`. Here you'll be able to redefine your `src` and `dist` directories, adjust compilation settings, tweak your vendor dependencies, and more. For the most part, you should be able to make changes in here **without ever having to touch the actual webpack build configuration**.
127+
128+
If you need environment-specific overrides (useful for dynamically setting API endpoints, for example), you can edit `~/config/environments.js` and define overrides on a per-NODE_ENV basis. There are examples for both `development` and `production`, so use those as guidelines. Here are some common configuration options:
129+
130+
|Key|Description|
131+
|---|-----------|
132+
|`dir_src`|application source code base path|
133+
|`dir_dist`|path to build compiled application to|
134+
|`server_host`|hostname for the Express server|
135+
|`server_port`|port for the Express server|
136+
|`compiler_devtool`|what type of source-maps to generate (set to `false`/`null` to disable)|
137+
|`compiler_vendor`|packages to separate into to the vendor bundle|
138+
139+
Webpack is configured to make use of [resolve.root](http://webpack.github.io/docs/configuration.html#resolve-root), which lets you import local packages as if you were traversing from the root of your `~/src` directory. Here's an example:
140+
141+
```js
142+
// current file: ~/src/views/some/nested/View.js
143+
// What used to be this:
144+
import SomeComponent from '../../../components/SomeComponent'
145+
146+
// Can now be this:
147+
import SomeComponent from 'components/SomeComponent' // Hooray!
148+
```
149+
150+
### Globals
151+
152+
These are global variables available to you anywhere in your source code. If you wish to modify them, they can be found as the `globals` key in `~/config/index.js`. When adding new globals, make sure you also add them to `~/.eslintrc`.
153+
154+
|Variable|Description|
155+
|---|---|
156+
|`process.env.NODE_ENV`|the active `NODE_ENV` when the build started|
157+
|`__DEV__`|True when `process.env.NODE_ENV` is `development`|
158+
|`__PROD__`|True when `process.env.NODE_ENV` is `production`|
159+
|`__TEST__`|True when `process.env.NODE_ENV` is `test`|
160+
161+
### Styles
162+
163+
Both `.scss` and `.css` file extensions are supported out of the box. After being imported, styles will be processed with [PostCSS](https://github.com/postcss/postcss) for minification and autoprefixing, and will be extracted to a `.css` file during production builds.
164+
165+
### Server
166+
167+
This starter kit comes packaged with an Express server. It's important to note that the sole purpose of this server is to provide `webpack-dev-middleware` and `webpack-hot-middleware` for hot module replacement. Using a custom Express app in place of [webpack-dev-server](https://github.com/webpack/webpack-dev-server) makes it easier to extend the starter kit to include functionality such as API's, universal rendering, and more -- all without bloating the base boilerplate.
168+
169+
### Production Optimization
170+
171+
Babel is configured to use [babel-plugin-transform-runtime](https://www.npmjs.com/package/babel-plugin-transform-runtime) so transforms aren't inlined. In production, webpack will extract styles to a `.css` file, minify your JavaScript, and perform additional optimizations such as module deduplication.
172+
173+
## Learning Resources
174+
175+
* [Starting out with react-redux-starter-kit](https://suspicious.website/2016/04/29/starting-out-with-react-redux-starter-kit/) is an introduction to the components used in this starter kit with a small example in the end.
176+
177+
16178
### Production
17179

18180
Build code before deployment by running `npm run build`. There are multiple options below for types of deployment, if you are unsure, checkout the Firebase section.
19181

20182
### Deployment
21183

22-
#### Firebase
23-
24184
1. Login to [Firebase](firebase.google.com) (or Signup if you don't have an account) and create a new project
25185
2. Install cli: `npm i -g firebase-tools`
26186
3. Login: `firebase login`
@@ -33,27 +193,9 @@ Build code before deployment by running `npm run build`. There are multiple opti
33193
6. Confirm Firebase config by running locally: `firebase serve`
34194
7. Deploy to firebase: `firebase deploy`
35195

36-
#### AWS S3
37-
38-
Selecting AWS S3 from the deploy options when running the generator adds deploy configs in `.travis.yml`.
39-
40-
1. Get your AWS Key and Secret from the AWS Console Credentials page
41-
2. Set the following environment vars within the Travis-CI repo settings page:
42-
* AWS_KEY - Your AWS key
43-
* AWS_SECRET - Your AWS secret
44-
* BUCKET - Your S3 Bucket
45196

46-
#### Heroku
47197

48-
Selecting [Heroku](http://heroku.com) from the deploy options when running the generator adds a `Procfile` as well as deploy configs in `.travis.yml` for out of the box deployment.
49198

50-
To deploy to [Heroku](http://heroku.com) through [Travis-CI](http://travis-ci.org):
51-
1. Enable Repo on Travis-CI Account
52-
2. Get API Key from Heroku Dashboard
53-
3. Create a new App (this name will be used in travis env var)
54-
4. Set the following environment vars within the Travis-CI repo settings page:
55-
* HEROKU_KEY - Your Heroku API key
56-
* APP - Your Heroku App name
57199

58200

59201
[npm-image]: https://img.shields.io/npm/v/react-firebase-redux.svg?style=flat-square

0 commit comments

Comments
 (0)