forked from OriginProtocol/origin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
71 lines (63 loc) · 1.6 KB
/
index.js
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
import { spawn } from 'child_process'
import services from '@origin/services'
let localContractAddress
try {
const Addresses = require(`@origin/contracts/build/contracts.json`)
localContractAddress = Addresses.Marketplace_V01
} catch (e) {
/* Ignore */
}
async function start() {
let shuttingDown = false
const shutdownAll = async () => {
if (shuttingDown) return
shuttingDown = true
if (shutdown) {
await shutdown()
}
if (webpackDevServer) {
webpackDevServer.kill()
}
if (backend) {
backend.kill()
}
console.log('Shut down ok.')
}
process.on('SIGINT', shutdownAll)
process.on('SIGTERM', shutdownAll)
const shutdown = await services({
ganache: true,
deployContracts: true,
ipfs: true,
skipContractsIfExists: process.env.CLEAN ? false : true
})
const devServerArgs = ['--host=0.0.0.0']
if (process.env.NODE_ENV === 'production') {
devServerArgs.push('--info=false')
}
if (process.env.NOOPENER !== 'true') {
devServerArgs.push('--open')
}
const webpackDevServer = spawn(
'./node_modules/.bin/webpack-dev-server',
devServerArgs,
{
stdio: 'inherit',
env: process.env
}
)
let backend
if (process.env.BACKEND !== 'false') {
console.log(`Starting backend with local contract ${localContractAddress}`)
backend = spawn('node', ['backend'], {
stdio: 'inherit',
env: {
...process.env,
MARKETPLACE_CONTRACT: localContractAddress,
DATA_URL:
process.env.DATA_URL || `http://0.0.0.0:8081/${process.env.DATA_DIR}/`
}
})
}
}
start()