-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.js
executable file
·108 lines (89 loc) · 2.31 KB
/
cli.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
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env node
var fs = require('fs')
var path = require('path')
var startServer = require('./lib/server')
var pkgUp = require('pkg-up')
var args = require('minimist')(process.argv.slice(2), {
alias: {
s: 'plotly-src',
v: 'version',
l: 'latest',
r: 'remote-mocks',
h: 'help',
m: 'mapbox-access-token',
k: 'keep-meta',
j: 'mathjax',
d: 'mock-dir',
p: 'plotly-dir',
t: 'remote-topojson'
},
boolean: [
'remote-mocks',
'keep-meta',
'remote-topojson'
]
})
if (args.help) {
process.stdout.write(fs.readFileSync(path.join(__dirname, 'lib/help.txt'), 'utf8'))
process.exit(0)
}
function printError (message) {
console.log('plotly-mock-viewer: Error: ' + message)
}
function printWarning (message) {
console.log('plotly-mock-viewer: Warning: ' + message)
}
var opts = {
isCDN: false,
title: '@dev'
}
if (args.version) {
opts.plotlySrc = 'https://cdn.plot.ly/plotly-' + args.version + '.js'
opts.isCDN = true
opts.title = '@' + args.version
console.log('plotly-mock-viewer: using CDN version of plotly ' + opts.plotlySrc)
}
if (args.latest) {
opts.plotlySrc = 'https://cdn.plot.ly/plotly-latest.js'
opts.isCDN = true
opts.title = '@latest'
console.log('plotly-mock-viewer: using CDN version of plotly ' + opts.plotlySrc)
}
if (args['plotly-src']) {
opts.plotlySrc = args['plotly-src'];
opts.isCDN = false;
opts.title = '@dev';
consoe.log('plotly-mock-viewer: using local bunbled plotly.js: ' + opts.plotlySrc);
}
if (args['remote-mocks']) {
opts.remoteMocks = true
}
if (args['remote-topojson']) {
opts.remoteTopojson = true
}
if (args['mapbox-access-token']) {
opts.mapboxAccessToken = args['mapbox-access-token']
}
if (args['mock-dir']) {
opts.mockPath = args['mock-dir']
}
if (args._[0]) {
opts.mockPath = path.dirname(args._[0]);
opts.initialMock = path.basename(args._[0]);
}
if (args.mathjax) {
opts.mathjax = true
}
opts.keepMeta = args['keep-meta']
var plotlyPkg
if (args['plotly-dir']) {
plotlyPkg = path.join(args['plotly-dir'], 'package.json')
} else {
plotlyPkg = pkgUp.sync()
}
var pkg = JSON.parse(fs.readFileSync(plotlyPkg, 'utf8'))
opts.plotlyPath = path.dirname(plotlyPkg)
if (!pkg || pkg.name !== 'plotly.js') {
opts.plotlyPath = path.join(path.dirname(require.resolve('plotly.js')), '../')
}
startServer(opts)