Skip to content

Commit 6b41327

Browse files
authored
Merge pull request #363 from oraclesorg/add-mobx
(Refactor) Mobx state management
2 parents 28f5a0e + fd204c1 commit 6b41327

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+35657
-1984
lines changed

.babelrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"presets": [
3+
"es2015",
4+
"stage-1",
5+
"react"
6+
],
7+
"plugins": ["transform-decorators-legacy"]
8+
}

.gitmodules

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[submodule "submodules/oracles-combine-solidity"]
66
path = submodules/oracles-combine-solidity
77
url = https://github.com/oraclesorg/oracles-combine-solidity
8+
branch = master
89
[submodule "submodules/oracles-web3-1.0"]
910
path = submodules/oracles-web3-1.0
1011
url = https://github.com/oraclesorg/web3.js

build_scripts/build.js

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
'use strict';
2+
3+
// Do this as the first thing so that any code reading it knows the right env.
4+
process.env.BABEL_ENV = 'production';
5+
process.env.NODE_ENV = 'production';
6+
7+
// Makes the script crash on unhandled rejections instead of silently
8+
// ignoring them. In the future, promise rejections that are not handled will
9+
// terminate the Node.js process with a non-zero exit code.
10+
process.on('unhandledRejection', err => {
11+
throw err;
12+
});
13+
14+
// Ensure environment variables are read.
15+
require('../config/env');
16+
17+
const path = require('path');
18+
const chalk = require('chalk');
19+
const fs = require('fs-extra');
20+
const webpack = require('webpack');
21+
const config = require('../config/webpack.config.prod');
22+
const paths = require('../config/paths');
23+
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
24+
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
25+
const printHostingInstructions = require('react-dev-utils/printHostingInstructions');
26+
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
27+
28+
const measureFileSizesBeforeBuild =
29+
FileSizeReporter.measureFileSizesBeforeBuild;
30+
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
31+
const useYarn = fs.existsSync(paths.yarnLockFile);
32+
33+
// These sizes are pretty large. We'll warn for bundles exceeding them.
34+
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
35+
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
36+
37+
// Warn and crash if required files are missing
38+
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
39+
process.exit(1);
40+
}
41+
42+
// First, read the current file sizes in build directory.
43+
// This lets us display how much they changed later.
44+
measureFileSizesBeforeBuild(paths.appBuild)
45+
.then(previousFileSizes => {
46+
// Remove all content but keep the directory so that
47+
// if you're in it, you don't end up in Trash
48+
fs.emptyDirSync(paths.appBuild);
49+
// Merge with the public folder
50+
copyPublicFolder();
51+
// Start the webpack build
52+
return build(previousFileSizes);
53+
})
54+
.then(
55+
({ stats, previousFileSizes, warnings }) => {
56+
if (warnings.length) {
57+
console.log(chalk.yellow('Compiled with warnings.\n'));
58+
console.log(warnings.join('\n\n'));
59+
console.log(
60+
'\nSearch for the ' +
61+
chalk.underline(chalk.yellow('keywords')) +
62+
' to learn more about each warning.'
63+
);
64+
console.log(
65+
'To ignore, add ' +
66+
chalk.cyan('// eslint-disable-next-line') +
67+
' to the line before.\n'
68+
);
69+
} else {
70+
console.log(chalk.green('Compiled successfully.\n'));
71+
}
72+
73+
console.log('File sizes after gzip:\n');
74+
printFileSizesAfterBuild(
75+
stats,
76+
previousFileSizes,
77+
paths.appBuild,
78+
WARN_AFTER_BUNDLE_GZIP_SIZE,
79+
WARN_AFTER_CHUNK_GZIP_SIZE
80+
);
81+
console.log();
82+
83+
const appPackage = require(paths.appPackageJson);
84+
const publicUrl = paths.publicUrl;
85+
const publicPath = config.output.publicPath;
86+
const buildFolder = path.relative(process.cwd(), paths.appBuild);
87+
printHostingInstructions(
88+
appPackage,
89+
publicUrl,
90+
publicPath,
91+
buildFolder,
92+
useYarn
93+
);
94+
},
95+
err => {
96+
console.log(chalk.red('Failed to compile.\n'));
97+
console.log((err.message || err) + '\n');
98+
process.exit(1);
99+
}
100+
);
101+
102+
// Create the production build and print the deployment instructions.
103+
function build(previousFileSizes) {
104+
console.log('Creating an optimized production build...');
105+
106+
let compiler = webpack(config);
107+
return new Promise((resolve, reject) => {
108+
compiler.run((err, stats) => {
109+
if (err) {
110+
return reject(err);
111+
}
112+
const messages = formatWebpackMessages(stats.toJson({}, true));
113+
if (messages.errors.length) {
114+
return reject(new Error(messages.errors.join('\n\n')));
115+
}
116+
if (
117+
process.env.CI &&
118+
(typeof process.env.CI !== 'string' ||
119+
process.env.CI.toLowerCase() !== 'false') &&
120+
messages.warnings.length
121+
) {
122+
console.log(
123+
chalk.yellow(
124+
'\nTreating warnings as errors because process.env.CI = true.\n' +
125+
'Most CI servers set it automatically.\n'
126+
)
127+
);
128+
return reject(new Error(messages.warnings.join('\n\n')));
129+
}
130+
return resolve({
131+
stats,
132+
previousFileSizes,
133+
warnings: messages.warnings,
134+
});
135+
});
136+
});
137+
}
138+
139+
function copyPublicFolder() {
140+
fs.copySync(paths.appPublic, paths.appBuild, {
141+
dereference: true,
142+
filter: file => file !== paths.appHtml,
143+
});
144+
}

