@@ -104,7 +104,7 @@ function prepmetadata (FILES, FORCE, IGNORE, SKIP_CHECKS, cb) {
104
104
105
105
if ( json . data . file ) {
106
106
json . data . file = conf . replaceConfigVars ( json . data . file )
107
- if ( / \$ { / . test ( json . data . file ) == false && ! fs . existsSync ( json . data . file ) ) {
107
+ if ( / \$ { / . test ( json . data . file ) === false && ! fs . existsSync ( json . data . file ) ) {
108
108
const msg = json . data . file + ' referenced in ' + catalogid + ' not found.'
109
109
log . error ( msg , true )
110
110
}
@@ -121,15 +121,15 @@ function prepmetadata (FILES, FORCE, IGNORE, SKIP_CHECKS, cb) {
121
121
122
122
jsonWarn ( formats , catalogid )
123
123
124
- const update_seconds = json . server [ 'catalog-update' ]
125
- if ( update_seconds ) {
126
- if ( ! Number . isInteger ( update_seconds ) ) {
124
+ const updateSeconds = json . server [ 'catalog-update' ]
125
+ if ( updateSeconds ) {
126
+ if ( ! Number . isInteger ( updateSeconds ) ) {
127
127
log . error ( serverfile + ' has a non-integer value for server.catalog-update.' , true )
128
128
}
129
- if ( update_seconds < 0 ) {
129
+ if ( updateSeconds < 0 ) {
130
130
log . error ( serverfile + ' has a negative value for server.catalog-update.' , true )
131
131
}
132
- log . info ( 'Updating ' + catalogid + ' every ' + update_seconds + ' seconds.' )
132
+ log . info ( 'Updating ' + catalogid + ' every ' + updateSeconds + ' seconds.' )
133
133
setInterval ( ( ) => {
134
134
updatemetadata ( FORCE , IGNORE , SKIP_CHECKS , json , ( e ) => {
135
135
const catalogid = json . server . id
@@ -141,7 +141,7 @@ function prepmetadata (FILES, FORCE, IGNORE, SKIP_CHECKS, cb) {
141
141
log . info ( 'Updated ' + catalogid )
142
142
}
143
143
} )
144
- } , update_seconds * 1000 )
144
+ } , updateSeconds * 1000 )
145
145
}
146
146
147
147
updatemetadata ( FORCE , IGNORE , SKIP_CHECKS , json , ( err ) => {
@@ -205,26 +205,26 @@ function updatemetadata (FORCE, IGNORE, SKIP_CHECKS, json, cb) {
205
205
}
206
206
} )
207
207
208
- function createcat ( ds_num , xcatalog ) {
208
+ function createcat ( dsNumber , xcatalog ) {
209
209
// Each element of xcatalog is a dataset
210
210
// Resolve info nodes and checks catalog and info.
211
211
212
- if ( ! xcatalog [ ds_num ] ) {
213
- const msg = `Dataset number ${ ds_num } does not have an id element.`
212
+ if ( ! xcatalog [ dsNumber ] ) {
213
+ const msg = `Dataset number ${ dsNumber } does not have an id element.`
214
214
log . error ( msg , true )
215
215
}
216
216
217
- const id = xcatalog [ ds_num ] . id
217
+ const id = xcatalog [ dsNumber ] . id
218
218
219
- if ( ds_num == 0 ) {
219
+ if ( dsNumber = == 0 ) {
220
220
log . info ( `Reading, parsing, and resolving metadata for ${ catalogid } ` )
221
221
}
222
222
223
223
metadata . newcache [ catalogid ] . ids . push ( id )
224
224
225
- catalog . catalog [ ds_num ] = xcatalog [ ds_num ]
225
+ catalog . catalog [ dsNumber ] = xcatalog [ dsNumber ]
226
226
227
- getmetadata ( xcatalog [ ds_num ] , 'info' , FORCE , ( e , info ) => {
227
+ getmetadata ( xcatalog [ dsNumber ] , 'info' , FORCE , ( e , info ) => {
228
228
if ( e ) {
229
229
log . error ( e , ! FORCE )
230
230
if ( FORCE ) cb ( e )
@@ -235,33 +235,33 @@ function updatemetadata (FORCE, IGNORE, SKIP_CHECKS, json, cb) {
235
235
236
236
function checkinfo ( info ) {
237
237
for ( const infoType of [ 'info' , 'info_inline' , 'info_url' , 'info_file' , 'info_command' ] ) {
238
- delete catalog . catalog [ ds_num ] [ infoType ]
238
+ delete catalog . catalog [ dsNumber ] [ infoType ]
239
239
}
240
240
241
241
info = JSON . parse ( JSON . stringify ( info ) )
242
242
info . HAPI = json . server . HAPI
243
243
info . status = json . status
244
244
245
245
// Resolve JSON refs in info.
246
- const info_resolved = resolveJSONRefs ( JSON . parse ( JSON . stringify ( info ) ) )
247
- if ( SKIP_CHECKS == false ) {
246
+ const infoResolved = resolveJSONRefs ( JSON . parse ( JSON . stringify ( info ) ) )
247
+ if ( SKIP_CHECKS === false ) {
248
248
// log.info("Checking schema validity of /info response metadata for " + id);
249
- validHAPIJSON ( info_resolved , info . HAPI , 'info' , IGNORE , xcatalog [ ds_num ] . id )
249
+ validHAPIJSON ( infoResolved , info . HAPI , 'info' , IGNORE , xcatalog [ dsNumber ] . id )
250
250
// log.info("Checked schema validity of /info response metadata for " + id);
251
251
}
252
- delete info_resolved . definitions
253
- metadata . newcache [ catalogid ] . info [ id ] = info_resolved
252
+ delete infoResolved . definitions
253
+ metadata . newcache [ catalogid ] . info [ id ] = infoResolved
254
254
metadata . newcache [ catalogid ] [ 'info-raw' ] [ id ] = info
255
255
256
- if ( ds_num < xcatalog . length - 1 ) {
257
- createcat ( ++ ds_num , xcatalog )
256
+ if ( dsNumber < xcatalog . length - 1 ) {
257
+ createcat ( ++ dsNumber , xcatalog )
258
258
} else {
259
259
checkcat ( )
260
260
}
261
261
}
262
262
263
263
function checkcat ( ) {
264
- if ( SKIP_CHECKS == false ) {
264
+ if ( SKIP_CHECKS === false ) {
265
265
log . info ( 'Checking schema validity of /catalog response metadata for ' + catalogid )
266
266
validHAPIJSON ( catalog , json . server . HAPI , 'catalog' , IGNORE )
267
267
// log.info("Checked schema validity of /catalog response metadata for " + catalogid);
@@ -296,7 +296,7 @@ function getmetadata (obj, nodeType, FORCE, cb) {
296
296
getone ( 0 )
297
297
298
298
function getone ( i ) {
299
- if ( i == catalog . length ) {
299
+ if ( i === catalog . length ) {
300
300
cb ( null , catalog )
301
301
return
302
302
}
@@ -358,15 +358,15 @@ function getmetadata (obj, nodeType, FORCE, cb) {
358
358
}
359
359
360
360
const type = metadataType ( obj , nodeType )
361
- if ( type == 'inline' ) {
361
+ if ( type === 'inline' ) {
362
362
// obj is inline JSON.
363
363
cb ( null , obj [ nodeType + '_' + type ] )
364
364
return
365
365
}
366
366
367
367
if ( type === undefined ) {
368
368
const msg = `No '${ nodeType } _{file,url,command,inline}', or '${ nodeType } ' node found.`
369
- log . error ( msg , rue )
369
+ log . error ( msg , true )
370
370
}
371
371
372
372
let nodeStr = ''
@@ -423,7 +423,7 @@ function getmetadata (obj, nodeType, FORCE, cb) {
423
423
} else if ( type === 'command' ) {
424
424
nodeStr = nodeStr . trim ( )
425
425
log . info ( 'Executing: ' + nodeStr )
426
- const eopts = { cwd : __dirname + '/ ..', maxBuffer : 100000000 }
426
+ const eopts = { cwd : path . join ( __dirname , ' ..') , maxBuffer : 100000000 }
427
427
require ( 'child_process' ) . exec ( nodeStr , eopts , ( e , info ) => {
428
428
if ( e ) {
429
429
log . error ( e . message . replace ( / \n $ / , '' ) . replace ( '\n' , '\n ' ) , ! FORCE )
@@ -444,7 +444,7 @@ function getmetadata (obj, nodeType, FORCE, cb) {
444
444
// Otherwise, attempt to read as a file.
445
445
log . info ( `'${ nodeType } ' is ambiguious. It could be a file or command. Attempting to evaluate as a command.` )
446
446
log . info ( `Attempting to execute '${ nodeStr } '` )
447
- const eopts = { cwd : __dirname + '/ ..', maxBuffer : 100000000 }
447
+ const eopts = { cwd : path . join ( __dirname , ' ..') , maxBuffer : 100000000 }
448
448
require ( 'child_process' ) . exec ( nodeStr , eopts , ( e , info ) => {
449
449
if ( ! e ) {
450
450
try {
@@ -467,15 +467,17 @@ function readCatalogConfig (file) {
467
467
process . exit ( 1 )
468
468
}
469
469
470
+ let fileStr
470
471
log . info ( 'Start reading, parsing, and resolving ' + trimPath ( file ) )
471
472
try {
472
- var str = fs . readFileSync ( file )
473
+ fileStr = fs . readFileSync ( file )
473
474
} catch ( ex ) {
474
475
log . error ( file + ' is not readable: ' + ex . message , true )
475
476
}
476
477
478
+ let json
477
479
try {
478
- var json = JSON . parse ( str )
480
+ json = JSON . parse ( fileStr )
479
481
} catch ( ex ) {
480
482
const msg = file + ' is not JSON parse-able. Try https://jsonlint.com/. Message: ' + ex . message
481
483
log . error ( msg , true )
@@ -561,8 +563,9 @@ function landing (json, serverfile, catalogid, IGNORE) {
561
563
}
562
564
563
565
if ( landingFile === '' && landingPath === '' ) {
564
- landingFile = path . normalize ( __dirname + '/../node_modules/hapi-server-ui/single.htm' )
565
- landingPath = path . normalize ( __dirname + '/../node_modules/hapi-server-ui/' )
566
+ const uiDir = path . join ( __dirname , '..' , 'node_modules' , 'hapi-server-ui' )
567
+ landingFile = path . normalize ( path . join ( uiDir , 'single.htm' ) )
568
+ landingPath = path . normalize ( uiDir )
566
569
log . info ( 'No landingFile or landingPath given in' )
567
570
log . info ( ` ${ trimPath ( serverfile ) } ` )
568
571
log . info ( ' Will use' )
@@ -673,15 +676,15 @@ function resolveJSONRefs (obj) {
673
676
const collectIds = function ( obj ) {
674
677
if ( ! obj ) { return }
675
678
if ( typeof ( obj ) === 'object' ) {
676
- if ( obj . hasOwnProperty ( '$ref' ) ) {
679
+ if ( Object . prototype . hasOwnProperty . call ( obj , '$ref' ) ) {
677
680
// Remove #/definitions/ from $ref
678
681
const name = obj . $ref . replace ( / .* \/ / , '' )
679
682
hashOfObjects [ obj . $ref ] = definitions [ name ]
680
683
}
681
684
for ( const prop in obj ) {
682
685
collectIds ( obj [ prop ] )
683
686
}
684
- } else if ( typeof ( obj ) === 'array' ) {
687
+ } else if ( Array . isArray ( obj ) ) {
685
688
obj . forEach ( function ( element ) {
686
689
collectIds ( element )
687
690
} )
@@ -692,7 +695,7 @@ function resolveJSONRefs (obj) {
692
695
if ( ! obj ) { return }
693
696
if ( typeof ( obj ) === 'object' ) {
694
697
for ( const prop in obj ) {
695
- if ( obj [ prop ] && typeof ( obj [ prop ] ) === 'object' && obj [ prop ] . hasOwnProperty ( '$ref' ) ) {
698
+ if ( obj [ prop ] && typeof ( obj [ prop ] ) === 'object' && Object . prototype . hasOwnProperty . call ( obj [ prop ] , '$ref' ) ) {
696
699
obj [ prop ] = hashOfObjects [ obj [ prop ] . $ref ]
697
700
} else {
698
701
setReferences ( obj [ prop ] )
@@ -701,7 +704,7 @@ function resolveJSONRefs (obj) {
701
704
} else if ( Array . isArray ( obj ) ) {
702
705
obj . forEach ( function ( element , index , array ) {
703
706
if ( element && typeof ( element ) === 'object' &&
704
- element . hasOwnProperty ( '$ref' ) ) {
707
+ Object . prototype . hasOwnProperty . call ( element , '$ref' ) ) {
705
708
array [ index ] = hashOfObjects [ element . $ref ]
706
709
} else {
707
710
setReferences ( element )
0 commit comments