-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.js
More file actions
103 lines (94 loc) · 3.78 KB
/
start.js
File metadata and controls
103 lines (94 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* eslint-disable require-atomic-updates */
/* eslint-disable @typescript-eslint/no-var-requires */
// Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = process.env.BABEL_ENV || 'development';
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
let devServer;
// 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 => {
if (devServer) {
devServer.close();
}
throw err;
});
// Ensure environment variables are read.
const {configureEnvVariables} = require('@statechannels/devtools');
configureEnvVariables();
const fs = require('fs');
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 configFactory = require('../config/webpack.config');
const createDevServerConfig = require('../config/webpackDevServer.config');
const config = require('../config/webpackDevServer.config');
const {getNetworkName, setupGanache} = require('@statechannels/devtools');
const {deploy} = require('../deployment/deploy');
void (async () => {
process.on('SIGINT', () => {
if (devServer) {
devServer.close();
}
});
process.on('SIGTERM', () => {
if (devServer) {
devServer.close();
}
});
process.env.TARGET_NETWORK = getNetworkName(process.env.CHAIN_NETWORK_ID);
// TODO: Devtools doesn't support hyperspace yet
if (Number(process.env.CHAIN_NETWORK_ID) === 3141) {
process.env.TARGET_NETWORK = 'hyperspace';
console.log("Using 'hyperspace' as the target network");
}
if (process.env.TARGET_NETWORK === 'development') {
// Add contract addresses to process.env if running ganache
const {deployer} = await await setupGanache(process.env.XSTATE_WALLET_DEPLOYER_ACCOUNT_INDEX);
const deployedArtifacts = await deploy(deployer);
process.env = {...process.env, ...deployedArtifacts};
}
const isInteractive = process.stdout.isTTY;
const {checkBrowsers} = require('react-dev-utils/browsersHelper');
await checkBrowsers(paths.appPath, isInteractive);
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3055;
const HOST = process.env.HOST || '0.0.0.0';
const port = await choosePort(HOST, DEFAULT_PORT);
const config = configFactory('development');
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
const appName = require(paths.appPackageJson).name;
const useTypeScript = fs.existsSync(paths.appTsConfig);
const urls = prepareUrls(protocol, HOST, port);
const devSocket = {
warnings: warnings => devServer.sockWrite(devServer.sockets, 'warnings', warnings),
errors: errors => devServer.sockWrite(devServer.sockets, 'errors', errors)
};
// Create a webpack compiler that is configured with custom messages.
const compiler = createCompiler({
appName,
config,
devSocket,
urls,
useYarn: true,
useTypeScript,
webpack
});
// 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 server.
const serverConfig = createDevServerConfig(proxyConfig, urls.lanUrlForConfig);
const devServer = new WebpackDevServer(compiler, serverConfig);
devServer.listen(port, HOST, error => {
console.error(error);
});
})();