Skip to content

Commit 30bf711

Browse files
committed
fix: lint
1 parent f668f30 commit 30bf711

29 files changed

+506
-424
lines changed

packages/docs/scripts/fixIsaacScriptCommon.mts

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
isMain,
5050
makeDirectory,
5151
readFile,
52-
renameFile,
52+
renameFileOrDirectory,
5353
writeFile,
5454
} from "complete-node";
5555
import { globSync } from "glob";
@@ -135,29 +135,29 @@ const BROKEN_LINK_DIR_NAMES = [
135135
] as const;
136136

137137
if (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

301307
function 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(/types_\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
}

packages/docs/scripts/fixIsaacTypeScriptDefinitions.mts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
deleteFileOrDirectory,
1111
isMain,
1212
readFile,
13-
renameFile,
13+
renameFileOrDirectory,
1414
writeFile,
1515
} from "complete-node";
1616
import fs from "node:fs";
@@ -47,35 +47,37 @@ const SIDEBAR_POSITIONS = new ReadonlyMap([
4747
]);
4848

4949
if (isMain()) {
50-
main();
50+
await main();
5151
}
5252

53-
function main() {
53+
async function main() {
5454
// Since we are only generating enums, there will be nothing in the module directory that we need,
5555
// so we can just delete it.
56-
deleteFileOrDirectory(MODULES_DIR);
57-
deleteFileOrDirectory(MODULES_MD_PATH);
56+
await deleteFileOrDirectory(MODULES_DIR);
57+
await deleteFileOrDirectory(MODULES_MD_PATH);
5858

59-
addCategoryFilesAndMarkdownHeaders();
60-
renameEnumFiles();
59+
await addCategoryFilesAndMarkdownHeaders();
60+
await renameEnumFiles();
6161
}
6262

63-
function addCategoryFilesAndMarkdownHeaders() {
63+
async function addCategoryFilesAndMarkdownHeaders() {
6464
// Do every subdirectory. (As of August 2022, it should only be the "enums" directory.)
6565
const directories = getDirectoryNames(PACKAGE_DOCS_DIR);
6666
for (const directoryName of directories) {
6767
const directoryPath = path.join(PACKAGE_DOCS_DIR, directoryName);
68-
addCategoryFile(directoryPath);
68+
// eslint-disable-next-line no-await-in-loop
69+
await addCategoryFile(directoryPath);
6970

7071
const markdownFileNames = getMarkdownFileNames(directoryPath);
7172
for (const markdownFileName of markdownFileNames) {
7273
const markdownFilePath = path.join(directoryPath, markdownFileName);
73-
addMarkdownHeader(markdownFilePath);
74+
// eslint-disable-next-line no-await-in-loop
75+
await addMarkdownHeader(markdownFilePath);
7476
}
7577
}
7678
}
7779

78-
function addCategoryFile(directoryPath: string) {
80+
async function addCategoryFile(directoryPath: string) {
7981
const directoryName = path.basename(directoryPath);
8082
const categoryFilePath = path.join(directoryPath, CATEGORY_FILE_NAME);
8183

@@ -86,10 +88,10 @@ function addCategoryFile(directoryPath: string) {
8688
if (position !== undefined) {
8789
fileContents += `position: ${position}\n`;
8890
}
89-
writeFile(categoryFilePath, fileContents);
91+
await writeFile(categoryFilePath, fileContents);
9092
}
9193

92-
function addMarkdownHeader(filePath: string) {
94+
async function addMarkdownHeader(filePath: string) {
9395
const title = getTitle(filePath);
9496
const header = `
9597
---
@@ -100,7 +102,7 @@ custom_edit_url: null
100102
101103
`.trimStart();
102104

103-
let fileContents = readFile(filePath);
105+
let fileContents = await readFile(filePath);
104106

105107
// Remove the title generated by `typedoc-plugin-markdown`, which will be on the first line.
106108
const lines = fileContents.trim().split("\n");
@@ -115,7 +117,7 @@ custom_edit_url: null
115117
fileContents = lines.join("\n");
116118

117119
const newFileContents = header + fileContents;
118-
writeFile(filePath, newFileContents);
120+
await writeFile(filePath, newFileContents);
119121
}
120122

121123
function getTitle(filePath: string) {
@@ -149,7 +151,7 @@ function getTitle(filePath: string) {
149151
* "collections_entityState.BigHornState.md". We want all of the enums to appear in the left-hand
150152
* sidebar in alphabetical order, so we want to rename everything to just be named after the enum.
151153
*/
152-
function renameEnumFiles() {
154+
async function renameEnumFiles() {
153155
const markdownFileNames = getMarkdownFileNames(ENUMS_DIR);
154156
for (const markdownFileName of markdownFileNames) {
155157
const markdownFilePath = path.join(ENUMS_DIR, markdownFileName);
@@ -167,7 +169,8 @@ function renameEnumFiles() {
167169
);
168170

169171
const dstPath = path.join(ENUMS_DIR, simplifiedFileName);
170-
renameFile(markdownFilePath, dstPath);
172+
// eslint-disable-next-line no-await-in-loop
173+
await renameFileOrDirectory(markdownFilePath, dstPath);
171174
}
172175
}
173176

0 commit comments

Comments
 (0)