-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
executable file
·59 lines (52 loc) · 1.63 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
'use strict'
const Config = require('./src/config.js')
const Server = require('./src/server')
const URL = require('url-parse')
const config = Config.config();
const defaults= {
'clean-db': true,
db: 'mongodb://localhost:27017/vapor_master',
ROS_MASTER_URI: 'http://localhost:11311'
}
if(config.read('help') || config.read('h')){
console.log(`Usage vapor-master`)
console.log(`\t`, `--clean-db`)
console.log(`\t`, `--no-clean-db`)
console.log(`\t`, `--db=[mongo-uri]`)
console.log(`\t`, `--dboptions=[mongo-options]`)
console.log(`\t`, `--ROS_MASTER_URI=[ros-master-uri]`)
console.log(`\t`, `--no-shutdown`)
process.exit(0)
}
let options = config.readAll() || {};
delete options._
delete options['$0']
if (options['no-clean-db'] || options['no-clean-db'] === false){
if(!options['clean-db'] && options['clean-db'] !== false ){
options['clean-db'] = !options['no-clean-db'];
}
delete options['no-clean-db']
}
if (Object.keys(options).length == 0){
options = defaults
} else {
if (!options.hasOwnProperty('ROS_MASTER_URI') || options.ROS_MASTER_URI === ''){
options.ROS_MASTER_URI = defaults.ROS_MASTER_URI
}
if (!options.hasOwnProperty('clean-db')){
options['clean-db'] = defaults['clean-db']
}
if (!options.hasOwnProperty('db')){
options.db = defaults.db
}
}
let printoptions = Object.assign({},options)
delete printoptions.dboptions;
const dbUri = new URL(printoptions.db);
delete printoptions.db;
printoptions.dbHost = dbUri.host
printoptions.dbName = dbUri.pathname
console.log("Vapor Master launching\nConfiguration: ")
console.log(printoptions)
let server = new Server(options)
server.start(false)