diff options
| author | Leonardo Bishop <me@leonardobishop.com> | 2024-03-15 00:13:40 +0000 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.com> | 2024-03-15 00:13:40 +0000 |
| commit | c9aefa81ca1950121d2357fc66afe15eb400f537 (patch) | |
| tree | fd6196b55626cea8101cd5a4a00cb2a00d8a495b /utils/loader.ts | |
| parent | 1dd5d0fa8bb2ae794b263d1629a662166a9b9d08 (diff) | |
Fix eslint errors
Diffstat (limited to 'utils/loader.ts')
| -rw-r--r-- | utils/loader.ts | 91 |
1 files changed, 49 insertions, 42 deletions
diff --git a/utils/loader.ts b/utils/loader.ts index 56e29fa..adfa40f 100644 --- a/utils/loader.ts +++ b/utils/loader.ts @@ -1,5 +1,5 @@ -import { parse } from "yaml"; -import { loadCategoriesFromJson, loadItemsFromJson, loadQuestsFromJson } from "~/lib/questsLoader"; +import { parse } from 'yaml'; +import { loadCategoriesFromJson, loadItemsFromJson, loadQuestsFromJson } from '~/lib/questsLoader'; export async function openFileSystem() { try { @@ -31,50 +31,57 @@ export async function enumerateQuestDirectory(dirHandle: any) { throw Error('invalid quest directory'); } - const [questFiles, itemFiles] = await Promise.all([questsDirectory ? listAllFilesAndDirs(questsDirectory) : [], itemsDirectory ? listAllFilesAndDirs(itemsDirectory) : []]); - const [categories, quests, items] = await Promise.all([(async () => { - if (!categoryFile) { - return []; - } + const [questFiles, itemFiles] = await Promise.all([ + questsDirectory ? listAllFilesAndDirs(questsDirectory) : [], + itemsDirectory ? listAllFilesAndDirs(itemsDirectory) : [], + ]); + const [categories, quests, items] = await Promise.all([ + (async () => { + if (!categoryFile) { + return []; + } - const file: any = await categoryFile.getFile(); - const text: string = await file.text(); - const parsedYaml: any = parse(text); + const file: any = await categoryFile.getFile(); + const text: string = await file.text(); + const parsedYaml: any = parse(text); - return loadCategoriesFromJson(parsedYaml.categories); - })(), - (async () => { - if (!questFiles) { - return []; - } + return loadCategoriesFromJson(parsedYaml.categories); + })(), + (async () => { + if (!questFiles) { + return []; + } - const allQuests = await Promise.all(questFiles.filter(({ name, handle, kind }) => name.endsWith('.yml')).map(async ({ name, handle, kind }) => { - const file: any = await handle.getFile(); - const text: string = await file.text(); - return [ - name.replace('.yml', ''), - parse(text) - ]; - })) + const allQuests = await Promise.all( + questFiles + .filter(({ name, handle, kind }) => name.endsWith('.yml')) + .map(async ({ name, handle, kind }) => { + const file: any = await handle.getFile(); + const text: string = await file.text(); + return [name.replace('.yml', ''), parse(text)]; + }) + ); - return loadQuestsFromJson(Object.fromEntries(allQuests)); - })(), - (async () => { - if (!itemFiles) { - return []; - } + return loadQuestsFromJson(Object.fromEntries(allQuests)); + })(), + (async () => { + if (!itemFiles) { + return []; + } - const allItems = await Promise.all(itemFiles.filter(({ name, handle, kind }) => name.endsWith('.yml')).map(async ({ name, handle, kind }) => { - const file: any = await handle.getFile(); - const text: string = await file.text(); - return [ - name.replace('.yml', ''), - parse(text) - ]; - })) + const allItems = await Promise.all( + itemFiles + .filter(({ name, handle, kind }) => name.endsWith('.yml')) + .map(async ({ name, handle, kind }) => { + const file: any = await handle.getFile(); + const text: string = await file.text(); + return [name.replace('.yml', ''), parse(text)]; + }) + ); - return loadItemsFromJson(Object.fromEntries(allItems)); - })()]); + return loadItemsFromJson(Object.fromEntries(allItems)); + })(), + ]); return { categories, quests, items }; } @@ -84,10 +91,10 @@ async function listAllFilesAndDirs(dirHandle: any): Promise<any[]> { for await (const [name, handle] of dirHandle) { const { kind } = handle; if (handle.kind === 'directory') { - files.push(...await listAllFilesAndDirs(handle)); + files.push(...(await listAllFilesAndDirs(handle))); } else { files.push({ name, handle, kind }); } } return files; -}
\ No newline at end of file +} |
