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