@@ -49,7 +49,7 @@ import {
4949 isMain ,
5050 makeDirectory ,
5151 readFile ,
52- renameFile ,
52+ renameFileOrDirectory ,
5353 writeFile ,
5454} from "complete-node" ;
5555import { globSync } from "glob" ;
@@ -135,29 +135,29 @@ const BROKEN_LINK_DIR_NAMES = [
135135] as const ;
136136
137137if ( isMain ( ) ) {
138- main ( ) ;
138+ await main ( ) ;
139139}
140140
141- function main ( ) {
142- createCallbackFile ( ) ;
143- moveModulesFiles ( ) ;
144- deleteFileOrDirectory ( MODULES_MD_PATH ) ;
145- makeDirectory ( OTHER_DIR ) ;
146- makeDirectory ( FEATURES_DIR ) ;
147- addCategoryFilesAndMarkdownHeaders ( ) ;
148- moveDirsToOther ( ) ;
149- renameSpecialPages ( ) ;
150- deleteDuplicatedPages ( ) ;
151- renameDuplicatedPages ( ) ;
152- fixLinks ( ) ;
141+ async function main ( ) {
142+ await createCallbackFile ( ) ;
143+ await moveModulesFiles ( ) ;
144+ await deleteFileOrDirectory ( MODULES_MD_PATH ) ;
145+ await makeDirectory ( OTHER_DIR ) ;
146+ await makeDirectory ( FEATURES_DIR ) ;
147+ await addCategoryFilesAndMarkdownHeaders ( ) ;
148+ await moveDirsToOther ( ) ;
149+ await renameSpecialPages ( ) ;
150+ await deleteDuplicatedPages ( ) ;
151+ await renameDuplicatedPages ( ) ;
152+ await fixLinks ( ) ;
153153}
154154
155155/**
156156 * Custom callbacks are documented on the `ModCallbackCustom` enum, but we want custom callbacks to
157157 * be part of the root navigation layout. Thus, we create a new Markdown file from scratch to
158158 * represent this.
159159 */
160- function createCallbackFile ( ) {
160+ async function createCallbackFile ( ) {
161161 const filePath = path . join ( PACKAGE_DOCS_DIR , "extra-callbacks.md" ) ;
162162 const fileContent = `
163163---
@@ -172,11 +172,11 @@ See the [ModCallbackCustom](/isaacscript-common/other/enums/ModCallbackCustom) e
172172 `
173173 . trim ( )
174174 . concat ( "\n" ) ;
175- writeFile ( filePath , fileContent ) ;
175+ await writeFile ( filePath , fileContent ) ;
176176}
177177
178178/** Move the files in the "modules" directory to proper directories. */
179- function moveModulesFiles ( ) {
179+ async function moveModulesFiles ( ) {
180180 const markdownFileNames = getMarkdownFileNames ( MODULES_DIR ) ;
181181 for ( const markdownFileName of markdownFileNames ) {
182182 const markdownFilePath = path . join ( MODULES_DIR , markdownFileName ) ;
@@ -202,9 +202,11 @@ function moveModulesFiles() {
202202 ) ;
203203
204204 const dstDirectory = path . join ( PACKAGE_DOCS_DIR , directoryName ) ;
205- makeDirectory ( dstDirectory ) ;
205+ // eslint-disable-next-line no-await-in-loop
206+ await makeDirectory ( dstDirectory ) ;
206207 const dstPath = path . join ( dstDirectory , newFileName ) ;
207- renameFile ( markdownFilePath , dstPath ) ;
208+ // eslint-disable-next-line no-await-in-loop
209+ await renameFileOrDirectory ( markdownFilePath , dstPath ) ;
208210
209211 if ( DEBUG ) {
210212 echo ( `Moved:\n ${ markdownFilePath } \n -->\n ${ dstPath } ` ) ;
@@ -219,39 +221,43 @@ function moveModulesFiles() {
219221 ) ;
220222 }
221223
222- deleteFileOrDirectory ( MODULES_DIR ) ;
224+ await deleteFileOrDirectory ( MODULES_DIR ) ;
223225}
224226
225- function addCategoryFilesAndMarkdownHeaders ( ) {
227+ async function addCategoryFilesAndMarkdownHeaders ( ) {
226228 const directories = getDirectoryNames ( PACKAGE_DOCS_DIR ) ;
227229 for ( const directoryName of directories ) {
228230 const directoryPath = path . join ( PACKAGE_DOCS_DIR , directoryName ) ;
229231
230- addCategoryFile ( directoryPath ) ;
232+ // eslint-disable-next-line no-await-in-loop
233+ await addCategoryFile ( directoryPath ) ;
231234 const subDirectories = getDirectoryNames ( directoryPath ) ;
232235 for ( const subDirectoryName of subDirectories ) {
233236 const subDirectoryPath = path . join ( directoryPath , subDirectoryName ) ;
234- addCategoryFile ( subDirectoryPath ) ;
237+ // eslint-disable-next-line no-await-in-loop
238+ await addCategoryFile ( subDirectoryPath ) ;
235239 }
236240
237241 const markdownFileNames = getMarkdownFileNames ( directoryPath ) ;
238242 for ( const markdownFileName of markdownFileNames ) {
239243 const markdownFilePath = path . join ( directoryPath , markdownFileName ) ;
240- addMarkdownHeader ( markdownFilePath , directoryName ) ;
244+ // eslint-disable-next-line no-await-in-loop
245+ await addMarkdownHeader ( markdownFilePath , directoryName ) ;
241246 }
242247 }
243248}
244249
245250/** Move some specific directories to an "other" directory for better top-level organization. */
246- function moveDirsToOther ( ) {
251+ async function moveDirsToOther ( ) {
247252 for ( const otherDirName of OTHER_DIR_NAMES ) {
248253 const srcPath = path . join ( PACKAGE_DOCS_DIR , otherDirName ) ;
249254 const dstPath = path . join ( OTHER_DIR , otherDirName ) ;
250- renameFile ( srcPath , dstPath ) ;
255+ // eslint-disable-next-line no-await-in-loop
256+ await renameFileOrDirectory ( srcPath , dstPath ) ;
251257 }
252258}
253259
254- function addCategoryFile ( directoryPath : string ) {
260+ async function addCategoryFile ( directoryPath : string ) {
255261 const directoryName = path . basename ( directoryPath ) ;
256262 const categoryFilePath = path . join ( directoryPath , CATEGORY_FILE_NAME ) ;
257263
@@ -263,10 +269,10 @@ function addCategoryFile(directoryPath: string) {
263269 if ( position !== undefined ) {
264270 fileContents += `position: ${ position } \n` ;
265271 }
266- writeFile ( categoryFilePath , fileContents ) ;
272+ await writeFile ( categoryFilePath , fileContents ) ;
267273}
268274
269- function addMarkdownHeader ( filePath : string , directoryName : string ) {
275+ async function addMarkdownHeader ( filePath : string , directoryName : string ) {
270276 const title = getTitle ( filePath , directoryName ) ;
271277 const header = `
272278---
@@ -277,7 +283,7 @@ custom_edit_url: null
277283
278284` . trimStart ( ) ;
279285
280- let fileContents = readFile ( filePath ) ;
286+ let fileContents = await readFile ( filePath ) ;
281287
282288 // Remove the title generated by `typedoc-plugin-markdown`, which will be on the first line.
283289 const lines = fileContents . trim ( ) . split ( "\n" ) ;
@@ -295,7 +301,7 @@ custom_edit_url: null
295301 fileContents = lines . join ( "\n" ) ;
296302
297303 const newFileContents = header + fileContents ;
298- writeFile ( filePath , newFileContents ) ;
304+ await writeFile ( filePath , newFileContents ) ;
299305}
300306
301307function getTitle ( filePath : string , directoryName : string ) {
@@ -341,24 +347,24 @@ function getTitle(filePath: string, directoryName: string) {
341347 * Some pages are erroneously deleted by the `deleteDuplicatedPages`, so we must handle them
342348 * manually.
343349 */
344- function renameSpecialPages ( ) {
350+ async function renameSpecialPages ( ) {
345351 const oldPath = path . join (
346352 OTHER_DIR ,
347353 "classes" ,
348354 "features_other_extraConsoleCommands_commands.md" ,
349355 ) ;
350356 const newPath = path . join ( FEATURES_DIR , "ExtraConsoleCommandsList.md" ) ;
351- renameFile ( oldPath , newPath ) ;
357+ await renameFileOrDirectory ( oldPath , newPath ) ;
352358
353- const contents = readFile ( newPath ) ;
359+ const contents = await readFile ( newPath ) ;
354360 const newContents = contents . replace (
355361 "# features_other_extraConsoleCommands_commands" ,
356362 "# Extra Console Commands (List)" ,
357363 ) ;
358- writeFile ( newPath , newContents ) ;
364+ await writeFile ( newPath , newContents ) ;
359365}
360366
361- function deleteDuplicatedPages ( ) {
367+ async function deleteDuplicatedPages ( ) {
362368 for ( const directoryName of DIR_NAMES_WITH_SECOND_BREADCRUMBS_LINE ) {
363369 const directoryPath = path . join ( OTHER_DIR , directoryName ) ;
364370 const fileNames = getFileNames ( directoryPath ) ;
@@ -370,7 +376,8 @@ function deleteDuplicatedPages() {
370376
371377 if ( ! isValidDuplicate ( fileName , directoryName ) ) {
372378 const filePath = path . join ( directoryPath , fileName ) ;
373- deleteFileOrDirectory ( filePath ) ;
379+ // eslint-disable-next-line no-await-in-loop
380+ await deleteFileOrDirectory ( filePath ) ;
374381
375382 if ( DEBUG ) {
376383 echo ( `Deleted duplicate page:\n ${ filePath } ` ) ;
@@ -380,7 +387,7 @@ function deleteDuplicatedPages() {
380387 }
381388}
382389
383- function renameDuplicatedPages ( ) {
390+ async function renameDuplicatedPages ( ) {
384391 for ( const directoryName of DIR_NAMES_WITH_SECOND_BREADCRUMBS_LINE ) {
385392 const directoryPath = path . join ( OTHER_DIR , directoryName ) ;
386393 const fileNames = getFileNames ( directoryPath ) ;
@@ -415,7 +422,8 @@ function renameDuplicatedPages() {
415422 properPath = path . join ( FEATURES_DIR , properName ) ;
416423 }
417424
418- renameFile ( filePath , properPath ) ;
425+ // eslint-disable-next-line no-await-in-loop
426+ await renameFileOrDirectory ( filePath , properPath ) ;
419427
420428 if ( DEBUG ) {
421429 echo ( `Renamed:\n ${ filePath } \n -->\n ${ properPath } ` ) ;
@@ -432,12 +440,13 @@ function isValidDuplicate(fileName: string, directoryName: string) {
432440}
433441
434442/** Because we manually moved files around, internal links generated by TypeDoc will break. */
435- function fixLinks ( ) {
443+ async function fixLinks ( ) {
436444 const markdownFilePaths = globSync ( "**/*.md" , { cwd : PACKAGE_DOCS_DIR } ) ;
437445
438446 for ( const filePath of markdownFilePaths ) {
439447 const fullFilePath = path . join ( PACKAGE_DOCS_DIR , filePath ) ;
440- const fileContents = readFile ( fullFilePath ) ;
448+ // eslint-disable-next-line no-await-in-loop
449+ const fileContents = await readFile ( fullFilePath ) ;
441450 let newFileContents = fileContents ;
442451
443452 // Start by removing any links with a "modules" prefix, since they are moved to the root.
@@ -501,7 +510,8 @@ function fixLinks() {
501510 newFileContents = newFileContents . replaceAll ( / t y p e s _ \w + \. / gm, "" ) ;
502511
503512 if ( fileContents !== newFileContents ) {
504- writeFile ( fullFilePath , newFileContents ) ;
513+ // eslint-disable-next-line no-await-in-loop
514+ await writeFile ( fullFilePath , newFileContents ) ;
505515 }
506516 }
507517}
0 commit comments