-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #363 from oraclesorg/add-mobx
(Refactor) Mobx state management
- Loading branch information
Showing
63 changed files
with
35,657 additions
and
1,984 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"presets": [ | ||
"es2015", | ||
"stage-1", | ||
"react" | ||
], | ||
"plugins": ["transform-decorators-legacy"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
'use strict'; | ||
|
||
// Do this as the first thing so that any code reading it knows the right env. | ||
process.env.BABEL_ENV = 'production'; | ||
process.env.NODE_ENV = 'production'; | ||
|
||
// Makes the script crash on unhandled rejections instead of silently | ||
// ignoring them. In the future, promise rejections that are not handled will | ||
// terminate the Node.js process with a non-zero exit code. | ||
process.on('unhandledRejection', err => { | ||
throw err; | ||
}); | ||
|
||
// Ensure environment variables are read. | ||
require('../config/env'); | ||
|
||
const path = require('path'); | ||
const chalk = require('chalk'); | ||
const fs = require('fs-extra'); | ||
const webpack = require('webpack'); | ||
const config = require('../config/webpack.config.prod'); | ||
const paths = require('../config/paths'); | ||
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles'); | ||
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages'); | ||
const printHostingInstructions = require('react-dev-utils/printHostingInstructions'); | ||
const FileSizeReporter = require('react-dev-utils/FileSizeReporter'); | ||
|
||
const measureFileSizesBeforeBuild = | ||
FileSizeReporter.measureFileSizesBeforeBuild; | ||
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild; | ||
const useYarn = fs.existsSync(paths.yarnLockFile); | ||
|
||
// These sizes are pretty large. We'll warn for bundles exceeding them. | ||
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024; | ||
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024; | ||
|
||
// Warn and crash if required files are missing | ||
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) { | ||
process.exit(1); | ||
} | ||
|
||
// First, read the current file sizes in build directory. | ||
// This lets us display how much they changed later. | ||
measureFileSizesBeforeBuild(paths.appBuild) | ||
.then(previousFileSizes => { | ||
// Remove all content but keep the directory so that | ||
// if you're in it, you don't end up in Trash | ||
fs.emptyDirSync(paths.appBuild); | ||
// Merge with the public folder | ||
copyPublicFolder(); | ||
// Start the webpack build | ||
return build(previousFileSizes); | ||
}) | ||
.then( | ||
({ stats, previousFileSizes, warnings }) => { | ||
if (warnings.length) { | ||
console.log(chalk.yellow('Compiled with warnings.\n')); | ||
console.log(warnings.join('\n\n')); | ||
console.log( | ||
'\nSearch for the ' + | ||
chalk.underline(chalk.yellow('keywords')) + | ||
' to learn more about each warning.' | ||
); | ||
console.log( | ||
'To ignore, add ' + | ||
chalk.cyan('// eslint-disable-next-line') + | ||
' to the line before.\n' | ||
); | ||
} else { | ||
console.log(chalk.green('Compiled successfully.\n')); | ||
} | ||
|
||
console.log('File sizes after gzip:\n'); | ||
printFileSizesAfterBuild( | ||
stats, | ||
previousFileSizes, | ||
paths.appBuild, | ||
WARN_AFTER_BUNDLE_GZIP_SIZE, | ||
WARN_AFTER_CHUNK_GZIP_SIZE | ||
); | ||
console.log(); | ||
|
||
const appPackage = require(paths.appPackageJson); | ||
const publicUrl = paths.publicUrl; | ||
const publicPath = config.output.publicPath; | ||
const buildFolder = path.relative(process.cwd(), paths.appBuild); | ||
printHostingInstructions( | ||
appPackage, | ||
publicUrl, | ||
publicPath, | ||
buildFolder, | ||
useYarn | ||
); | ||
}, | ||
err => { | ||
console.log(chalk.red('Failed to compile.\n')); | ||
console.log((err.message || err) + '\n'); | ||
process.exit(1); | ||
} | ||
); | ||
|
||
// Create the production build and print the deployment instructions. | ||
function build(previousFileSizes) { | ||
console.log('Creating an optimized production build...'); | ||
|
||
let compiler = webpack(config); | ||
return new Promise((resolve, reject) => { | ||
compiler.run((err, stats) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
const messages = formatWebpackMessages(stats.toJson({}, true)); | ||
if (messages.errors.length) { | ||
return reject(new Error(messages.errors.join('\n\n'))); | ||
} | ||
if ( | ||
process.env.CI && | ||
(typeof process.env.CI !== 'string' || | ||
process.env.CI.toLowerCase() !== 'false') && | ||
messages.warnings.length | ||
) { | ||
console.log( | ||
chalk.yellow( | ||
'\nTreating warnings as errors because process.env.CI = true.\n' + | ||
'Most CI servers set it automatically.\n' | ||
) | ||
); | ||
return reject(new Error(messages.warnings.join('\n\n'))); | ||
} | ||
return resolve({ | ||
stats, | ||
previousFileSizes, | ||
warnings: messages.warnings, | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
function copyPublicFolder() { | ||
fs.copySync(paths.appPublic, paths.appBuild, { | ||
dereference: true, | ||
filter: file => file !== paths.appHtml, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
'use strict'; | ||
|
||
// Do this as the first thing so that any code reading it knows the right env. | ||
process.env.BABEL_ENV = 'development'; | ||
process.env.NODE_ENV = 'development'; | ||
|
||
// Makes the script crash on unhandled rejections instead of silently | ||
// ignoring them. In the future, promise rejections that are not handled will | ||
// terminate the Node.js process with a non-zero exit code. | ||
process.on('unhandledRejection', err => { | ||
throw err; | ||
}); | ||
|
||
// Ensure environment variables are read. | ||
require('../config/env'); | ||
|
||
const fs = require('fs'); | ||
const chalk = require('chalk'); | ||
const webpack = require('webpack'); | ||
const WebpackDevServer = require('webpack-dev-server'); | ||
const clearConsole = require('react-dev-utils/clearConsole'); | ||
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles'); | ||
const { | ||
choosePort, | ||
createCompiler, | ||
prepareProxy, | ||
prepareUrls, | ||
} = require('react-dev-utils/WebpackDevServerUtils'); | ||
const openBrowser = require('react-dev-utils/openBrowser'); | ||
const paths = require('../config/paths'); | ||
const config = require('../config/webpack.config.dev'); | ||
const createDevServerConfig = require('../config/webpackDevServer.config'); | ||
|
||
const useYarn = fs.existsSync(paths.yarnLockFile); | ||
const isInteractive = process.stdout.isTTY; | ||
|
||
// Warn and crash if required files are missing | ||
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) { | ||
process.exit(1); | ||
} | ||
|
||
// Tools like Cloud9 rely on this. | ||
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000; | ||
const HOST = process.env.HOST || '0.0.0.0'; | ||
|
||
// We attempt to use the default port but if it is busy, we offer the user to | ||
// run on a different port. `detect()` Promise resolves to the next free port. | ||
choosePort(HOST, DEFAULT_PORT) | ||
.then(port => { | ||
if (port == null) { | ||
// We have not found a port. | ||
return; | ||
} | ||
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http'; | ||
const appName = require(paths.appPackageJson).name; | ||
const urls = prepareUrls(protocol, HOST, port); | ||
// Create a webpack compiler that is configured with custom messages. | ||
const compiler = createCompiler(webpack, config, appName, urls, useYarn); | ||
// Load proxy config | ||
const proxySetting = require(paths.appPackageJson).proxy; | ||
const proxyConfig = prepareProxy(proxySetting, paths.appPublic); | ||
// Serve webpack assets generated by the compiler over a web sever. | ||
const serverConfig = createDevServerConfig( | ||
proxyConfig, | ||
urls.lanUrlForConfig | ||
); | ||
const devServer = new WebpackDevServer(compiler, serverConfig); | ||
// Launch WebpackDevServer. | ||
devServer.listen(port, HOST, err => { | ||
if (err) { | ||
return console.log(err); | ||
} | ||
if (isInteractive) { | ||
clearConsole(); | ||
} | ||
console.log(chalk.cyan('Starting the development server...\n')); | ||
openBrowser(urls.localUrlForBrowser); | ||
}); | ||
|
||
['SIGINT', 'SIGTERM'].forEach(function(sig) { | ||
process.on(sig, function() { | ||
devServer.close(); | ||
process.exit(); | ||
}); | ||
}); | ||
}) | ||
.catch(err => { | ||
if (err && err.message) { | ||
console.log(err.message); | ||
} | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
// Do this as the first thing so that any code reading it knows the right env. | ||
process.env.BABEL_ENV = 'test'; | ||
process.env.NODE_ENV = 'test'; | ||
process.env.PUBLIC_URL = ''; | ||
|
||
// Makes the script crash on unhandled rejections instead of silently | ||
// ignoring them. In the future, promise rejections that are not handled will | ||
// terminate the Node.js process with a non-zero exit code. | ||
process.on('unhandledRejection', err => { | ||
throw err; | ||
}); | ||
|
||
// Ensure environment variables are read. | ||
require('../config/env'); | ||
|
||
const jest = require('jest'); | ||
const argv = process.argv.slice(2); | ||
|
||
// Watch unless on CI or in coverage mode | ||
if (!process.env.CI && argv.indexOf('--coverage') < 0) { | ||
argv.push('--watch'); | ||
} | ||
|
||
|
||
jest.run(argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const paths = require('./paths'); | ||
|
||
// Make sure that including paths.js after env.js will read .env variables. | ||
delete require.cache[require.resolve('./paths')]; | ||
|
||
const NODE_ENV = process.env.NODE_ENV; | ||
if (!NODE_ENV) { | ||
throw new Error( | ||
'The NODE_ENV environment variable is required but was not specified.' | ||
); | ||
} | ||
|
||
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use | ||
var dotenvFiles = [ | ||
`${paths.dotenv}.${NODE_ENV}.local`, | ||
`${paths.dotenv}.${NODE_ENV}`, | ||
// Don't include `.env.local` for `test` environment | ||
// since normally you expect tests to produce the same | ||
// results for everyone | ||
NODE_ENV !== 'test' && `${paths.dotenv}.local`, | ||
paths.dotenv, | ||
].filter(Boolean); | ||
|
||
// Load environment variables from .env* files. Suppress warnings using silent | ||
// if this file is missing. dotenv will never modify any environment variables | ||
// that have already been set. | ||
// https://github.com/motdotla/dotenv | ||
dotenvFiles.forEach(dotenvFile => { | ||
if (fs.existsSync(dotenvFile)) { | ||
require('dotenv').config({ | ||
path: dotenvFile, | ||
}); | ||
} | ||
}); | ||
|
||
// We support resolving modules according to `NODE_PATH`. | ||
// This lets you use absolute paths in imports inside large monorepos: | ||
// https://github.com/facebookincubator/create-react-app/issues/253. | ||
// It works similar to `NODE_PATH` in Node itself: | ||
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders | ||
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored. | ||
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims. | ||
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421 | ||
// We also resolve them to make sure all tools using them work consistently. | ||
const appDirectory = fs.realpathSync(process.cwd()); | ||
process.env.NODE_PATH = (process.env.NODE_PATH || '') | ||
.split(path.delimiter) | ||
.filter(folder => folder && !path.isAbsolute(folder)) | ||
.map(folder => path.resolve(appDirectory, folder)) | ||
.join(path.delimiter); | ||
|
||
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be | ||
// injected into the application via DefinePlugin in Webpack configuration. | ||
const REACT_APP = /^REACT_APP_/i; | ||
|
||
function getClientEnvironment(publicUrl) { | ||
const raw = Object.keys(process.env) | ||
.filter(key => REACT_APP.test(key)) | ||
.reduce( | ||
(env, key) => { | ||
env[key] = process.env[key]; | ||
return env; | ||
}, | ||
{ | ||
// Useful for determining whether we’re running in production mode. | ||
// Most importantly, it switches React into the correct mode. | ||
NODE_ENV: process.env.NODE_ENV || 'development', | ||
// Useful for resolving the correct path to static assets in `public`. | ||
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />. | ||
// This should only be used as an escape hatch. Normally you would put | ||
// images into the `src` and `import` them in code to get their paths. | ||
PUBLIC_URL: publicUrl, | ||
} | ||
); | ||
// Stringify all values so we can feed into Webpack DefinePlugin | ||
const stringified = { | ||
'process.env': Object.keys(raw).reduce((env, key) => { | ||
env[key] = JSON.stringify(raw[key]); | ||
return env; | ||
}, {}), | ||
}; | ||
|
||
return { raw, stringified }; | ||
} | ||
|
||
module.exports = getClientEnvironment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
// This is a custom Jest transformer turning style imports into empty objects. | ||
// http://facebook.github.io/jest/docs/tutorial-webpack.html | ||
|
||
module.exports = { | ||
process() { | ||
return 'module.exports = {};'; | ||
}, | ||
getCacheKey() { | ||
// The output is always the same. | ||
return 'cssTransform'; | ||
}, | ||
}; |
Oops, something went wrong.