Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #65 from codekiln/redux_-_general_example_#64
Browse files Browse the repository at this point in the history
fix #64
  • Loading branch information
codekiln authored Aug 31, 2017
2 parents 1b24dfa + 57837a6 commit 9660ed5
Show file tree
Hide file tree
Showing 114 changed files with 4,681 additions and 3,871 deletions.
24 changes: 22 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/**
* WARNING: This file is just to prevent from global .babelrc files!
* This babel funcitonality is actually controlled within config/index.js
**/
{
"presets": ["react-app", "es2015", "react"]
}
"plugins": [
"transform-runtime",
"lodash",
"transform-decorators-legacy"
],
"presets": [
"es2015",
"react",
"stage-0"
],
"env": {
"test": {
"plugins": [
"transform-es2015-modules-commonjs"
]
}
}
}
34 changes: 34 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"parser" : "babel-eslint",
"extends" : [
"standard",
"standard-react",
"prettier/react"
],
"plugins": [
"babel",
"prettier"
],
"env" : {
"browser" : true
},
"globals" : {
"__DEV__" : false,
"__PROD__" : false,
"__DEBUG__" : false,
"__COVERAGE__" : false,
"__BASENAME__" : false
},
"rules": {
"semi" : [2, "never"],
"max-len": [2, 120, 2],
"generator-star-spacing": 0,
"babel/generator-star-spacing": 1,
"jsx-quotes": ["error", "prefer-single"],
"prettier/prettier": ["error", {
"singleQuote": true,
"trailingComma": "es6",
"semi": false
}]
}
}
7 changes: 7 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"projects": {
"dev": "beetimer-redux",
"stage": "beetimer-redux",
"prod": "beetimer-redux"
}
}
55 changes: 55 additions & 0 deletions bin/compile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const webpack = require('webpack')
const debug = require('debug')('app:bin:compile')
const webpackConfig = require('../config/webpack.config')
const project = require('../config/project.config')

// Wrapper around webpack to promisify its compiler and supply friendly logging
const webpackCompiler = (webpackConfig) =>
new Promise((resolve, reject) => {
const compiler = webpack(webpackConfig)

compiler.run((err, stats) => {
if (err) {
debug('Webpack compiler encountered a fatal error.', err)
return reject(err)
}

const jsonStats = stats.toJson()
debug('Webpack compile completed.')
debug(stats.toString(project.compiler_stats))

if (jsonStats.errors.length > 0) {
debug('Webpack compiler encountered errors.')
debug(jsonStats.errors.join('\n'))
return reject(new Error('Webpack compiler encountered errors'))
} else if (jsonStats.warnings.length > 0) {
debug('Webpack compiler encountered warnings.')
debug(jsonStats.warnings.join('\n'))
} else {
debug('No errors or warnings encountered.')
}
resolve(jsonStats)
})
})

const compile = () => {
debug('Starting compiler.')
return Promise.resolve()
.then(() => webpackCompiler(webpackConfig))
// .then(stats => {
// if (stats.warnings.length && project.compiler_fail_on_warning) {
// throw new Error('Config set to fail on warning, exiting with status code "1".')
// }
// debug('Copying static assets to dist folder.')
// fs.copySync(project.paths.public(), project.paths.dist())
// })
.then(() => {
debug('Compilation completed successfully.')
})
.catch((err) => {
debug('Compiler encountered an error.', err)
process.exit(1)
})
}

compile()
6 changes: 6 additions & 0 deletions bin/dev-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const project = require('../config/project.config')
const server = require('../server/main')
const debug = require('debug')('app:bin:server')

server.listen(project.server_port)
debug(`Server is now running at http://localhost:${project.server_port}.`)
60 changes: 60 additions & 0 deletions config/environments.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Here is where you can define configuration overrides based on the execution environment.
// Supply a key to the default export matching the NODE_ENV that you wish to target, and
// the base configuration will apply your overrides before exporting itself.

const apiKeyLocal = process.env.FIREBASE_OLDTIMER_LOCAL_DEV

