-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.js
81 lines (74 loc) · 2.3 KB
/
launch.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
72
73
74
75
76
77
78
79
80
81
// Set up nodemon to run jigs in development mode. Offers all sorts of nice
// features, restarting it if it's config changes, if it changes, etc.
const path = require('path')
const { green, bold, red } = require('colorette')
const nodemon = require('nodemon')
const jetpack = require('fs-jetpack')
let jigsConfig
if (jetpack.exists('./jigs.config.js')) {
jigsConfig = require(path.resolve('./jigs.config.js'))
}
// set NODE_ENV according to the JIGS_MODE
// TODO: sometimes, for an app with a back-end, "jigs build" may be used to
// build a dev site, so we shouldn't hard-code the NODE_ENV here.
if (process.env.JIGS_MODE === 'build') {
process.env.NODE_ENV = 'production'
} else {
process.env.NODE_ENV = 'development'
}
if (process.env.JIGS_MODE === undefined) {
console.log(red(bold('Jigs was invoked without any JIGS_MODE env set')))
process.exit(1)
} else if (process.env.JIGS_MODE === 'development') {
nodemon({
script: path.resolve(__dirname, 'build', 'index.js'),
watch: [
// restart jigs if any of these files in the project change...
'./jigs.config.js',
'webpack.base.config.js',
'webpack.client.config.js',
'webpack.server.config.js',
jigsConfig.rootTemplate,
// ... or if jigs is rebuilt
path.resolve(__dirname, 'build')
],
delay: 0.1,
env: process.env
})
const saySomething = thing => {
console.log(green(bold(`[${thing}]`)))
}
let isRestarting = false
nodemon.on('start', function () {
if (!isRestarting) {
saySomething('Jigs is starting (enter "rs" to restart at any time)')
}
isRestarting = false
}).on('quit', function () {
saySomething('Jigs has quit')
process.exit()
}).on('restart', function () {
isRestarting = true
saySomething('Jigs is restarting')
})
} else if (process.env.JIGS_MODE === 'build') {
const c = require('child_process')
.spawnSync(
'node', [
`${path.resolve(__dirname, 'build', 'index.js')}`,
...process.argv.slice(2)
], {
stdio: 'inherit',
// child process inherits environment
env: process.env
},
err => {
console.log('??')
if (err.code) {
process.exit(err.code)
}
}
)
} else {
console.log(red(bold(`Unknown JIGS_MODE env "${process.env.JIGS_MODE}"`)))
}