Skip to content

Commit 19ee5b3

Browse files
authored
Merge pull request #49 from robotboy655/regression-fix2
Regression fixes
2 parents b443e9f + 58c5226 commit 19ee5b3

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/api-writer/glua-api-writer.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
4146
export 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) {

src/cli-scraper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ async function startScrape() {
9090
console.log('Scraping all pages...');
9191
let scrape_start = performance.now();
9292

93+
let cur = 0;
9394
let queue: Promise<any>[] = [];
9495
for (const pageIndex of pageIndexes) {
9596
const pageMarkupScraper = new WikiPageMarkupScraper(`${baseUrl}/${pageIndex.address}?format=text`);
9697

98+
const indexForThis = cur++;
9799
pageMarkupScraper.on('scraped', (url, pageMarkups) => {
98100
if (pageMarkups.length === 0)
99101
return;
@@ -118,7 +120,7 @@ async function startScrape() {
118120
const moduleFile = path.join(baseDirectory, moduleName);
119121

120122
// Write Lua API docs
121-
writer.writePages(pageMarkups, path.join(baseDirectory, `${moduleName}.lua`));
123+
writer.writePages(pageMarkups, path.join(baseDirectory, `${moduleName}.lua`), indexForThis);
122124

123125
// Write JSON data
124126
if (!fs.existsSync(moduleFile))

0 commit comments

Comments
 (0)