-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
49 lines (34 loc) · 1.49 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
const args = require('yargs')
.strict(true)
.option('variables', {
alias: 'v', describe: 'Set of variables passed to the visualization', type: 'array', default: []
})
.option('folders', {
alias: 'f', describe: 'Set the folders that will be mounted in the server', type: 'array', default: ['public']
})
.option('interactive', {
alias: 'i', describe: 'Set interactive mode', type: 'boolean', default: false
})
.option('localfileurls', {
alias: 'l', describe: 'Use local file urls', type: 'boolean', default: false
})
.option('port', {
alias: 'p', describe: 'Set port (>= 0 and < 65536)', type: 'number', default: 8080
})
.option('default', {
alias: 'd', describe: 'Set default visualization', type: 'string', default: 'default.html'
})
.check((arg) => {
if (!(Number.isInteger(arg.port) && arg.port >= 0 && arg.port < 65536)) {
throw new Error('The value specified is not a valid port');
}
if (arg.variables && arg.variables.some(variableValue => !variableValue.includes('='))) {
throw new Error('Variables must be defined as variable=value');
}
return true;
})
.showHelpOnFail(false, 'Specify --help for available options')
.help()
.argv;
const variables = args.variables ? Object.assign({}, ...args.variables.map(i => i.split('=')).map(i => ({ [i[0]]: i[1] }))) : {};
require('./server.js').VisualizationServer.initializeServer(args.port, args.interactive, args.default, args.folders, args.localfileurls, variables);