build_scripts/start.js

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
'use strict';
2+
3+
// Do this as the first thing so that any code reading it knows the right env.
4+
process.env.BABEL_ENV = 'development';
5+
process.env.NODE_ENV = 'development';
6+
7+
// Makes the script crash on unhandled rejections instead of silently
8+
// ignoring them. In the future, promise rejections that are not handled will
9+
// terminate the Node.js process with a non-zero exit code.
10+
process.on('unhandledRejection', err => {
11+
throw err;
12+
});
13+
14+
// Ensure environment variables are read.
15+
require('../config/env');
16+
17+
const fs = require('fs');
18+
const chalk = require('chalk');
19+
const webpack = require('webpack');
20+
const WebpackDevServer = require('webpack-dev-server');
21+
const clearConsole = require('react-dev-utils/clearConsole');
22+
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
23+
const {
24+
choosePort,
25+
createCompiler,
26+
prepareProxy,
27+
prepareUrls,
28+
} = require('react-dev-utils/WebpackDevServerUtils');
29+
const openBrowser = require('react-dev-utils/openBrowser');
30+
const paths = require('../config/paths');
31+
const config = require('../config/webpack.config.dev');
32+
const createDevServerConfig = require('../config/webpackDevServer.config');
33+
34+
const useYarn = fs.existsSync(paths.yarnLockFile);
35+
const isInteractive = process.stdout.isTTY;
36+
37+
// Warn and crash if required files are missing
38+
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
39+
process.exit(1);
40+
}
41+
42+
// Tools like Cloud9 rely on this.
43+
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
44+
const HOST = process.env.HOST || '0.0.0.0';
45+
46+
// We attempt to use the default port but if it is busy, we offer the user to
47+
// run on a different port. `detect()` Promise resolves to the next free port.
48+
choosePort(HOST, DEFAULT_PORT)
49+
.then(port => {
50+
if (port == null) {
51+
// We have not found a port.
52+
return;
53+
}
54+
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
55+
const appName = require(paths.appPackageJson).name;
56+
const urls = prepareUrls(protocol, HOST, port);
57+
// Create a webpack compiler that is configured with custom messages.
58+
const compiler = createCompiler(webpack, config, appName, urls, useYarn);
59+
// Load proxy config
60+
const proxySetting = require(paths.appPackageJson).proxy;
61+
const proxyConfig = prepareProxy(proxySetting, paths.appPublic);
62+
// Serve webpack assets generated by the compiler over a web sever.
63+
const serverConfig = createDevServerConfig(
64+
proxyConfig,
65+
urls.lanUrlForConfig
66+
);
67+
const devServer = new WebpackDevServer(compiler, serverConfig);
68+
// Launch WebpackDevServer.
69+
devServer.listen(port, HOST, err => {
70+
if (err) {
71+
return console.log(err);
72+
}
73+
if (isInteractive) {
74+
clearConsole();
75+
}
76+
console.log(chalk.cyan('Starting the development server...\n'));
77+
openBrowser(urls.localUrlForBrowser);
78+
});
79+
80+
['SIGINT', 'SIGTERM'].forEach(function(sig) {
81+
process.on(sig, function() {
82+
devServer.close();
83+
process.exit();
84+
});
85+
});
86+
})
87+
.catch(err => {
88+
if (err && err.message) {
89+
console.log(err.message);
90+
}
91+
process.exit(1);
92+
});

