From 0ac04c897d60f3cad0f35a8935bff03e47f15c5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Tue, 19 Sep 2017 12:41:08 +0100 Subject: [PATCH] feat(joyent-boilerplate): use joyent-react-scripts --- packages/joyent-boilerplate/package.json | 20 +-- .../scripts/patch-webpack-config.js | 120 ------------------ .../joyent-boilerplate/scripts/postinstall.js | 41 ------ .../scripts/webpack.config.dev.js | 4 - .../scripts/webpack.config.prod.js | 4 - yarn.lock | 13 +- 6 files changed, 18 insertions(+), 184 deletions(-) delete mode 100644 packages/joyent-boilerplate/scripts/patch-webpack-config.js delete mode 100644 packages/joyent-boilerplate/scripts/postinstall.js delete mode 100644 packages/joyent-boilerplate/scripts/webpack.config.dev.js delete mode 100644 packages/joyent-boilerplate/scripts/webpack.config.prod.js diff --git a/packages/joyent-boilerplate/package.json b/packages/joyent-boilerplate/package.json index 4db88542..c60e488d 100644 --- a/packages/joyent-boilerplate/package.json +++ b/packages/joyent-boilerplate/package.json @@ -5,15 +5,15 @@ "repository": "github:yldio/joyent-portal", "main": "build/", "scripts": { - "dev": "REACT_APP_GQL_PORT=3000 PORT=3069 REACT_APP_GQL_PROTOCOL=http react-scripts start", - "start": "PORT=3069 react-scripts start", - "build": "NODE_ENV=production react-scripts build", + "dev": "REACT_APP_GQL_PORT=3000 PORT=3069 REACT_APP_GQL_PROTOCOL=http joyent-react-scripts start", + "start": "PORT=3069 joyent-react-scripts start", + "build": "NODE_ENV=production joyent-react-scripts build", "lint:css": "stylelint './src/**/*.js'", "lint:js": "eslint . --fix", "lint": "redrun -s lint:*", "test": "NODE_ENV=test ./test/run --env=jsdom", "test-ci": "echo 0 `# NODE_ENV=test ./test/run --env=jsdom --coverage`", - "prepublish": "node scripts/postinstall" + "prepublish": "echo 0" }, "dependencies": { "apollo": "^0.2.2", @@ -33,16 +33,12 @@ "redux-form": "^7.0.3", "remcalc": "^1.0.8", "styled-components": "^2.1.2", - "styled-is": "^1.0.11", - "unitcalc": "^1.0.8" + "styled-is": "^1.0.11" }, "devDependencies": { - "apr-for-each": "^1.0.6", - "apr-main": "^1.0.7", "babel-plugin-inline-react-svg": "^0.4.0", "babel-plugin-styled-components": "^1.2.0", "babel-preset-joyent-portal": "^2.0.0", - "cross-env": "^5.0.5", "eslint": "^4.5.0", "eslint-config-joyent-portal": "3.0.0", "jest": "^21.0.1", @@ -54,9 +50,7 @@ "jest-snapshot": "^21.0.0", "jest-styled-components": "^4.4.1", "jest-transform-graphql": "^2.1.0", - "lodash.sortby": "^4.7.0", - "mz": "^2.6.0", - "react-scripts": "^1.0.12", + "joyent-react-scripts": "^1.0.2", "react-test-renderer": "^15.6.1", "redrun": "^5.9.17", "stylelint": "^8.1.1", @@ -65,4 +59,4 @@ "stylelint-config-styled-components": "^0.1.1", "stylelint-processor-styled-components": "^0.4.0" } -} \ No newline at end of file +} diff --git a/packages/joyent-boilerplate/scripts/patch-webpack-config.js b/packages/joyent-boilerplate/scripts/patch-webpack-config.js deleted file mode 100644 index ae95b04c..00000000 --- a/packages/joyent-boilerplate/scripts/patch-webpack-config.js +++ /dev/null @@ -1,120 +0,0 @@ -const webpack = require('webpack'); -const isString = require('lodash.isstring'); -const fs = require('fs'); -const path = require('path'); - -const FRONTEND_ROOT = process.cwd(); -const FRONTEND = path.join(FRONTEND_ROOT, 'src'); - -const BabelLoader = loader => ({ - test: loader.test, - include: loader.include, - loader: loader.loader, - options: { - babelrc: true, - cacheDirectory: true - } -}); - -const FileLoader = loader => ({ - exclude: loader.exclude.concat([/\.(graphql|gql)$/]), - loader: loader.loader, - options: loader.options -}); - -module.exports = config => { - config.resolve.plugins = []; - - config.plugins = config.plugins.filter( - plugin => !(plugin instanceof webpack.optimize.UglifyJsPlugin) - ); - - config.module.rules = config.module.rules - .reduce((loaders, loader, index) => { - if (Array.isArray(loader.use)) { - return loaders.concat([ - Object.assign(loader, { - use: loader.use.map(l => { - if (isString(l) || !isString(l.loader)) { - return l; - } - - if (!l.loader.match(/eslint-loader/)) { - return l; - } - - return Object.assign(l, { - options: Object.assign(l.options, { - baseConfig: null, - useEslintrc: true - }) - }); - }) - }) - ]); - } - - if (Array.isArray(loader.oneOf)) { - return loaders.concat([ - Object.assign(loader, { - oneOf: loader.oneOf.map(loader => { - if (!isString(loader.loader)) { - return loader; - } - - if (loader.loader.match(/babel-loader/)) { - return BabelLoader(loader); - } - - if (loader.loader.match(/file-loader/)) { - return FileLoader(loader); - } - - return loader; - }) - }) - ]); - } - - if (!isString(loader.loader)) { - return loaders.concat([loader]); - } - - if (loader.loader.match(/babel-loader/)) { - return loaders.concat(BabelLoader(loader)); - } - - if (loader.loader.match(/file-loader/)) { - return loaders.concat([FileLoader(loader)]); - } - - return loaders.concat([loader]); - }, []) - .concat([ - { - test: /\.(graphql|gql)$/, - exclude: /node_modules/, - loader: require.resolve('graphql-tag/loader') - } - ]); - - config.resolve.alias = Object.assign( - {}, - config.resolve.alias, - fs - .readdirSync(FRONTEND) - .map(name => path.join(FRONTEND, name)) - .filter(fullpath => fs.statSync(fullpath).isDirectory()) - .reduce( - (aliases, fullpath) => - Object.assign(aliases, { - [`@${path.basename(fullpath)}`]: fullpath - }), - { - '@root': FRONTEND - } - ) - ); - - return config; -}; diff --git a/packages/joyent-boilerplate/scripts/postinstall.js b/packages/joyent-boilerplate/scripts/postinstall.js deleted file mode 100644 index d313c46c..00000000 --- a/packages/joyent-boilerplate/scripts/postinstall.js +++ /dev/null @@ -1,41 +0,0 @@ -const { readFile, writeFile, exists } = require('mz/fs'); -const main = require('apr-main'); -const forEach = require('apr-for-each'); -const path = require('path'); - -const ROOT = path.join(__dirname, '../../../node_modules/react-scripts/config'); -const configs = ['webpack.config.dev', 'webpack.config.prod']; - -const toCopy = [ - 'patch-webpack-config', - 'webpack.config.dev', - 'webpack.config.prod' -]; - -const backup = async file => { - const backupPath = path.join(ROOT, `${file}.original.js`); - const backupExists = await exists(backupPath); - - if (backupExists) { - return; - } - - const originalPath = path.join(ROOT, `${file}.js`); - const orignalConfig = await readFile(originalPath, 'utf-8'); - return writeFile(backupPath, orignalConfig); -}; - -const copy = async file => { - const srcPath = path.join(__dirname, `${file}.js`); - const destPath = path.join(ROOT, `${file}.js`); - - const src = await readFile(srcPath, 'utf-8'); - return writeFile(destPath, src); -}; - -main( - (async () => { - await forEach(configs, backup); - await forEach(toCopy, copy); - })() -); diff --git a/packages/joyent-boilerplate/scripts/webpack.config.dev.js b/packages/joyent-boilerplate/scripts/webpack.config.dev.js deleted file mode 100644 index 324e9d33..00000000 --- a/packages/joyent-boilerplate/scripts/webpack.config.dev.js +++ /dev/null @@ -1,4 +0,0 @@ -const originalConfig = require('./webpack.config.dev.original'); -const patch = require('./patch-webpack-config'); - -module.exports = patch(originalConfig); diff --git a/packages/joyent-boilerplate/scripts/webpack.config.prod.js b/packages/joyent-boilerplate/scripts/webpack.config.prod.js deleted file mode 100644 index d4bb301c..00000000 --- a/packages/joyent-boilerplate/scripts/webpack.config.prod.js +++ /dev/null @@ -1,4 +0,0 @@ -const originalConfig = require('./webpack.config.prod.original'); -const patch = require('./patch-webpack-config'); - -module.exports = patch(originalConfig); diff --git a/yarn.lock b/yarn.lock index 316140d3..781efda9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6126,6 +6126,15 @@ jodid25519@^1.0.0: dependencies: jsbn "~0.1.0" +joyent-react-scripts@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/joyent-react-scripts/-/joyent-react-scripts-1.0.2.tgz#1c7503fcb13f66390e8e532fb5fe4c5d2cd25ac1" + dependencies: + apr-for-each "^1.0.6" + apr-main "^1.0.7" + mz "^2.7.0" + react-scripts "^1.0.13" + js-base64@^2.1.9: version "2.3.2" resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.3.2.tgz#a79a923666372b580f8e27f51845c6f7e8fbfbaf" @@ -7068,7 +7077,7 @@ mv@~2: ncp "~2.0.0" rimraf "~2.4.0" -mz@^2.6.0: +mz@^2.6.0, mz@^2.7.0: version "2.7.0" resolved "https://registry.yarnpkg.com/mz/-/mz-2.7.0.tgz#95008057a56cafadc2bc63dde7f9ff6955948e32" dependencies: @@ -8558,7 +8567,7 @@ react-router@^4.1.1, react-router@^4.2.0: prop-types "^15.5.4" warning "^3.0.0" -react-scripts@^1.0.12: +react-scripts@^1.0.12, react-scripts@^1.0.13: version "1.0.13" resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-1.0.13.tgz#a51d775a4b195ab2653c562b735735c8f70cba0e" dependencies: