Skip to content

Commit 8065cbe

Browse files
arbronFyorl
authored andcommitted
[#69] Add item type to extracted adventure document names
When unpacking using the `expandAdventures` option but not the `folders` option, this appends the item type to the name to prevent conflicts caused by two documents of different types that share the same name and ID. This does not make the change when the `folders` option is used because documents of different types are split into their own folders so there is no conflict risk. This causes the file names of extracted documents to change: ``` // Original Aarakocra_toaAarakocra0000.yml // New Aarakocra_Actor_toaAarakocra0000.yml ``` Closes #69
1 parent 023e0d1 commit 8065cbe

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

lib/package.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ export const TYPE_COLLECTION_MAP = {
207207
User: "users"
208208
};
209209

210+
/**
211+
* A mapping of collection names to primary document types.
212+
* @type {Record<DocumentCollection, DocumentType>}
213+
*/
214+
export const COLLECTION_TYPE_MAP = Object.fromEntries(Object.entries(TYPE_COLLECTION_MAP).map(([k, v]) => [v, k]));
215+
210216
/* -------------------------------------------- */
211217
/* Compiling */
212218
/* -------------------------------------------- */
@@ -595,6 +601,7 @@ async function extractAdventure(doc, dest, { folderMap }={}, {
595601
// Write all documents contained in the adventure
596602
for ( const embeddedCollectionName of ADVENTURE_DOCS ) {
597603
const paths = [];
604+
const typeSuffix = folders ? "" : `_${COLLECTION_TYPE_MAP[embeddedCollectionName]}`;
598605
for ( const embeddedDoc of doc[embeddedCollectionName] ?? [] ) {
599606
if ( await transformEntry?.(embeddedDoc, context) === false ) continue;
600607
let embeddedFolder = path.join(adventureFolder ?? "", embeddedFolderMap.get(embeddedDoc.folder)?.path ?? "");
@@ -605,7 +612,7 @@ async function extractAdventure(doc, dest, { folderMap }={}, {
605612
embeddedFolder = adventureFolder;
606613
embeddedName = path.join(embeddedFolderMap.get(embeddedDoc._id).path, `_Folder.${yaml ? "yml" : "json"}`);
607614
} else {
608-
embeddedName = `${name ? `${getSafeFilename(name)}_${id}` : doc._id}.${yaml ? "yml" : "json"}`;
615+
embeddedName = `${name ? `${getSafeFilename(name)}${typeSuffix}_${id}` : doc._id}.${yaml ? "yml" : "json"}`;
609616
}
610617
if ( embeddedFolder ) embeddedName = path.join(embeddedFolder, embeddedName);
611618
}

0 commit comments

Comments
 (0)