-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall.js
91 lines (84 loc) · 2.43 KB
/
install.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
82
83
84
85
86
87
88
89
90
91
/**
* This file contains code shamelessly, and grateful, cribbed from Medium Phantomjs installer. It is licensed under Apache 2.0.
*/
const exec = require('child_process').exec
const chalk = require('chalk')
const {
getWorlds,
mct1WorldsExistLocally,
worldUpdateAvailable,
getLocalWorldsMetadata,
} = require('./lib/getWorlds')
const { copyPlugin } = require('./lib/copyPlugin')
const { mct1WorldDir } = require('./lib/util')
// If the process exits without going through exit(), then we did not complete.
var validExit = false
Promise.resolve(true)
.then(checkForDocker)
.then(copyPlugin)
.then(checkMCT1WorldsLocally)
.then(getWorlds)
.then(() => exit(0))
.catch(e => {
console.log(`An error occured during installation`)
console.log(e)
exit(1)
})
function checkForDocker() {
return new Promise(resolve => {
exec('docker', {}, function(error, stdout, stderr) {
if (error) {
console.log(
'Docker not found. Please install Docker from https://www.docker.com.'
)
exit(1)
} else {
resolve(true)
}
})
})
}
function checkMCT1WorldsLocally() {
if (mct1WorldsExistLocally()) {
return Promise.resolve()
.then(getLocalWorldsMetadata)
.then(({ version }) => {
return console.log(
`Found MCT1 worlds version ${version} installed at`,
mct1WorldDir
)
})
.then(worldUpdateAvailable)
.then(updateAvailable => {
if (updateAvailable) {
console.log(
chalk.yellow(
`World update available: ${updateAvailable}`
)
)
}
return updateAvailable || exit(0)
})
} else {
return Promise.resolve()
}
}
process.on('exit', function() {
if (!validExit) {
console.log('Install exited unexpectedly')
exit(1)
}
})
function exit(code) {
validExit = true
if (code === 0) {
console.log(`MCT1 Server installed.`)
console.log(
'\n' +
chalk.blue('Type ') +
chalk.yellow('mct1-server start') +
chalk.blue(' to start\n')
)
}
process.exit(code || 0)
}