@@ -224,7 +224,7 @@ function loadMainJsAndIndex(mainJs, aliases, searchIndex, crate) {
224
224
}
225
225
searchIndex . pop ( ) ;
226
226
searchIndex = loadContent ( searchIndex . join ( "\n" ) + '\nexports.searchIndex = searchIndex;' ) ;
227
- finalJS = "" ;
227
+ var finalJS = "" ;
228
228
229
229
var arraysToLoad = [ "itemTypes" ] ;
230
230
var variablesToLoad = [ "MAX_LEV_DISTANCE" , "MAX_RESULTS" , "NO_TYPE_FILTER" ,
@@ -306,52 +306,53 @@ function runChecks(testFile, loaded, index) {
306
306
return errors ;
307
307
}
308
308
309
- function load_files ( doc_folder , version , crate ) {
310
- var mainJs = readFile ( doc_folder + "/main" + version + ".js" ) ;
311
- var aliases = readFile ( doc_folder + "/aliases" + version + ".js" ) ;
312
- var searchIndex = readFile ( doc_folder + "/search-index" + version + ".js" ) . split ( "\n" ) ;
309
+ function load_files ( doc_folder , resource_suffix , crate ) {
310
+ var mainJs = readFile ( path . join ( doc_folder , "main" + resource_suffix + ".js" ) ) ;
311
+ var aliases = readFile ( path . join ( doc_folder , "aliases" + resource_suffix + ".js" ) ) ;
312
+ var searchIndex = readFile (
313
+ path . join ( doc_folder , "search-index" + resource_suffix + ".js" ) ) . split ( "\n" ) ;
313
314
314
315
return loadMainJsAndIndex ( mainJs , aliases , searchIndex , crate ) ;
315
316
}
316
317
317
318
function showHelp ( ) {
318
319
console . log ( "rustdoc-js options:" ) ;
319
- console . log ( " --doc-folder [PATH] : location of the generated doc folder" ) ;
320
- console . log ( " --help : show this message then quit" ) ;
321
- console . log ( " --std : to run std tests " ) ;
322
- console . log ( " --test-file [PATH]: location of the JS test file" ) ;
323
- console . log ( " --test-folder [PATH]: location of the JS tests folder" ) ;
324
- console . log ( " --version [STRING] : version used when generating docs (used to get js files) " ) ;
320
+ console . log ( " --doc-folder [PATH] : location of the generated doc folder" ) ;
321
+ console . log ( " --help : show this message then quit" ) ;
322
+ console . log ( " --crate-name [STRING] : crate name to be used " ) ;
323
+ console . log ( " --test-file [PATH] : location of the JS test file" ) ;
324
+ console . log ( " --test-folder [PATH] : location of the JS tests folder" ) ;
325
+ console . log ( " --resource-suffix [STRING] : suffix to refer to the correct files" ) ;
325
326
}
326
327
327
328
function parseOptions ( args ) {
328
329
var opts = {
329
- "is_std " : false ,
330
- "version " : "" ,
330
+ "crate_name " : "" ,
331
+ "resource_suffix " : "" ,
331
332
"doc_folder" : "" ,
332
333
"test_folder" : "" ,
333
334
"test_file" : "" ,
334
335
} ;
335
336
var correspondances = {
336
- "--version " : "version " ,
337
+ "--resource-suffix " : "resource_suffix " ,
337
338
"--doc-folder" : "doc_folder" ,
338
339
"--test-folder" : "test_folder" ,
339
340
"--test-file" : "test_file" ,
341
+ "--crate-name" : "crate_name" ,
340
342
} ;
341
343
342
344
for ( var i = 0 ; i < args . length ; ++ i ) {
343
- if ( args [ i ] === "--version "
345
+ if ( args [ i ] === "--resource-suffix "
344
346
|| args [ i ] === "--doc-folder"
345
347
|| args [ i ] === "--test-folder"
346
- || args [ i ] === "--test-file" ) {
348
+ || args [ i ] === "--test-file"
349
+ || args [ i ] === "--crate-name" ) {
347
350
i += 1 ;
348
351
if ( i >= args . length ) {
349
352
console . error ( "Missing argument after `" + args [ i - 1 ] + "` option." ) ;
350
353
return null ;
351
354
}
352
355
opts [ correspondances [ args [ i - 1 ] ] ] = args [ i ] ;
353
- } else if ( args [ i ] === "--std" ) {
354
- opts [ "is_std" ] = true ;
355
356
} else if ( args [ i ] === "--help" ) {
356
357
showHelp ( ) ;
357
358
process . exit ( 0 ) ;
@@ -363,28 +364,20 @@ function parseOptions(args) {
363
364
}
364
365
if ( opts [ "doc_folder" ] . length < 1 ) {
365
366
console . error ( "Missing `--doc-folder` option." ) ;
366
- return null ;
367
+ } else if ( opts [ "crate_name" ] . length < 1 ) {
368
+ console . error ( "Missing `--crate-name` option." ) ;
367
369
} else if ( opts [ "test_folder" ] . length < 1 && opts [ "test_file" ] . length < 1 ) {
368
370
console . error ( "At least one of `--test-folder` or `--test-file` option is required." ) ;
369
- return null ;
370
- } else if ( opts [ "is_std" ] === true && opts [ "test_file" ] . length !== 0 ) {
371
- console . error ( "`--std` and `--test-file` options can't be used at the same time." )
371
+ } else {
372
+ return opts ;
372
373
}
373
- return opts ;
374
+ return null ;
374
375
}
375
376
376
- function checkFile ( test_file , opts , std_loaded , std_index ) {
377
+ function checkFile ( test_file , opts , loaded , index ) {
377
378
const test_name = path . basename ( test_file , ".js" ) ;
378
379
379
380
process . stdout . write ( 'Checking "' + test_name + '" ... ' ) ;
380
-
381
- var loaded = std_loaded ;
382
- var index = std_index ;
383
- if ( opts [ "is_std" ] !== true ) {
384
- var tmp = load_files ( path . join ( opts [ "doc_folder" ] , test_name ) , opts [ "version" ] , test_name ) ;
385
- loaded = tmp [ 0 ] ;
386
- index = tmp [ 1 ] ;
387
- }
388
381
return runChecks ( test_file , loaded , index ) ;
389
382
}
390
383
@@ -394,25 +387,21 @@ function main(argv) {
394
387
return 1 ;
395
388
}
396
389
397
- var std_loaded = null ;
398
- var std_index = null ;
399
- if ( opts [ "is_std" ] === true ) {
400
- var tmp = load_files ( opts [ "doc_folder" ] , opts [ "version" ] , "std" ) ;
401
- std_loaded = tmp [ 0 ] ;
402
- std_index = tmp [ 1 ] ;
403
- }
404
-
390
+ var [ loaded , index ] = load_files (
391
+ opts [ "doc_folder" ] ,
392
+ opts [ "resource_suffix" ] ,
393
+ opts [ "crate_name" ] ) ;
405
394
var errors = 0 ;
406
395
407
396
if ( opts [ "test_file" ] . length !== 0 ) {
408
- errors += checkFile ( opts [ "test_file" ] , opts , null , null ) ;
397
+ errors += checkFile ( opts [ "test_file" ] , opts , loaded , index ) ;
409
398
}
410
399
if ( opts [ "test_folder" ] . length !== 0 ) {
411
400
fs . readdirSync ( opts [ "test_folder" ] ) . forEach ( function ( file ) {
412
401
if ( ! file . endsWith ( ".js" ) ) {
413
402
return ;
414
403
}
415
- errors += checkFile ( path . join ( opts [ "test_folder" ] , file ) , opts , std_loaded , std_index ) ;
404
+ errors += checkFile ( path . join ( opts [ "test_folder" ] , file ) , opts , loaded , index ) ;
416
405
} ) ;
417
406
}
418
407
return errors > 0 ? 1 : 0 ;
0 commit comments