build_scripts/test.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
// Do this as the first thing so that any code reading it knows the right env.
4+
process.env.BABEL_ENV = 'test';
5+
process.env.NODE_ENV = 'test';
6+
process.env.PUBLIC_URL = '';
7+
8+
// Makes the script crash on unhandled rejections instead of silently
9+
// ignoring them. In the future, promise rejections that are not handled will
10+
// terminate the Node.js process with a non-zero exit code.
11+
process.on('unhandledRejection', err => {
12+
throw err;
13+
});
14+
15+
// Ensure environment variables are read.
16+
require('../config/env');
17+
18+
const jest = require('jest');
19+
const argv = process.argv.slice(2);
20+
21+
// Watch unless on CI or in coverage mode
22+
if (!process.env.CI && argv.indexOf('--coverage') < 0) {
23+
argv.push('--watch');
24+
}
25+
26+
27+
jest.run(argv);

config/env.js

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const paths = require('./paths');
6+
7+
// Make sure that including paths.js after env.js will read .env variables.
8+
delete require.cache[require.resolve('./paths')];
9+
10+
const NODE_ENV = process.env.NODE_ENV;
11+
if (!NODE_ENV) {
12+
throw new Error(
13+
'The NODE_ENV environment variable is required but was not specified.'
14+
);
15+
}
16+
17+
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
18+
var dotenvFiles = [
19+
`${paths.dotenv}.${NODE_ENV}.local`,
20+
`${paths.dotenv}.${NODE_ENV}`,
21+
// Don't include `.env.local` for `test` environment
22+
// since normally you expect tests to produce the same
23+
// results for everyone
24+
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
25+
paths.dotenv,
26+
].filter(Boolean);
27+
28+
// Load environment variables from .env* files. Suppress warnings using silent
29+
// if this file is missing. dotenv will never modify any environment variables
30+
// that have already been set.
31+
// https://github.com/motdotla/dotenv
32+
dotenvFiles.forEach(dotenvFile => {
33+
if (fs.existsSync(dotenvFile)) {
34+
require('dotenv').config({
35+
path: dotenvFile,
36+
});
37+
}
38+
});
39+
40+
// We support resolving modules according to `NODE_PATH`.
41+
// This lets you use absolute paths in imports inside large monorepos:
42+
// https://github.com/facebookincubator/create-react-app/issues/253.
43+
// It works similar to `NODE_PATH` in Node itself:
44+
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
45+
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
46+
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
47+
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
48+
// We also resolve them to make sure all tools using them work consistently.
49+
const appDirectory = fs.realpathSync(process.cwd());
50+
process.env.NODE_PATH = (process.env.NODE_PATH || '')
51+
.split(path.delimiter)
52+
.filter(folder => folder && !path.isAbsolute(folder))
53+
.map(folder => path.resolve(appDirectory, folder))
54+
.join(path.delimiter);
55+
56+
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
57+
// injected into the application via DefinePlugin in Webpack configuration.
58+
const REACT_APP = /^REACT_APP_/i;
59+
60+
function getClientEnvironment(publicUrl) {
61+
const raw = Object.keys(process.env)
62+
.filter(key => REACT_APP.test(key))
63+
.reduce(
64+
(env, key) => {
65+
env[key] = process.env[key];
66+
return env;
67+
},
68+
{
69+
// Useful for determining whether we’re running in production mode.
70+
// Most importantly, it switches React into the correct mode.
71+
NODE_ENV: process.env.NODE_ENV || 'development',
72+
// Useful for resolving the correct path to static assets in `public`.
73+
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
74+
// This should only be used as an escape hatch. Normally you would put
75+
// images into the `src` and `import` them in code to get their paths.
76+
PUBLIC_URL: publicUrl,
77+
}
78+
);
79+
// Stringify all values so we can feed into Webpack DefinePlugin
80+
const stringified = {
81+
'process.env': Object.keys(raw).reduce((env, key) => {
82+
env[key] = JSON.stringify(raw[key]);
83+
return env;
84+
}, {}),
85+
};
86+
87+
return { raw, stringified };
88+
}
89+
90+
module.exports = getClientEnvironment;

config/jest/cssTransform.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
// This is a custom Jest transformer turning style imports into empty objects.
4+
// http://facebook.github.io/jest/docs/tutorial-webpack.html
5+
6+
module.exports = {
7+
process() {
8+
return 'module.exports = {};';
9+
},
10+
getCacheKey() {
11+
// The output is always the same.
12+
return 'cssTransform';
13+
},
14+
};

0 commit comments

Comments
 (0)