From fe3d5c1bb71880476d67dcd164eb12eecbab7fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Tue, 17 Oct 2017 15:48:32 +0100 Subject: [PATCH] build(my-joyent): use joyent-react-scripts --- packages/my-joyent/package.json | 11 +- .../my-joyent/scripts/patch-webpack-config.js | 124 ------------------ packages/my-joyent/scripts/postinstall.js | 41 ------ .../my-joyent/scripts/webpack.config.dev.js | 4 - .../my-joyent/scripts/webpack.config.prod.js | 4 - 5 files changed, 6 insertions(+), 178 deletions(-) delete mode 100644 packages/my-joyent/scripts/patch-webpack-config.js delete mode 100644 packages/my-joyent/scripts/postinstall.js delete mode 100644 packages/my-joyent/scripts/webpack.config.dev.js delete mode 100644 packages/my-joyent/scripts/webpack.config.prod.js diff --git a/packages/my-joyent/package.json b/packages/my-joyent/package.json index d3024bed..d9cb54b7 100644 --- a/packages/my-joyent/package.json +++ b/packages/my-joyent/package.json @@ -5,15 +5,15 @@ "repository": "github:yldio/joyent-portal", "main": "build/", "scripts": { - "dev": "REACT_APP_GQL_PORT=4000 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=4000 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": "echo 0 `# 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" + "test-ci": "echo 0 `# NODE_ENV=test ./test/run --env=jsdom --coverage`" }, "dependencies": { "apollo": "^0.2.2", @@ -57,6 +57,7 @@ "jest-snapshot": "^21.2.1", "jest-styled-components": "^4.7.0", "jest-transform-graphql": "^2.1.0", + "joyent-react-scripts": "^2.3.0", "lodash.sortby": "^4.7.0", "mz": "^2.7.0", "react-scripts": "^1.0.14", diff --git a/packages/my-joyent/scripts/patch-webpack-config.js b/packages/my-joyent/scripts/patch-webpack-config.js deleted file mode 100644 index b9c990e6..00000000 --- a/packages/my-joyent/scripts/patch-webpack-config.js +++ /dev/null @@ -1,124 +0,0 @@ -const MinifyPlugin = require('babel-minify-webpack-plugin'); -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, - compact: 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.map( - plugin => - plugin instanceof webpack.optimize.UglifyJsPlugin - ? new MinifyPlugin() - : plugin - ); - - 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/my-joyent/scripts/postinstall.js b/packages/my-joyent/scripts/postinstall.js deleted file mode 100644 index d313c46c..00000000 --- a/packages/my-joyent/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/my-joyent/scripts/webpack.config.dev.js b/packages/my-joyent/scripts/webpack.config.dev.js deleted file mode 100644 index 324e9d33..00000000 --- a/packages/my-joyent/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/my-joyent/scripts/webpack.config.prod.js b/packages/my-joyent/scripts/webpack.config.prod.js deleted file mode 100644 index d4bb301c..00000000 --- a/packages/my-joyent/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);