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

Commit

Permalink
refactor(build): upgrade to webpack 2
Browse files Browse the repository at this point in the history
  • Loading branch information
David Zukowski committed May 17, 2017
1 parent 1a4a71b commit 6b3b570
Show file tree
Hide file tree
Showing 48 changed files with 2,885 additions and 3,092 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
blueprints/**/files/**
coverage/**
node_modules/**
dist/**
Expand Down
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
"__COVERAGE__" : false
},
"rules": {
"key-spacing" : 0,
"key-spacing" : "off",
"jsx-quotes" : [2, "prefer-single"],
"max-len" : [2, 120, 2],
"object-curly-spacing" : [2, "always"]
"object-curly-spacing" : [2, "always"],
"comma-dangle" : "off"
}
}
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
.DS_STORE
*.log

node_modules

dist
coverage

.idea/
.yarn-cache
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ node_js:
- "6"

cache:
yarn: true
directories:
- node_modules

install:
- npm install -g yarn
- yarn install

script:
- npm run deploy:dev
- npm run deploy:prod
- yarn lint
- yarn test
- yarn build

after_success:
- npm run codecov
- yarn codecov
195 changes: 76 additions & 119 deletions README.md

Large diffs are not rendered by default.

56 changes: 0 additions & 56 deletions bin/compile.js

This file was deleted.

6 changes: 0 additions & 6 deletions bin/dev-server.js

This file was deleted.

50 changes: 50 additions & 0 deletions build/karma.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const argv = require('yargs').argv
const webpackConfig = require('./webpack.config')

const TEST_BUNDLER = './tests/test-bundler.js'

const karmaConfig = {
basePath: '../',
browsers: ['PhantomJS'],
singleRun: !argv.watch,
coverageReporter: {
reporters: [
{ type: 'text-summary' },
],
},
files: [{
pattern : TEST_BUNDLER,
watched : false,
served : true,
included : true
}],
frameworks: ['mocha'],
reporters: ['mocha'],
preprocessors: {
[TEST_BUNDLER]: ['webpack'],
},
logLevel: 'WARN',
browserConsoleLogOptions: {
terminal: true,
format: '%b %T: %m',
level: '',
},
webpack: {
entry: TEST_BUNDLER,
devtool: 'cheap-module-source-map',
module: webpackConfig.module,
plugins: webpackConfig.plugins,
resolve: webpackConfig.resolve,
externals: {
'react/addons': 'react',
'react/lib/ExecutionEnvironment': 'react',
'react/lib/ReactContext': 'react',
},
},
webpackMiddleware: {
stats: 'errors-only',
noInfo: true,
},
}

module.exports = (cfg) => cfg.set(karmaConfig)
8 changes: 8 additions & 0 deletions build/lib/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const chalk = require('chalk')
const figures = require('figures')

exports.log = (...messages) => console.log(...messages)
exports.error = (...messages) => console.error(chalk.red(figures.cross, ...messages))
exports.info = (...messages) => console.info(chalk.cyan(figures.info, ...messages))
exports.success = (...messages) => console.log(chalk.green(figures.tick, ...messages))
exports.warn = (...messages) => console.warn(chalk.yellow(figures.warning, ...messages))
53 changes: 53 additions & 0 deletions build/scripts/compile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const fs = require('fs-extra')
const path = require('path')
const chalk = require('chalk')
const webpack = require('webpack')
const logger = require('../lib/logger')
const webpackConfig = require('../webpack.config')
const project = require('../../project.config')

const runWebpackCompiler = (webpackConfig) =>
new Promise((resolve, reject) => {
webpack(webpackConfig).run((err, stats) => {
if (err) {
logger.error('Webpack compiler encountered a fatal error.', err)
return reject(err)
}

const jsonStats = stats.toJson()
if (jsonStats.errors.length > 0) {
logger.error('Webpack compiler encountered errors.')
logger.log(jsonStats.errors.join('\n'))
return reject(new Error('Webpack compiler encountered errors'))
} else if (jsonStats.warnings.length > 0) {
logger.warn('Webpack compiler encountered warnings.')
logger.log(jsonStats.warnings.join('\n'))
}
resolve(stats)
})
})

const compile = () => Promise.resolve()
.then(() => logger.info('Starting compiler...'))
.then(() => logger.info('Target application environment: ' + chalk.bold(project.env)))
.then(() => runWebpackCompiler(webpackConfig))
.then((stats) => {
logger.info(`Copying static assets from ./public to ./${project.outDir}.`)
fs.copySync(
path.resolve(project.basePath, 'public'),
path.resolve(project.basePath, project.outDir)
)
return stats
})
.then((stats) => {
if (project.verbose) {
logger.log(stats.toString({
colors: true,
chunks: false,
}))
}
logger.success(`Compiler finished successfully! See ./${project.outDir}.`)
})
.catch((err) => logger.error('Compiler encountered errors.', err))

compile()
6 changes: 6 additions & 0 deletions build/scripts/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const logger = require('../lib/logger')

logger.info('Starting server...')
require('../../server/main').listen(3000, () => {
logger.success('Server is running at http://localhost:3000')
})
Loading

0 comments on commit 6b3b570

Please sign in to comment.