@@ -38,12 +38,17 @@ export const RESERVERD_KEYWORDS = new Set([
3838 'while'
3939] ) ;
4040
41+ type IndexedWikiPage = {
42+ index : number ;
43+ page : WikiPage ;
44+ } ;
45+
4146export class GluaApiWriter {
4247 private readonly writtenClasses : Set < string > = new Set ( ) ;
4348 private readonly writtenLibraryGlobals : Set < string > = new Set ( ) ;
4449 private readonly pageOverrides : Map < string , string > = new Map ( ) ;
4550
46- private readonly files : Map < string , WikiPage [ ] > = new Map ( ) ;
51+ private readonly files : Map < string , IndexedWikiPage [ ] > = new Map ( ) ;
4752
4853 constructor ( ) { }
4954
@@ -274,32 +279,36 @@ export class GluaApiWriter {
274279 return api ;
275280 }
276281
277- public writePages ( pages : WikiPage [ ] , filePath : string ) {
282+ public writePages ( pages : WikiPage [ ] , filePath : string , index : number = 0 ) {
278283 if ( ! this . files . has ( filePath ) ) this . files . set ( filePath , [ ] ) ;
279- this . files . get ( filePath ) ! . push ( ...pages ) ;
284+
285+ pages . forEach ( page => {
286+ this . files . get ( filePath ) ! . push ( { index : index , page : page } ) ;
287+ } ) ;
280288 }
281289
282290 public getPages ( filePath : string ) {
283291 return this . files . get ( filePath ) ?? [ ] ;
284292 }
285293
286- public makeApiFromPages ( pages : WikiPage [ ] ) {
294+ public makeApiFromPages ( pages : IndexedWikiPage [ ] ) {
287295 let api = "" ;
288296
289- // First we write the "header" types
290- for ( const page of pages . filter ( x => isClass ( x ) || isLibrary ( x ) ) ) {
291- api += this . writePage ( page ) ;
292- }
297+ pages . sort ( ( a , b ) => a . index - b . index ) ;
293298
294- for ( const page of pages . filter ( x => ! isClass ( x ) && ! isLibrary ( x ) ) ) {
295- api += this . writePage ( page ) ;
296- }
299+ // First we write the "header" types
300+ for ( const page of pages . filter ( x => isClass ( x . page ) || isLibrary ( x . page ) || isPanel ( x . page ) ) ) {
301+ api += this . writePage ( page . page ) ;
302+ }
303+ for ( const page of pages . filter ( x => ! isClass ( x . page ) && ! isLibrary ( x . page ) && ! isPanel ( x . page ) ) ) {
304+ api += this . writePage ( page . page ) ;
305+ }
297306
298307 return api ;
299308 }
300309
301310 public writeToDisk ( ) {
302- this . files . forEach ( ( pages : WikiPage [ ] , filePath : string ) => {
311+ this . files . forEach ( ( pages : IndexedWikiPage [ ] , filePath : string ) => {
303312 let api = this . makeApiFromPages ( pages ) ;
304313
305314 if ( api . length > 0 ) {
0 commit comments