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 | |
| parent | 1dd5d0fa8bb2ae794b263d1629a662166a9b9d08 (diff) | |
Fix eslint errors
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/loader.ts | 91 | ||||
| -rw-r--r-- | utils/util.ts | 27 | ||||
| -rw-r--r-- | utils/zipExporter.ts | 58 |
3 files changed, 103 insertions, 73 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 +} diff --git a/utils/util.ts b/utils/util.ts index 273191a..f5f7247 100644 --- a/utils/util.ts +++ b/utils/util.ts @@ -1,31 +1,34 @@ -const COLOR_CODE_REGEX = /&([0-9a-fk-or]|#[0-9A-F]{6})/ig; +const COLOR_CODE_REGEX = /&([0-9a-fk-or]|#[0-9A-F]{6})/gi; export function stripColorCodes(str: string): string { return str.replace(COLOR_CODE_REGEX, ''); } -export function navigateToEditorPane(type: 'quest' | 'category' | 'item' | 'config' | null, id?: string) { +export function navigateToEditorPane( + type: 'quest' | 'category' | 'item' | 'config' | null, + id?: string +) { if (id) { if (type === 'category') { - navigateTo({ path: '/editor/category/' + id }) + navigateTo({ path: '/editor/category/' + id }); } else if (type === 'quest') { - navigateTo({ path: '/editor/quest/' + id }) + navigateTo({ path: '/editor/quest/' + id }); } else if (type === 'item') { - navigateTo({ path: '/editor/item/' + id }) + navigateTo({ path: '/editor/item/' + id }); } } else if (type === 'config') { - navigateTo({ path: '/editor/config' }) + navigateTo({ path: '/editor/config' }); } else if (!id && !type) { - navigateTo({ path: '/editor' }) + navigateTo({ path: '/editor' }); } } export type BrowserCapabilities = { - canUseFsApi: boolean -} + canUseFsApi: boolean; +}; export function getBrowserCapabilities(): BrowserCapabilities { return { - canUseFsApi: typeof (window as any)?.showDirectoryPicker === 'function' - } -}
\ No newline at end of file + canUseFsApi: typeof (window as any)?.showDirectoryPicker === 'function', + }; +} diff --git a/utils/zipExporter.ts b/utils/zipExporter.ts index 635e89d..3aff4b3 100644 --- a/utils/zipExporter.ts +++ b/utils/zipExporter.ts @@ -1,33 +1,53 @@ -import JSZip from "jszip"; -import { stringify } from "yaml"; -import { mapJsonCategoryToYamlObject, mapJsonItemToYamlObject, mapJsonQuestToYamlObject } from "~/lib/questsLoader"; +import JSZip from 'jszip'; +import { stringify } from 'yaml'; +import { + mapJsonCategoryToYamlObject, + mapJsonItemToYamlObject, + mapJsonQuestToYamlObject, +} from '~/lib/questsLoader'; //TODO include the main configuration -export async function prepareZip(quests: EditorQuest[], categories: EditorCategory[], items: EditorItem[]) { - const transformedQuests = Object.fromEntries(quests.map((quest) => [quest.id, stringify(mapJsonQuestToYamlObject(quest))])); - const transformedItems = Object.fromEntries(items.map((item) => [item.id, stringify(mapJsonItemToYamlObject(item))])); - const transformedCategories = stringify(Object.fromEntries(categories.map((category) => [category.id, mapJsonCategoryToYamlObject(category)]))); +export async function prepareZip( + quests: EditorQuest[], + categories: EditorCategory[], + items: EditorItem[] +) { + const transformedQuests = Object.fromEntries( + quests.map((quest) => [quest.id, stringify(mapJsonQuestToYamlObject(quest))]) + ); + const transformedItems = Object.fromEntries( + items.map((item) => [item.id, stringify(mapJsonItemToYamlObject(item))]) + ); + const transformedCategories = stringify( + Object.fromEntries( + categories.map((category) => [category.id, mapJsonCategoryToYamlObject(category)]) + ) + ); return { transformedQuests, transformedItems, - transformedCategories - } + transformedCategories, + }; } -export async function createZip(quests: { [key: string]: string }, categories: string, items: { [key: string]: string }) { +export async function createZip( + quests: { [key: string]: string }, + categories: string, + items: { [key: string]: string } +) { const zip = new JSZip(); - zip.file("categories.yml", categories); + zip.file('categories.yml', categories); - const questsDirectory = zip.folder("quests"); + const questsDirectory = zip.folder('quests'); Object.entries(quests).forEach(([key, value]) => { - questsDirectory?.file(`${key}.yml`, value) - }) - const itemsDirectory = zip.folder("items"); + questsDirectory?.file(`${key}.yml`, value); + }); + const itemsDirectory = zip.folder('items'); Object.entries(items).forEach(([key, value]) => { - itemsDirectory?.file(`${key}.yml`, value) - }) + itemsDirectory?.file(`${key}.yml`, value); + }); - return await zip.generateAsync({ type: "blob" }); -}
\ No newline at end of file + return await zip.generateAsync({ type: 'blob' }); +} |
