File tree 1 file changed +22
-2
lines changed
1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -2,19 +2,39 @@ const fs = require('fs');
2
2
const path = require ( 'path' ) ;
3
3
const tools = require ( '../rustdoc-js-common/lib.js' ) ;
4
4
5
+
5
6
function findFile ( dir , name , extension ) {
6
7
var entries = fs . readdirSync ( dir ) ;
8
+ var matches = [ ] ;
7
9
for ( var i = 0 ; i < entries . length ; ++ i ) {
8
10
var entry = entries [ i ] ;
9
11
var file_type = fs . statSync ( dir + entry ) ;
10
12
if ( file_type . isDirectory ( ) ) {
11
13
continue ;
12
14
}
13
15
if ( entry . startsWith ( name ) && entry . endsWith ( extension ) ) {
14
- return entry ;
16
+ var version = entry . slice ( name . length , entry . length - extension . length ) ;
17
+ version = version . split ( "." ) . map ( function ( x ) {
18
+ return parseInt ( x ) ;
19
+ } ) ;
20
+ var total = 0 ;
21
+ var mult = 1 ;
22
+ for ( var j = version . length - 1 ; j >= 0 ; -- j ) {
23
+ total += version [ j ] * mult ;
24
+ mult *= 1000 ;
25
+ }
26
+ matches . push ( [ entry , total ] ) ;
15
27
}
16
28
}
17
- return null ;
29
+ if ( matches . length === 0 ) {
30
+ return null ;
31
+ }
32
+ // We make a reverse sort to have the "highest" file. Very useful in case you didn't clean up
33
+ // you std doc folder...
34
+ matches . sort ( function ( a , b ) {
35
+ return b [ 1 ] - a [ 1 ] ;
36
+ } ) ;
37
+ return matches [ 0 ] [ 0 ] ;
18
38
}
19
39
20
40
function readFileMatching ( dir , name , extension ) {
You can’t perform that action at this time.
0 commit comments