-
Notifications
You must be signed in to change notification settings - Fork 28
/
config.js
95 lines (85 loc) · 3.5 KB
/
config.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
'use strict';
const path = require('path')
const fs = require('fs')
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
const configFile = path.resolve(__dirname, '..', '.config')
var ask = prompt => {
return new Promise(resolve => {
rl.question(prompt + ' ', res => resolve(res))
})
}
var demand = (prompt, validate) => {
return new Promise(resolve => {
rl.question(prompt + ' ', res => {
if (res != '') {
if (!validate) resolve(res)
else {
if (validate.test(res)) resolve(res)
else demand(prompt, validate).then(res => resolve(res))
}
} else demand(prompt, validate).then(res => resolve(res))
})
})
}
var saveOpts = (opts, callback) => {
fs.writeFile(configFile, JSON.stringify(opts, null, 2), callback)
}
var startConfig = () => {
var opts = {}
ask('Mongo host? (localhost)').then(res => {
opts.mongoHost = res || 'localhost'
}).then(() => ask('Mongo port? (27017)')).then(res => {
opts.mongoPort = res || 27017
}).then(() => ask('Mongo username? (none)')).then(res => {
opts.mongoUsername = res || ''
}).then(() => ask('Mongo password? (none)')).then(res => {
opts.mongoPassword = res || ''
}).then(() => ask('Mongo auth DB? (admin)')).then(res => {
opts.mongoAuthDB = res || 'admin'
}).then(() => {
console.log('')
console.log('Now we\'ll configure Chromecast integration.')
}).then(() => demand('Application ID?')).then(res => {
opts.appId = res
}).then(() => {
console.log('')
console.log('Does this look right?')
console.log('')
console.log(opts)
console.log('')
}).then(() => demand('(y/N)', /[yn]/i)).then(res => {
if(/y/i.test(res)) {
saveOpts(opts, () => {
console.log('')
console.log('Configuration updated! To get started, just run\n' +
'\n' +
' multicast start'
'\n')
})
rl.close()
} else {
console.log('')
console.log('Alright, let\'s start over.')
console.log('')
startConfig()
}
})
}
/* Let's get started! */
/* credit to ASCII art goes to patorjk.com/software/taag/ */
console.log('')
console.log(' W E L C O M E T O')
console.log(`
███╗ ███╗██╗ ██╗██╗ ████████╗██╗ ██████╗ █████╗ ███████╗████████╗
████╗ ████║██║ ██║██║ ╚══██╔══╝██║██╔════╝██╔══██╗██╔════╝╚══██╔══╝
██╔████╔██║██║ ██║██║ ██║ ██║██║ ███████║███████╗ ██║
██║╚██╔╝██║██║ ██║██║ ██║ ██║██║ ██╔══██║╚════██║ ██║
██║ ╚═╝ ██║╚██████╔╝███████╗██║ ██║╚██████╗██║ ██║███████║ ██║
╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═╝ `)
console.log('')
console.log('We\'ll start off by configuring database options. Just press [ENTER] after each.')
startConfig()