forked from lirantal/dockly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·97 lines (81 loc) · 1.9 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
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
#!/usr/bin/env node
'use strict'
/**
* Project dependencies
*/
const semver = require('semver')
const chalk = require('chalk')
const nodeVersion = require('./lib/node.version')
const Screen = require('./src/screen')
const DockerUtil = require('./src/dockerUtil')
const cli = require('./src/cli')
const cliOptions = cli.cliParse()
if (cliOptions.help) {
cli.showUsage()
process.exit(0)
}
if (cliOptions.version) {
cli.showVersion()
process.exit(0)
}
if (semver.lt(process.version, nodeVersion.minimum)) {
cli.showUsage()
console.log(chalk.red('unsupported node version, please use a version equal or greater than ' + nodeVersion.minimum))
process.exit(0)
}
initDockerConnection()
.then(initScreens)
.then(function (screen) {
process.on('uncaughtException', (err) => {
// Make sure the screen is cleared
screen.teardown()
exitError(err)
})
})
.catch((err) => {
return exitError(err)
})
function initDockerConnection () {
return new Promise((resolve, reject) => {
let utils
let docker
try {
docker = new DockerUtil(cli.cliParse())
} catch (err) {
return exitError(err)
}
docker.ping((err) => {
if (err) {
return reject(err)
}
utils = new Map([
['docker', docker]
])
return resolve(utils)
})
})
}
function initScreens (utils) {
return new Promise((resolve, reject) => {
let screen
try {
screen = new Screen(utils)
screen.init()
} catch (err) {
return reject(err)
}
return resolve(screen)
})
}
function exitError (err) {
cli.showUsage()
if (err && err.message) {
console.log('\x1b[31m')
console.trace(err)
if (err.message === 'Unable to determine the domain name') {
console.log('-> check your connection options to the docker daemon and confirm containers exist')
}
console.log('\x1b[0m')
}
process.exit(-1)
}