From ada55f14fd0dc3afd0479ed1f339ada0f85d9027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Mon, 24 Oct 2016 14:11:50 +0100 Subject: [PATCH] lint frontend --- frontend/.eslintignore | 3 ++- frontend/package.json | 2 +- frontend/scripts/build-locales.js | 5 +---- frontend/src/intl.js | 5 +++-- frontend/src/root.js | 1 - frontend/webpack/{config.js => base.js} | 4 ++-- frontend/webpack/development.js | 8 ++++---- frontend/webpack/production.js | 6 +++--- frontend/webpack/test.js | 12 +++++------- 9 files changed, 21 insertions(+), 25 deletions(-) rename frontend/webpack/{config.js => base.js} (97%) diff --git a/frontend/.eslintignore b/frontend/.eslintignore index b1d4c644..f9b9f952 100644 --- a/frontend/.eslintignore +++ b/frontend/.eslintignore @@ -1,3 +1,4 @@ /node_modules coverage -.nyc_output \ No newline at end of file +.nyc_output +static \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index d3375b06..deb744fa 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -14,7 +14,7 @@ "test": "BABEL_DISABLE_CACHE=1 NODE_ENV=test CONFIG=$(pwd)/webpack/index.js nyc ava test/*.js --verbose", "open": "nyc report --reporter=html & open coverage/index.html", "coverage": "nyc check-coverage --statements 100 --functions 100 --lines 100 --branches 100", - "build-locales": "NODE_ENV=test babel-node scripts/build-locales" + "build-locales": " CONFIG=$(pwd)/webpack/index.js NODE_ENV=test babel-node scripts/build-locales" }, "dependencies": { "constant-case": "^2.0.0", diff --git a/frontend/scripts/build-locales.js b/frontend/scripts/build-locales.js index 8ca37b7b..599b7e0d 100644 --- a/frontend/scripts/build-locales.js +++ b/frontend/scripts/build-locales.js @@ -5,7 +5,6 @@ const Ncp = require('ncp'); const readdir = thenify(fs.readdir); const writeFile = thenify(fs.writeFile); -const readFile = thenify(fs.readFile); const ncp = thenify(Ncp.ncp); const root = path.join(__dirname, '../locales'); @@ -27,7 +26,7 @@ const compile = async () => { const files = await readdir(root); const jsons = files.filter(filename => path.extname(filename) === '.json'); - const locales = files.reduce((res, filename) => { + const locales = jsons.reduce((res, filename) => { const name = path.parse(filename).name; const json = JSON.stringify(require(path.join(root, filename))); const lang = name.split(/\-/)[0]; @@ -52,8 +51,6 @@ const compile = async () => { return ncp(source, destination); })); - - return await Promise.all(Object.keys(locales).map((name) => { console.log(`Writing ${name}.js`); diff --git a/frontend/src/intl.js b/frontend/src/intl.js index c771ce54..2a531164 100644 --- a/frontend/src/intl.js +++ b/frontend/src/intl.js @@ -25,8 +25,9 @@ module.exports = (({ ).toLowerCase(); const lang = detectedLocale.split(/\-/)[0]; - const locale = ReactIntlLocaleData[lang] ? - (Locales[detectedLocale] ? detectedLocale : 'en-us') : 'en-us'; + const locale = ReactIntlLocaleData[lang] + ? (Locales[detectedLocale] ? detectedLocale : 'en-us') + : 'en-us'; return { locale, diff --git a/frontend/src/root.js b/frontend/src/root.js index db12152c..b92b2515 100644 --- a/frontend/src/root.js +++ b/frontend/src/root.js @@ -1,4 +1,3 @@ -const qs = require('querystring'); const React = require('react'); const ReactIntlRedux = require('react-intl-redux'); const ReactHotLoader = require('react-hot-loader'); diff --git a/frontend/webpack/config.js b/frontend/webpack/base.js similarity index 97% rename from frontend/webpack/config.js rename to frontend/webpack/base.js index 01ea94c2..59ca778b 100644 --- a/frontend/webpack/config.js +++ b/frontend/webpack/base.js @@ -33,7 +33,7 @@ const plugins = { }) }; -module.exports = { +exports.config = { context: path.join(__dirname, '../src'), output: { path: path.join(__dirname, '../static'), @@ -76,4 +76,4 @@ module.exports = { } }; -module.exports.__plugins = plugins; +exports.plugins = plugins; diff --git a/frontend/webpack/development.js b/frontend/webpack/development.js index b657d827..fa85d998 100644 --- a/frontend/webpack/development.js +++ b/frontend/webpack/development.js @@ -1,12 +1,12 @@ const graphql = require('../../cloudapi-graphql/src/endpoint'); -const config = require('./config.js'); +const base = require('./base.js'); const webpack = require('webpack'); const devServer = { hot: true, compress: true, lazy: false, - publicPath: config.output.publicPath, + publicPath: base.config.output.publicPath, setup: (app) => { app.use('/graphql', graphql); }, @@ -15,14 +15,14 @@ const devServer = { } }; -module.exports = Object.assign(config, { +module.exports = Object.assign(base.config, { entry: [ 'react-hot-loader/patch', 'webpack-dev-server/client?http://localhost:8080', 'webpack/hot/only-dev-server', './index.js' ], - plugins: config.plugins.concat([ + plugins: base.config.plugins.concat([ new webpack.HotModuleReplacementPlugin() ]), devtool: 'source-map', diff --git a/frontend/webpack/production.js b/frontend/webpack/production.js index 7d1a0c48..688eece7 100644 --- a/frontend/webpack/production.js +++ b/frontend/webpack/production.js @@ -1,11 +1,11 @@ -const config = require('./config.js'); +const base = require('./base.js'); const webpack = require('webpack'); -module.exports = Object.assign(config, { +module.exports = Object.assign(base.config, { entry: [ './index.js' ], - plugins: config.plugins.concat([ + plugins: base.config.concat([ new webpack.optimize.DedupePlugin(), new webpack.optimize.OccurrenceOrderPlugin(true), new webpack.optimize.UglifyJsPlugin() diff --git a/frontend/webpack/test.js b/frontend/webpack/test.js index ba6eebc4..aad175cc 100644 --- a/frontend/webpack/test.js +++ b/frontend/webpack/test.js @@ -1,15 +1,13 @@ -const config = require('./config'); -const webpack = require('webpack'); -const path = require('path'); +const base = require('./base'); module.exports = { output: { libraryTarget: 'commonjs2' }, plugins: [ - config.__plugins['no-errors-plugin'], - config.__plugins['loader-options-plugin'], - config.__plugins['define-plugin'] + base.plugins['no-errors-plugin'], + base.plugins['loader-options-plugin'], + base.plugins['define-plugin'] ], module: { loaders: [{ @@ -17,4 +15,4 @@ module.exports = { loader: 'style-loader!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss-loader' }] } -}; \ No newline at end of file +};