diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ebc613c26..4551c5691 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,5 +5,5 @@ entry: ./node_modules/.bin/prettier language: node stages: [commit] - files: ^(static/)*.(js|css) + files: (.*)\.(js|css)$ args: ["--write"] diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..4047166e5 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +node_modules/ +static/ diff --git a/.prettierrc b/.prettierrc.js similarity index 100% rename from .prettierrc rename to .prettierrc.js diff --git a/karma.conf.js b/karma.conf.js index 31beac8b4..434436db7 100755 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,16 +1,12 @@ -const sharedConfig = require('./shared.webpack')({context: {DEBUG: true}}); +const sharedConfig = require('./shared.webpack')({ context: { DEBUG: true } }); const webpackConfig = require('./webpack.config.js'); process.env.CHROME_BIN = require('puppeteer').executablePath(); -module.exports = function (config) { +module.exports = function(config) { config.set({ autoWatch: true, browsers: ['ChromeHeadless'], frameworks: ['jasmine'], - files: [ - 'bundles/init/index.js', - 'bundles/**/*_spec.js', - 'bundles/**/*Spec.js', - ], + files: ['bundles/init/index.js', 'bundles/**/*_spec.js', 'bundles/**/*Spec.js'], preprocessors: { 'bundles/init/*.js': ['webpack'], 'bundles/**/*_spec.js': ['webpack'], @@ -26,10 +22,6 @@ module.exports = function (config) { noInfo: true, poll: 1000, }, - plugins: [ - require('karma-webpack'), - require('karma-jasmine'), - require('karma-chrome-launcher'), - ], + plugins: [require('karma-webpack'), require('karma-jasmine'), require('karma-chrome-launcher')], }); }; diff --git a/package.json b/package.json index e4f8b48a6..045e00816 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "build": "git clean -fxd static && cross-env NODE_ENV=production webpack", "start": "cross-env NODE_ENV=${NODE_ENV:-development} SOURCE_MAPS=${SOURCE_MAPS:-1} webpack-dev-server", "test": "karma start --single-run", - "test:watch": "karma start" + "test:watch": "karma start", + "fix:prettier": "prettier --write \"bundles/**\"" }, "author": "", "license": "ISC", diff --git a/shared.webpack.js b/shared.webpack.js index bf24fc5d2..d66e9174a 100755 --- a/shared.webpack.js +++ b/shared.webpack.js @@ -4,14 +4,13 @@ const _ = require('lodash'); const packageJSON = require('./package.json'); function keyMirror(obj) { - return Object.keys(obj).reduce(function (memo, key) { + return Object.keys(obj).reduce(function(memo, key) { memo[key] = key; return memo; }, {}); } - -module.exports = function (opts = {}) { +module.exports = function(opts = {}) { const hmr = opts.hmr || process.env.NODE_ENV === 'development'; return { module: { @@ -19,10 +18,7 @@ module.exports = function (opts = {}) { { test: /\.jsx?$/, exclude: /(node_modules|bower_components)/, - use: _.compact([ - hmr && 'react-hot-loader/webpack', - 'babel-loader', - ]), + use: _.compact([hmr && 'react-hot-loader/webpack', 'babel-loader']), }, { test: /\.css$/, @@ -43,31 +39,25 @@ module.exports = function (opts = {}) { localIdentName: '[local]--[hash:base64:10]', }, }, - } + }, ], }, { test: /\.(png|jpg|svg)$/, - use: [ - 'url-loader', - ], + use: ['url-loader'], }, { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, - use: [ - 'url-loader?limit=10000&mimetype=application/font-woff' - ], + use: ['url-loader?limit=10000&mimetype=application/font-woff'], }, { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, - use: [ - 'file-loader', - ], - } + use: ['file-loader'], + }, ], }, node: { - fs: 'empty' + fs: 'empty', }, resolve: { alias: { @@ -77,24 +67,14 @@ module.exports = function (opts = {}) { poll: 1000, externals: keyMirror(packageJSON.dependencies), devServer: { - proxy: [{ - context: [ - '/admin', - '/logout', - '/api', - '/ui', - '/static', - '/tracker', - '/donate', - ], - target: 'http://localhost:8000/', - headers: {'X-Webpack': 1}, - }], - allowedHosts: [ - 'localhost', - '127.0.0.1', - '.ngrok.io', + proxy: [ + { + context: ['/admin', '/logout', '/api', '/ui', '/static', '/tracker', '/donate'], + target: 'http://localhost:8000/', + headers: { 'X-Webpack': 1 }, + }, ], + allowedHosts: ['localhost', '127.0.0.1', '.ngrok.io'], }, }; }; diff --git a/webpack.config.js b/webpack.config.js index 3314647af..411bc2a82 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,7 +3,6 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const WebpackManifestPlugin = require('webpack-yam-plugin'); const sharedConfig = require('./shared.webpack')(); - const PROD = process.env.NODE_ENV === 'production'; console.log(PROD ? 'PRODUCTION BUILD' : 'DEVELOPMENT BUILD'); @@ -16,17 +15,17 @@ module.exports = { donate: ['./bundles/init', './bundles/donate'], }, output: { - 'filename': PROD ? 'tracker-[name]-[hash].js' : 'tracker-[name].js', - 'pathinfo': true, - 'path': __dirname + '/static/gen', - 'publicPath': '/static/gen', + filename: PROD ? 'tracker-[name]-[hash].js' : 'tracker-[name].js', + pathinfo: true, + path: __dirname + '/static/gen', + publicPath: '/static/gen', }, module: sharedConfig.module, plugins: [ new webpack.optimize.OccurrenceOrderPlugin(), new WebpackManifestPlugin({ manifestPath: __dirname + '/ui-tracker.manifest.json', - outputRoot: __dirname + '/static' + outputRoot: __dirname + '/static', }), new MiniCssExtractPlugin({ filename: PROD ? 'tracker-[name]-[hash].css' : 'tracker-[name].css',