File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 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');
22const path = require ( 'path' ) ;
33const tools = require ( '../rustdoc-js-common/lib.js' ) ;
44
5+
56function findFile ( dir , name , extension ) {
67 var entries = fs . readdirSync ( dir ) ;
8+ var matches = [ ] ;
79 for ( var i = 0 ; i < entries . length ; ++ i ) {
810 var entry = entries [ i ] ;
911 var file_type = fs . statSync ( dir + entry ) ;
1012 if ( file_type . isDirectory ( ) ) {
1113 continue ;
1214 }
1315 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 ] ) ;
1527 }
1628 }
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 ] ;
1838}
1939
2040function readFileMatching ( dir , name , extension ) {
You can’t perform that action at this time.
0 commit comments