|
1 |
| -const fs = require('fs'); |
| 1 | +const fs = require('fs') |
2 | 2 |
|
3 |
| -let usage = "node server.js"; |
| 3 | +let usage = 'node server.js' |
4 | 4 | if (/server$/.test(process.execPath)) {
|
5 | 5 | // Binary executable called.
|
6 |
| - usage = "server"; |
| 6 | + usage = 'server' |
7 | 7 | }
|
8 | 8 |
|
9 |
| -checkNodeJSVersion(); |
| 9 | +checkNodeJSVersion() |
10 | 10 |
|
11 |
| -module.exports.argv = readCommandLine(); |
| 11 | +module.exports.argv = readCommandLine() |
12 | 12 |
|
13 |
| -function readCommandLine() { |
14 |
| - |
15 |
| - let argv = require('yargs') |
| 13 | +function readCommandLine () { |
| 14 | + const argv = require('yargs') |
16 | 15 | .strict()
|
17 | 16 | .help()
|
18 | 17 | .option('file', {
|
19 |
| - 'description': 'Catalog configuration file or file pattern', |
20 |
| - 'type': 'string', |
21 |
| - 'default': require("path").normalize(__dirname + '/../metadata/TestData2.0.json'), |
22 |
| - 'alias': 'f' |
| 18 | + description: 'Catalog configuration file or file pattern', |
| 19 | + type: 'string', |
| 20 | + default: require('path').normalize(__dirname + '/../metadata/TestData2.0.json'), |
| 21 | + alias: 'f' |
23 | 22 | })
|
24 | 23 | .option('port', {
|
25 |
| - 'description': 'Server port', |
26 |
| - 'default': 8999, |
27 |
| - 'type': 'number', |
28 |
| - 'alias': 'p' |
| 24 | + description: 'Server port', |
| 25 | + default: 8999, |
| 26 | + type: 'number', |
| 27 | + alias: 'p' |
29 | 28 | })
|
30 | 29 | .option('conf', {
|
31 |
| - 'description': 'Server configuration file', |
32 |
| - 'default': require("path").normalize(__dirname + '/../conf/server.json'), |
33 |
| - 'type': 'string', |
34 |
| - 'alias': 'c' |
| 30 | + description: 'Server configuration file', |
| 31 | + default: require('path').normalize(__dirname + '/../conf/server.json'), |
| 32 | + type: 'string', |
| 33 | + alias: 'c' |
35 | 34 | })
|
36 | 35 | .option('force', {
|
37 |
| - 'description': 'Start server even if test or metadata generation fails.', |
38 |
| - 'type': 'boolean', |
39 |
| - 'alias': 'i' |
| 36 | + description: 'Start server even if test or metadata generation fails.', |
| 37 | + type: 'boolean', |
| 38 | + alias: 'i' |
40 | 39 | })
|
41 | 40 | .option('ignore', {
|
42 |
| - 'description': 'Start server even if metadata validation errors', |
43 |
| - 'type': 'boolean', |
44 |
| - 'alias': 'i' |
| 41 | + description: 'Start server even if metadata validation errors', |
| 42 | + type: 'boolean', |
| 43 | + alias: 'i' |
45 | 44 | })
|
46 | 45 | .option('skipchecks', {
|
47 |
| - 'description': 'Skip startup metadata validation and command line tests', |
48 |
| - 'default': false, |
49 |
| - 'type': 'boolean', |
50 |
| - 'alias': 's' |
| 46 | + description: 'Skip startup metadata validation and command line tests', |
| 47 | + default: false, |
| 48 | + type: 'boolean', |
| 49 | + alias: 's' |
51 | 50 | })
|
52 | 51 | .option('logdir', {
|
53 |
| - 'description': 'Log directory', |
54 |
| - 'default': require("path").normalize(__dirname + "/../log"), |
55 |
| - 'type': 'string', |
56 |
| - 'alias': 'l' |
| 52 | + description: 'Log directory', |
| 53 | + default: require('path').normalize(__dirname + '/../log'), |
| 54 | + type: 'string', |
| 55 | + alias: 'l' |
57 | 56 | })
|
58 | 57 | .option('open', {
|
59 |
| - 'description': 'Open web page on start', |
60 |
| - 'default': false, |
61 |
| - 'type': 'boolean', |
62 |
| - 'alias': 'o' |
| 58 | + description: 'Open web page on start', |
| 59 | + default: false, |
| 60 | + type: 'boolean', |
| 61 | + alias: 'o' |
63 | 62 | })
|
64 | 63 | .option('test', {
|
65 |
| - 'description': 'Run URL tests and exit', |
66 |
| - 'default': false, |
67 |
| - 'type': 'boolean', |
68 |
| - 'alias': 't' |
| 64 | + description: 'Run URL tests and exit', |
| 65 | + default: false, |
| 66 | + type: 'boolean', |
| 67 | + alias: 't' |
69 | 68 | })
|
70 | 69 | .option('verify', {
|
71 |
| - 'description': 'Run verification tests on command line and exit', |
72 |
| - 'default': false, |
73 |
| - 'type': 'boolean' |
| 70 | + description: 'Run verification tests on command line and exit', |
| 71 | + default: false, |
| 72 | + type: 'boolean' |
74 | 73 | })
|
75 | 74 | .option('loglevel', {
|
76 |
| - 'description': 'none, info, or debug', |
77 |
| - 'default': 'info', |
78 |
| - 'type': 'string' |
| 75 | + description: 'none, info, or debug', |
| 76 | + default: 'info', |
| 77 | + type: 'string' |
79 | 78 | })
|
80 | 79 | .option('debug', {
|
81 |
| - 'description': "set loglevel to 'debug'", |
82 |
| - 'default': false, |
83 |
| - 'type': 'boolean' |
| 80 | + description: "set loglevel to 'debug'", |
| 81 | + default: false, |
| 82 | + type: 'boolean' |
84 | 83 | })
|
85 | 84 | .option('server-ui-include', {
|
86 |
| - 'description': 'Also include these servers in server-ui server drop-down. Use multiple times for more than one list.', |
87 |
| - 'default': null, |
88 |
| - 'type': 'string' |
| 85 | + description: 'Also include these servers in server-ui server drop-down. Use multiple times for more than one list.', |
| 86 | + default: null, |
| 87 | + type: 'string' |
89 | 88 | })
|
90 | 89 | .option('proxy-whitelist', {
|
91 |
| - 'description': 'Allow proxying of servers in this file (so one can use server=http://... in address bar of server-ui).', |
92 |
| - 'default': '', |
93 |
| - 'type': 'string' |
| 90 | + description: 'Allow proxying of servers in this file (so one can use server=http://... in address bar of server-ui).', |
| 91 | + default: '', |
| 92 | + type: 'string' |
94 | 93 | })
|
95 | 94 | .option('verifier', {
|
96 |
| - 'description': 'Verifier server URL on landing page (__VERIFIER__ in html is replaced with this value)', |
97 |
| - 'default': 'http://hapi-server.org/verify/', |
98 |
| - 'type': 'string' |
| 95 | + description: 'Verifier server URL on landing page (__VERIFIER__ in html is replaced with this value)', |
| 96 | + default: 'http://hapi-server.org/verify/', |
| 97 | + type: 'string' |
99 | 98 | })
|
100 | 99 | .option('plotserver', {
|
101 |
| - 'description': 'Plot server URL on landing page (__PLOTSERVER__ in html is replaced with this value)', |
102 |
| - 'default': 'http://hapi-server.org/plot/', |
103 |
| - 'type': 'string' |
| 100 | + description: 'Plot server URL on landing page (__PLOTSERVER__ in html is replaced with this value)', |
| 101 | + default: 'http://hapi-server.org/plot/', |
| 102 | + type: 'string' |
104 | 103 | })
|
105 | 104 | .option('hapiserverpath', {
|
106 |
| - 'description': 'Absolute path to use for $HAPISERVERPATH in server metadata files', |
107 |
| - 'default': require("path").normalize(__dirname + "/.."), |
108 |
| - 'type': 'string' |
| 105 | + description: 'Absolute path to use for $HAPISERVERPATH in server metadata files', |
| 106 | + default: require('path').normalize(__dirname + '/..'), |
| 107 | + type: 'string' |
109 | 108 | })
|
110 | 109 | .option('nodejs', {
|
111 |
| - 'description': 'Location of NodeJS binary to use for $NODEJSEXE in server metadata files (if needed for command line calls).', |
112 |
| - 'default': process.execPath, |
113 |
| - 'type': 'string' |
| 110 | + description: 'Location of NodeJS binary to use for $NODEJSEXE in server metadata files (if needed for command line calls).', |
| 111 | + default: process.execPath, |
| 112 | + type: 'string' |
114 | 113 | })
|
115 | 114 | .option('python', {
|
116 |
| - 'description': 'Location of Python binary to use for $PYTHONEXE in server metadata files (if needed for command line calls).', |
117 |
| - 'type': 'string' |
| 115 | + description: 'Location of Python binary to use for $PYTHONEXE in server metadata files (if needed for command line calls).', |
| 116 | + type: 'string' |
118 | 117 | })
|
119 | 118 | .option('https', {
|
120 |
| - 'description': 'Start https server', |
121 |
| - 'type': 'boolean' |
| 119 | + description: 'Start https server', |
| 120 | + type: 'boolean' |
122 | 121 | })
|
123 | 122 | .option('cert', {
|
124 |
| - 'description': 'https certificate file path', |
125 |
| - 'type': 'string' |
| 123 | + description: 'https certificate file path', |
| 124 | + type: 'string' |
126 | 125 | })
|
127 | 126 | .option('key', {
|
128 |
| - 'description': 'https key file path', |
129 |
| - 'type': 'string' |
| 127 | + description: 'https key file path', |
| 128 | + type: 'string' |
130 | 129 | })
|
131 |
| - .epilog("For more details, see README at https://github.com/hapi-server/server-nodejs/") |
| 130 | + .epilog('For more details, see README at https://github.com/hapi-server/server-nodejs/') |
132 | 131 | .usage('Usage: ' + usage + ' [options]')
|
133 |
| - .argv; |
| 132 | + .argv |
134 | 133 |
|
135 |
| - if (typeof(argv.file) == 'string') { |
136 |
| - argv.file = [argv.file]; |
| 134 | + if (typeof (argv.file) === 'string') { |
| 135 | + argv.file = [argv.file] |
137 | 136 | }
|
138 | 137 |
|
139 | 138 | // TODO: yargs does not allow specifying that no option can be repeated with
|
140 | 139 | // some exception. https://github.com/yargs/yargs/issues/1318
|
141 | 140 | // So a check should be made here.
|
142 | 141 |
|
143 |
| - if (argv["debug"] === true) { |
144 |
| - argv["loglevel"] = "debug"; |
145 |
| - delete argv["debug"]; |
| 142 | + if (argv.debug === true) { |
| 143 | + argv.loglevel = 'debug' |
| 144 | + delete argv.debug |
146 | 145 | }
|
147 | 146 |
|
148 |
| - if (argv["proxy-whitelist"] !== '') { |
149 |
| - if (!fs.existsSync(argv["proxy-whitelist"])) { |
150 |
| - console.error("Error: --proxy-whitelist file '" + argv["proxy-whitelist"] + "' does not exist."); |
151 |
| - process.exit(1); |
| 147 | + if (argv['proxy-whitelist'] !== '') { |
| 148 | + if (!fs.existsSync(argv['proxy-whitelist'])) { |
| 149 | + console.error("Error: --proxy-whitelist file '" + argv['proxy-whitelist'] + "' does not exist.") |
| 150 | + process.exit(1) |
152 | 151 | }
|
153 | 152 | }
|
154 | 153 |
|
155 |
| - if (typeof argv["server-ui-include"] === 'string') { |
156 |
| - if (argv["server-ui-include"].trim() === '') { |
157 |
| - console.error("Error: --server-ui-include must be followed by a non-empty string."); |
158 |
| - process.exit(0); |
| 154 | + if (typeof argv['server-ui-include'] === 'string') { |
| 155 | + if (argv['server-ui-include'].trim() === '') { |
| 156 | + console.error('Error: --server-ui-include must be followed by a non-empty string.') |
| 157 | + process.exit(0) |
159 | 158 | }
|
160 |
| - argv["server-ui-include"] = [argv["server-ui-include"]]; |
| 159 | + argv['server-ui-include'] = [argv['server-ui-include']] |
161 | 160 | }
|
162 | 161 |
|
163 |
| - return argv; |
| 162 | + return argv |
164 | 163 | }
|
165 | 164 |
|
166 |
| -function checkNodeJSVersion() { |
167 |
| - const semver = require('semver'); |
168 |
| - const versionConstraint = require("../package.json").engines.node; |
| 165 | +function checkNodeJSVersion () { |
| 166 | + const semver = require('semver') |
| 167 | + const versionConstraint = require('../package.json').engines.node |
169 | 168 | if (!semver.satisfies(process.version, versionConstraint)) {
|
170 |
| - let msg = `Error: Node.js semantic version constraint ${versionConstraint} ` |
171 |
| - + `not satisfied. node.js -v returns ${process.version}. ` |
172 |
| - + "Consider installing https://github.com/creationix/nvm" |
173 |
| - + ` and then 'nvm install VERSION', where VERSION satisfies constraint.\n`; |
174 |
| - console.log(msg); |
175 |
| - process.exit(1); |
| 169 | + const msg = `Error: Node.js semantic version constraint ${versionConstraint} ` + |
| 170 | + `not satisfied. node.js -v returns ${process.version}. ` + |
| 171 | + 'Consider installing https://github.com/creationix/nvm' + |
| 172 | + ' and then \'nvm install VERSION\', where VERSION satisfies constraint.\n' |
| 173 | + console.log(msg) |
| 174 | + process.exit(1) |
176 | 175 | }
|
177 | 176 | }
|
0 commit comments