feat(joyent-boilerplate): use joyent-react-scripts

This commit is contained in:
Sérgio Ramos 2017-09-19 12:41:08 +01:00
parent 0a8b025c7e
commit 0ac04c897d
6 changed files with 18 additions and 184 deletions

View File

@ -5,15 +5,15 @@
"repository": "github:yldio/joyent-portal", "repository": "github:yldio/joyent-portal",
"main": "build/", "main": "build/",
"scripts": { "scripts": {
"dev": "REACT_APP_GQL_PORT=3000 PORT=3069 REACT_APP_GQL_PROTOCOL=http react-scripts start", "dev": "REACT_APP_GQL_PORT=3000 PORT=3069 REACT_APP_GQL_PROTOCOL=http joyent-react-scripts start",
"start": "PORT=3069 react-scripts start", "start": "PORT=3069 joyent-react-scripts start",
"build": "NODE_ENV=production react-scripts build", "build": "NODE_ENV=production joyent-react-scripts build",
"lint:css": "stylelint './src/**/*.js'", "lint:css": "stylelint './src/**/*.js'",
"lint:js": "eslint . --fix", "lint:js": "eslint . --fix",
"lint": "redrun -s lint:*", "lint": "redrun -s lint:*",
"test": "NODE_ENV=test ./test/run --env=jsdom", "test": "NODE_ENV=test ./test/run --env=jsdom",
"test-ci": "echo 0 `# NODE_ENV=test ./test/run --env=jsdom --coverage`", "test-ci": "echo 0 `# NODE_ENV=test ./test/run --env=jsdom --coverage`",
"prepublish": "node scripts/postinstall" "prepublish": "echo 0"
}, },
"dependencies": { "dependencies": {
"apollo": "^0.2.2", "apollo": "^0.2.2",
@ -33,16 +33,12 @@
"redux-form": "^7.0.3", "redux-form": "^7.0.3",
"remcalc": "^1.0.8", "remcalc": "^1.0.8",
"styled-components": "^2.1.2", "styled-components": "^2.1.2",
"styled-is": "^1.0.11", "styled-is": "^1.0.11"
"unitcalc": "^1.0.8"
}, },
"devDependencies": { "devDependencies": {
"apr-for-each": "^1.0.6",
"apr-main": "^1.0.7",
"babel-plugin-inline-react-svg": "^0.4.0", "babel-plugin-inline-react-svg": "^0.4.0",
"babel-plugin-styled-components": "^1.2.0", "babel-plugin-styled-components": "^1.2.0",
"babel-preset-joyent-portal": "^2.0.0", "babel-preset-joyent-portal": "^2.0.0",
"cross-env": "^5.0.5",
"eslint": "^4.5.0", "eslint": "^4.5.0",
"eslint-config-joyent-portal": "3.0.0", "eslint-config-joyent-portal": "3.0.0",
"jest": "^21.0.1", "jest": "^21.0.1",
@ -54,9 +50,7 @@
"jest-snapshot": "^21.0.0", "jest-snapshot": "^21.0.0",
"jest-styled-components": "^4.4.1", "jest-styled-components": "^4.4.1",
"jest-transform-graphql": "^2.1.0", "jest-transform-graphql": "^2.1.0",
"lodash.sortby": "^4.7.0", "joyent-react-scripts": "^1.0.2",
"mz": "^2.6.0",
"react-scripts": "^1.0.12",
"react-test-renderer": "^15.6.1", "react-test-renderer": "^15.6.1",
"redrun": "^5.9.17", "redrun": "^5.9.17",
"stylelint": "^8.1.1", "stylelint": "^8.1.1",

View File

@ -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;
};

View File

@ -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);
})()
);

View File

@ -1,4 +0,0 @@
const originalConfig = require('./webpack.config.dev.original');
const patch = require('./patch-webpack-config');
module.exports = patch(originalConfig);

View File

@ -1,4 +0,0 @@
const originalConfig = require('./webpack.config.prod.original');
const patch = require('./patch-webpack-config');
module.exports = patch(originalConfig);

View File

@ -6126,6 +6126,15 @@ jodid25519@^1.0.0:
dependencies: dependencies:
jsbn "~0.1.0" 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: js-base64@^2.1.9:
version "2.3.2" version "2.3.2"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.3.2.tgz#a79a923666372b580f8e27f51845c6f7e8fbfbaf" resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.3.2.tgz#a79a923666372b580f8e27f51845c6f7e8fbfbaf"
@ -7068,7 +7077,7 @@ mv@~2:
ncp "~2.0.0" ncp "~2.0.0"
rimraf "~2.4.0" rimraf "~2.4.0"
mz@^2.6.0: mz@^2.6.0, mz@^2.7.0:
version "2.7.0" version "2.7.0"
resolved "https://registry.yarnpkg.com/mz/-/mz-2.7.0.tgz#95008057a56cafadc2bc63dde7f9ff6955948e32" resolved "https://registry.yarnpkg.com/mz/-/mz-2.7.0.tgz#95008057a56cafadc2bc63dde7f9ff6955948e32"
dependencies: dependencies:
@ -8558,7 +8567,7 @@ react-router@^4.1.1, react-router@^4.2.0:
prop-types "^15.5.4" prop-types "^15.5.4"
warning "^3.0.0" warning "^3.0.0"
react-scripts@^1.0.12: react-scripts@^1.0.12, react-scripts@^1.0.13:
version "1.0.13" version "1.0.13"
resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-1.0.13.tgz#a51d775a4b195ab2653c562b735735c8f70cba0e" resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-1.0.13.tgz#a51d775a4b195ab2653c562b735735c8f70cba0e"
dependencies: dependencies: