Skip to content

Commit 5a0f5bc

Browse files
committed
standard.js
1 parent ad3b459 commit 5a0f5bc

13 files changed

+1661
-1733
lines changed

lib/cli.js

+102-103
Original file line numberDiff line numberDiff line change
@@ -1,177 +1,176 @@
1-
const fs = require('fs');
1+
const fs = require('fs')
22

3-
let usage = "node server.js";
3+
let usage = 'node server.js'
44
if (/server$/.test(process.execPath)) {
55
// Binary executable called.
6-
usage = "server";
6+
usage = 'server'
77
}
88

9-
checkNodeJSVersion();
9+
checkNodeJSVersion()
1010

11-
module.exports.argv = readCommandLine();
11+
module.exports.argv = readCommandLine()
1212

13-
function readCommandLine() {
14-
15-
let argv = require('yargs')
13+
function readCommandLine () {
14+
const argv = require('yargs')
1615
.strict()
1716
.help()
1817
.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'
2322
})
2423
.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'
2928
})
3029
.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'
3534
})
3635
.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'
4039
})
4140
.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'
4544
})
4645
.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'
5150
})
5251
.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'
5756
})
5857
.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'
6362
})
6463
.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'
6968
})
7069
.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'
7473
})
7574
.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'
7978
})
8079
.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'
8483
})
8584
.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'
8988
})
9089
.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'
9493
})
9594
.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'
9998
})
10099
.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'
104103
})
105104
.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'
109108
})
110109
.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'
114113
})
115114
.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'
118117
})
119118
.option('https', {
120-
'description': 'Start https server',
121-
'type': 'boolean'
119+
description: 'Start https server',
120+
type: 'boolean'
122121
})
123122
.option('cert', {
124-
'description': 'https certificate file path',
125-
'type': 'string'
123+
description: 'https certificate file path',
124+
type: 'string'
126125
})
127126
.option('key', {
128-
'description': 'https key file path',
129-
'type': 'string'
127+
description: 'https key file path',
128+
type: 'string'
130129
})
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/')
132131
.usage('Usage: ' + usage + ' [options]')
133-
.argv;
132+
.argv
134133

135-
if (typeof(argv.file) == 'string') {
136-
argv.file = [argv.file];
134+
if (typeof (argv.file) === 'string') {
135+
argv.file = [argv.file]
137136
}
138137

139138
// TODO: yargs does not allow specifying that no option can be repeated with
140139
// some exception. https://github.com/yargs/yargs/issues/1318
141140
// So a check should be made here.
142141

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
146145
}
147146

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)
152151
}
153152
}
154153

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)
159158
}
160-
argv["server-ui-include"] = [argv["server-ui-include"]];
159+
argv['server-ui-include'] = [argv['server-ui-include']]
161160
}
162161

163-
return argv;
162+
return argv
164163
}
165164

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
169168
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)
176175
}
177176
}

0 commit comments

Comments
 (0)