diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 9748435e7..000000000 --- a/.eslintrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": [ - "eslint:recommended", - "plugin:react/recommended" - ] -} diff --git a/.eslintrc.json b/.eslintrc.json index 1c17e897a..731580171 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,9 @@ { "parser": "babel-eslint", "extends": [ - "airbnb" + "airbnb", + "eslint:recommended", + "plugin:react/recommended" ], "rules": { "jsx-quotes": ["error", "prefer-single"], @@ -19,10 +21,16 @@ "jsx-a11y/no-static-element-interactions": 0, "jsx-a11y/no-noninteractive-element-interactions": 0, "jsx-a11y/label-has-for": 0, + "jsx-a11y/control-has-associated-label": 0, "no-plusplus": 0, "react/prefer-stateless-function": 0, "no-nested-ternary": 0, - "import/prefer-default-export": 0 + "import/prefer-default-export": 0, + "comma-dangle": ["error", "always-multiline"], + "arrow-parens": [2, "as-needed", { "requireForBlockBody": true }], + "react/static-property-placement": ["error", "static public field"], + "react/state-in-constructor": 0, + "react/jsx-props-no-spreading": 0 }, "settings": { "import/resolver": { diff --git a/.gitignore b/.gitignore index 50ce22d57..0d163e0e5 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,8 @@ yarn.lock todo /db /logs/*.log +tags + +Session.vim +.undodir +coverage diff --git a/config/getHttpsConfig.js b/config/getHttpsConfig.js new file mode 100644 index 000000000..013d493c1 --- /dev/null +++ b/config/getHttpsConfig.js @@ -0,0 +1,66 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const crypto = require('crypto'); +const chalk = require('react-dev-utils/chalk'); +const paths = require('./paths'); + +// Ensure the certificate and key provided are valid and if not +// throw an easy to debug error +function validateKeyAndCerts({ cert, key, keyFile, crtFile }) { + let encrypted; + try { + // publicEncrypt will throw an error with an invalid cert + encrypted = crypto.publicEncrypt(cert, Buffer.from('test')); + } catch (err) { + throw new Error( + `The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}` + ); + } + + try { + // privateDecrypt will throw an error with an invalid key + crypto.privateDecrypt(key, encrypted); + } catch (err) { + throw new Error( + `The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${ + err.message + }` + ); + } +} + +// Read file and throw an error if it doesn't exist +function readEnvFile(file, type) { + if (!fs.existsSync(file)) { + throw new Error( + `You specified ${chalk.cyan( + type + )} in your env, but the file "${chalk.yellow(file)}" can't be found.` + ); + } + return fs.readFileSync(file); +} + +// Get the https config +// Return cert files if provided in env, otherwise just true or false +function getHttpsConfig() { + const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env; + const isHttps = HTTPS === 'true'; + + if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) { + const crtFile = path.resolve(paths.appPath, SSL_CRT_FILE); + const keyFile = path.resolve(paths.appPath, SSL_KEY_FILE); + const config = { + cert: readEnvFile(crtFile, 'SSL_CRT_FILE'), + key: readEnvFile(keyFile, 'SSL_KEY_FILE'), + }; + + validateKeyAndCerts({ ...config, keyFile, crtFile }); + return config; + } + return isHttps; +} + +module.exports = getHttpsConfig; diff --git a/config/paths.js b/config/paths.js index 8416daec7..ee6257bb3 100644 --- a/config/paths.js +++ b/config/paths.js @@ -1,40 +1,23 @@ - - -const path = require('path') -const fs = require('fs') -const url = require('url') +const path = require('path'); +const fs = require('fs'); +const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath'); // Make sure any symlinks in the project folder are resolved: // https://github.com/facebook/create-react-app/issues/637 -const appDirectory = fs.realpathSync(process.cwd()) -const resolveApp = relativePath => path.resolve(appDirectory, relativePath) - -const envPublicUrl = process.env.PUBLIC_URL - -function ensureSlash(inputPath, needsSlash) { - const hasSlash = inputPath.endsWith('/') - if (hasSlash && !needsSlash) { - return inputPath.substr(0, inputPath.length - 1) - } if (!hasSlash && needsSlash) { - return `${inputPath}/` - } - return inputPath - -} - -const getPublicUrl = appPackageJson => envPublicUrl || require(appPackageJson).homepage +const appDirectory = fs.realpathSync(process.cwd()); +const resolveApp = relativePath => path.resolve(appDirectory, relativePath); // We use `PUBLIC_URL` environment variable or "homepage" field to infer // "public path" at which the app is served. -// Webpack needs to know it to put the right