diff options
| author | Leonardo Bishop <me@leonardobishop.com> | 2024-03-13 19:33:33 +0000 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.com> | 2024-03-13 19:33:33 +0000 |
| commit | bd26b2800e2675613c6990673ad0b7b5175aa841 (patch) | |
| tree | 26d1a89d9ed60ad73a82fbe3371d8c58578702f5 /utils/zipExporter.ts | |
| parent | 825d2cadee4ddf34d0dde8c278fc8e8a99e95b95 (diff) | |
Add zip export
Diffstat (limited to 'utils/zipExporter.ts')
| -rw-r--r-- | utils/zipExporter.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/utils/zipExporter.ts b/utils/zipExporter.ts new file mode 100644 index 0000000..635e89d --- /dev/null +++ b/utils/zipExporter.ts @@ -0,0 +1,33 @@ +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)]))); + + return { + transformedQuests, + transformedItems, + transformedCategories + } +} + +export async function createZip(quests: { [key: string]: string }, categories: string, items: { [key: string]: string }) { + const zip = new JSZip(); + + zip.file("categories.yml", categories); + + const questsDirectory = zip.folder("quests"); + Object.entries(quests).forEach(([key, value]) => { + questsDirectory?.file(`${key}.yml`, value) + }) + const itemsDirectory = zip.folder("items"); + Object.entries(items).forEach(([key, value]) => { + itemsDirectory?.file(`${key}.yml`, value) + }) + + return await zip.generateAsync({ type: "blob" }); +}
\ No newline at end of file |