module.exports = {
// ======================================================
// Overrides when NODE_ENV === 'development'
// ======================================================
// NOTE: In development, we use an explicit public path when the assets
// are served webpack by to fix this issue:
// http://stackoverflow.com/questions/34133808/webpack-ots-parsing-error-loading-fonts/34133809#34133809
development: (config) => ({
compiler_public_path: `http://${config.server_host}:${config.server_port}/`,
firebase: {
apiKey: apiKeyLocal,
authDomain: "oldtimer-9dfb6.firebaseapp.com",
databaseURL: "https://oldtimer-9dfb6.firebaseio.com",
projectId: "oldtimer-9dfb6",
storageBucket: "oldtimer-9dfb6.appspot.com",
messagingSenderId: "332873739617"
},
reduxFirebase: {
userProfile: 'users', // root that user profiles are written to
enableLogging: false, // enable/disable Firebase Database Logging
updateProfileOnLogin: false // enable/disable updating of profile on login
// profileDecorator: (userData) => ({ email: userData.email }) // customize format of user profile
}
}),

// ======================================================
// Overrides when NODE_ENV === 'production'
// ======================================================
production: (config) => ({
compiler_public_path: '/',
compiler_fail_on_warning: false,
compiler_hash_type: 'chunkhash',
compiler_devtool: null,
compiler_stats: {
chunks: true,
chunkModules: true,
colors: true
},
firebase: {
apiKey: "AIzaSyCd6-VL0WhO1kjS8sfXIgGl3co4T8Xf83A",
authDomain: "oldtimer-9dfb6.firebaseapp.com",
databaseURL: "https://oldtimer-9dfb6.firebaseio.com",
projectId: "oldtimer-9dfb6",
storageBucket: "oldtimer-9dfb6.appspot.com",
messagingSenderId: "332873739617"
},
reduxFirebase: {
userProfile: 'users', // root that user profiles are written to
enableLogging: false, // enable/disable Firebase Database Logging
updateProfileOnLogin: false // enable/disable updating of profile on login
// profileDecorator: (userData) => ({ email: userData.email }) // customize format of user profile
}
})
}
135 changes: 135 additions & 0 deletions config/project.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/* eslint key-spacing:0 spaced-comment:0 */
const path = require('path')
const debug = require('debug')('app:config')
const argv = require('yargs').argv
const ip = require('ip')

debug('Creating default configuration.')
// ========================================================
// Default Configuration
// ========================================================
const config = {
env : process.env.NODE_ENV || 'development',

// ----------------------------------
// Project Structure
// ----------------------------------
path_base : path.resolve(__dirname, '..'),
dir_client : 'src',
dir_dist : 'dist',
dir_server : 'server',
dir_test : 'tests',

// ----------------------------------
// Server Configuration
// ----------------------------------
server_host : ip.address(), // use string 'localhost' to prevent exposure on local network
server_port : process.env.PORT || 3000,

// ----------------------------------
// Compiler Configuration
// ----------------------------------
compiler_babel : {
cacheDirectory : true,
plugins : ['transform-runtime', 'lodash', 'transform-decorators-legacy'],
presets : ['es2015', 'react', 'stage-0']
},
compiler_devtool : 'eval',
compiler_hash_type : 'hash',
compiler_fail_on_warning : false,
compiler_quiet : false,
compiler_public_path : '/',
compiler_stats : {
chunks : false,
chunkModules : false,
colors : true
},
compiler_vendors : [
'react',
'react-router',
'react-redux',
// 'redux', // avoid warning in production
'react-redux-firebase',
'material-ui'
],

compiler_css_modules: true, // enable/disable css modules

// ----------------------------------
// Test Configuration
// ----------------------------------
coverage_reporters : [
{ type : 'text-summary' },
{ type : 'lcov', dir : 'coverage' }
]
}

/************************************************
-------------------------------------------------
All Internal Configuration Below
Edit at Your Own Risk
-------------------------------------------------
************************************************/

// ------------------------------------
// Environment
// ------------------------------------
// N.B.: globals added here must _also_ be added to .eslintrc
config.globals = {
'process.env' : {
'NODE_ENV' : JSON.stringify(config.env)
},
'NODE_ENV' : config.env,
'__DEV__' : config.env === 'development',
'__PROD__' : config.env === 'production',
'__TEST__' : config.env === 'test',
'__COVERAGE__' : !argv.watch && config.env === 'test',
'__BASENAME__' : JSON.stringify(process.env.BASENAME || '')
}

// ------------------------------------
// Validate Vendor Dependencies
// ------------------------------------
const pkg = require('../package.json')

config.compiler_vendors = config.compiler_vendors
.filter((dep) => {
if (pkg.dependencies[dep]) return true

debug(
`Package "${dep}" was not found as an npm dependency in package.json; ` +
`it won't be included in the webpack vendor bundle.
Consider removing it from \`compiler_vendors\` in ~/config/index.js`
)
})

// ------------------------------------
// Utilities
// ------------------------------------
function base () {
const args = [config.path_base].concat([].slice.call(arguments))
return path.resolve.apply(path, args)
}

config.paths = {
base : base,
client : base.bind(null, config.dir_client),
dist : base.bind(null, config.dir_dist)
}

// ========================================================
// Environment Configuration
// ========================================================
debug(`Looking for environment overrides for NODE_ENV "${config.env}".`)
const environments = require('./environments.config')
const overrides = environments[config.env]
if (overrides) {
debug('Found overrides, applying to default configuration.')
Object.assign(config, overrides(config))
} else {
debug('No environment overrides found, defaults will be used.')
}

module.exports = config
Loading

0 comments on commit 9660ed5

Please sign in to comment.