Skip to content

Commit

Permalink
Task: Clean-up code (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagomapmarques committed Aug 2, 2019
1 parent 5e966f8 commit a54375d
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM nginx:1.15
FROM nginx:1.17

# install node 10 LTS
RUN apt-get -qq update && apt-get -qq --assume-yes install gnupg curl
Expand Down
6 changes: 2 additions & 4 deletions config/base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import HtmlWebpackPlugin from 'html-webpack-plugin';
import FaviconsWebpackPlugin from 'favicons-webpack-plugin';
import ManifestJsonWebpackPlugin from 'manifest-json-webpack-plugin';
import { sync as glob } from 'glob';
import reduceFlatten from 'reduce-flatten';

import { manifest } from './common/manifest';
import {
Expand Down Expand Up @@ -57,10 +58,7 @@ export const baseConfig = {
new ManifestJsonWebpackPlugin(manifest.pretty),
],
resolve: {
extensions: Object.keys(app.extensions).reduce((accumulator, key) => ([
...accumulator,
...app.extensions[key].map(ext => `.${ext}`),
]), []),
extensions: Object.values(app.extensions).reduce(reduceFlatten, []).map(ext => `.${ext}`),
modules: [
paths.appAbsolute,
'node_modules',
Expand Down
18 changes: 9 additions & 9 deletions config/common/add-server.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-disable import/no-extraneous-dependencies */
// eslint-disable-next-line import/no-extraneous-dependencies
import LocalWebServer from 'local-web-server';
import reduceFlatten from 'reduce-flatten';
// eslint-disable-next-line import/no-extraneous-dependencies
import opn from 'open';
/* eslint-enable import/no-extraneous-dependencies */
import reduceFlatten from 'reduce-flatten';
import os from 'os';

import { findPort } from './find-ports';

const server = (port, open, spa, https) => {
const serve = (port, open, spa, https) => {
LocalWebServer.create({
port,
https,
Expand All @@ -34,9 +34,9 @@ const server = (port, open, spa, https) => {
};

class ServeAfterFirstBuildPlugin {
constructor(options) {
constructor(port, options) {
this.isFirstCompilation = true;
this.port = findPort(options.port || 8000);
this.port = findPort(port);
this.open = options.open || false;
this.spa = options.spa || false;
this.secure = options.secure || false;
Expand All @@ -46,11 +46,11 @@ class ServeAfterFirstBuildPlugin {
compiler.hooks.afterEmit.tap('ServeAfterFirstBuild', () => {
if (this.isFirstCompilation) {
this.isFirstCompilation = false;
server(this.port, this.open, this.spa, this.secure);
serve(this.port, this.open, this.spa, this.secure);
}
});
}
}

export const addServer = (config, options) => config.plugins
.push(new ServeAfterFirstBuildPlugin(options));
export const addServer = (config, port, options) => config.plugins
.push(new ServeAfterFirstBuildPlugin(port, options));
5 changes: 2 additions & 3 deletions config/common/javascript-to-sass.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

const isNumber = (variable) => {
const value = parseInt(variable, 10);
// Comparing against itself to check if it is NaN
// eslint-disable-next-line no-self-compare
return value === value && typeof value === 'number';
// eslint-disable-next-line compat/compat
return typeof value === 'number' && !Number.isNaN(value);
};

const toSassVariable = variable => (
Expand Down
3 changes: 1 addition & 2 deletions config/common/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const projectPath = resolve(process.cwd());
// eslint-disable-next-line import/no-dynamic-require
const babelOptions = require(`${projectPath}/.babelrc.js`);

const removeLast = path => path.split('/').reverse().slice(1).reverse()
.join('/');
const removeLast = path => path.split('/').slice(0, -1).join('/');

const getStyleNaming = (minify, globalStyles) => {
if (globalStyles) {
Expand Down
3 changes: 2 additions & 1 deletion config/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { environments } from './environments';
import { app } from './settings';

export const webpackInit = (requestedEnv, { serve, open, spa }) => {
const actualEnv = (requestedEnv && environments[requestedEnv]) || environments.default;
Expand All @@ -9,7 +10,7 @@ export const webpackInit = (requestedEnv, { serve, open, spa }) => {

if (serve) {
// eslint-disable-next-line global-require
require('./common/add-server').addServer(config, { open, spa });
require('./common/add-server').addServer(config, app.port, { open, spa });
}

return config;
Expand Down
1 change: 1 addition & 0 deletions config/settings/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const app = {
script: '[name].js',
style: '[name].css',
},
port: 8000,
rendering: {
staticDir: paths.distAbsolute,
routes: ['/'],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"postcss-loader": "~3.0",
"prerender-spa-plugin": "~3.4",
"raw-loader": "~3.1",
"reduce-flatten": "~2.0",
"sass-loader": "~7.1",
"url-loader": "~2.1",
"webpack": "~4.39",
Expand All @@ -86,7 +87,6 @@
"jest-fetch-mock": "~2.1",
"local-web-server": "~3.0",
"open": "~6.4",
"reduce-flatten": "~2.0",
"synchronized-promise": "~0.1",
"typescript": "~3.5",
"webpack-livereload-plugin": "~2.2"
Expand Down
60 changes: 39 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1054,9 +1054,9 @@
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==

"@types/node@*", "@types/node@~12.6":
version "12.6.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.6.8.tgz#e469b4bf9d1c9832aee4907ba8a051494357c12c"
integrity sha512-aX+gFgA5GHcDi89KG5keey2zf0WfZk/HAQotEamsK2kbey+8yGKcson0hbK8E+v0NArlCJQCqMP161YhV6ZXLg==
version "12.6.9"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.6.9.tgz#ffeee23afdc19ab16e979338e7b536fdebbbaeaf"
integrity sha512-+YB9FtyxXGyD54p8rXwWaN1EWEyar5L58GlGWgtH2I9rGmLGBQcw63+0jw+ujqVavNuO47S1ByAjm9zdHMnskw==

"@types/q@^1.5.1":
version "1.5.2"
Expand Down Expand Up @@ -1703,9 +1703,9 @@ async-foreach@^0.1.3:
integrity sha1-NhIfhFwFeBct5Bmpfb6x0W7DRUI=

async-limiter@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8"
integrity sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==
version "1.0.1"
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==

async@^1.5.0, async@^1.5.2:
version "1.5.2"
Expand Down Expand Up @@ -3452,13 +3452,13 @@ dom-converter@^0.2:
dependencies:
utila "~0.4"

dom-serializer@0, dom-serializer@~0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.1.1.tgz#1ec4059e284babed36eec2941d4a970a189ce7c0"
integrity sha512-l0IU0pPzLWSHBcieZbpOKgkIn3ts3vAh7ZuFyXNwJxJXk/c4Gwj9xaTJwIDVQCXawWD0qb3IzMGH5rglQaO0XA==
dom-serializer@0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.2.1.tgz#13650c850daffea35d8b626a4cfc4d3a17643fdb"
integrity sha512-sK3ujri04WyjwQXVoK4PU3y8ula1stq10GJZpqHIUgoGZdsGzAGu65BnU3d08aTVSvO7mGPZUc0wTEDL+qGE0Q==
dependencies:
domelementtype "^1.3.0"
entities "^1.1.1"
domelementtype "^2.0.1"
entities "^2.0.0"

[email protected]:
version "0.1.0"
Expand All @@ -3468,6 +3468,14 @@ [email protected]:
domelementtype "~1.1.1"
entities "~1.1.1"

dom-serializer@~0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.1.1.tgz#1ec4059e284babed36eec2941d4a970a189ce7c0"
integrity sha512-l0IU0pPzLWSHBcieZbpOKgkIn3ts3vAh7ZuFyXNwJxJXk/c4Gwj9xaTJwIDVQCXawWD0qb3IzMGH5rglQaO0XA==
dependencies:
domelementtype "^1.3.0"
entities "^1.1.1"

dom-walk@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.1.tgz#672226dc74c8f799ad35307df936aba11acd6018"
Expand All @@ -3483,6 +3491,11 @@ domelementtype@1, domelementtype@^1.3.0, domelementtype@^1.3.1:
resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-1.3.1.tgz#d048c44b37b0d10a7f2a3d5fee3f4333d790481f"
integrity sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==

domelementtype@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-2.0.1.tgz#1f8bdfe91f5a78063274e803b4bdcedf6e94f94d"
integrity sha512-5HOHUDsYZWV8FGWN0Njbr/Rn7f/eWSQi1v7+HsUVwXgn8nWWlL64zKDkS0n8ZmQ3mlWOMuXOnR+7Nx/5tMO5AQ==

domelementtype@~1.1.1:
version "1.1.3"
resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-1.1.3.tgz#bd28773e2642881aec51544924299c5cd822185b"
Expand Down Expand Up @@ -3599,9 +3612,9 @@ [email protected]:
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=

electron-to-chromium@^1.3.191:
version "1.3.210"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.210.tgz#0ce6247366c5771d4f5663a5879388fd1adefb7e"
integrity sha512-m1i/F+gw9jkauxDx0mOr7Sj6vp6se1mfkQNYqZb1yL5VGTp0AC1NZH5CGI6YMSO7WaScILmkKDZFG9/hlR9axQ==
version "1.3.211"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.211.tgz#0c39d17316bf342d1971fed68e754fa1775918f7"
integrity sha512-GZAiK3oHrs0K+LwH+HD+bdjZ17v40oQQdXbbd3dgrwgbENvazrGpcuIADSAREWnxzo9gADB1evuizrbXsnoU2Q==

elliptic@^6.0.0:
version "6.5.0"
Expand Down Expand Up @@ -3662,6 +3675,11 @@ entities@^1.1.1, entities@~1.1.1:
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56"
integrity sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==

entities@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/entities/-/entities-2.0.0.tgz#68d6084cab1b079767540d80e56a39b423e4abf4"
integrity sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw==

errno@^0.1.3, errno@~0.1.7:
version "0.1.7"
resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.7.tgz#4684d71779ad39af177e3f007996f7c67c852618"
Expand Down Expand Up @@ -10546,9 +10564,9 @@ stylelint-no-unsupported-browser-features@~3.0:
postcss "^7.0.0"

stylelint-scss@~3.9:
version "3.9.2"
resolved "https://registry.yarnpkg.com/stylelint-scss/-/stylelint-scss-3.9.2.tgz#5435174a57696ee52eae40146778a4e62f7ed3a3"
integrity sha512-VUh173p3T1qJf016P7yeJ6nxkUpqF5qQ+VSDw3J8P6wEJbA1loaNgBHR3k3skHvUkF+9brLO1ibCHA00pjW3cw==
version "3.9.3"
resolved "https://registry.yarnpkg.com/stylelint-scss/-/stylelint-scss-3.9.3.tgz#4fa300eeb2feced9b00ca6fbe5fa664bca146a06"
integrity sha512-pLLpwSpUwiqpAga/C22ZuN/d5ql2zVWGzG8MO+P3DQYcDNue3eZGvda/bJdkx4mDcVy06jlDt+BgSvMYUrwleQ==
dependencies:
lodash "^4.17.11"
postcss-media-query-parser "^0.2.3"
Expand Down Expand Up @@ -11552,9 +11570,9 @@ webpack-sources@^1.0, webpack-sources@^1.1.0, webpack-sources@^1.4.0, webpack-so
source-map "~0.6.1"

webpack@~4.39:
version "4.39.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.39.0.tgz#1d511308c3dd8f9fe3152c9447ce30f1814a620c"
integrity sha512-nrxFNSEKm4T1C/EsgOgN50skt//Pl4X7kgJC1MrlE47M292LSCVmMOC47iTGL0CGxbdwhKGgeThrJcw0bstEfA==
version "4.39.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.39.1.tgz#60ed9fb2b72cd60f26ea526c404d2a4cc97a1bd8"
integrity sha512-/LAb2TJ2z+eVwisldp3dqTEoNhzp/TLCZlmZm3GGGAlnfIWDgOEE758j/9atklNLfRyhKbZTCOIoPqLJXeBLbQ==
dependencies:
"@webassemblyjs/ast" "1.8.5"
"@webassemblyjs/helper-module-context" "1.8.5"
Expand Down

0 comments on commit a54375d

Please sign in to comment.