diff --git a/gulpfile.js b/gulpfile.js index 1c9a2e74..9682be33 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -51,6 +51,34 @@ function buildStyles() { .pipe(gulp.dest(path.join(distDirectory, "css"))); } +/** + * Remove unwanted data from a pack entry + */ +function cleanPackEntry(entry, cleanSourceId = true) { + if (cleanSourceId) { + delete entry.flags?.core?.sourceId; + } + if (entry.permission) entry.permission = { default: 0 }; + + const embeddedDocumentCollections = [ + "drawings", + "effects", + "items", + "lights", + "notes", + "results", + "sounds", + "templates", + "tiles", + "tokens", + "walls", + ]; + embeddedDocumentCollections + .flatMap((embeddedDocumentCollection) => entry[embeddedDocumentCollection] ?? []) + .forEach((embeddedEntry) => cleanPackEntry(embeddedEntry, false)); + return entry; +} + /** * Convert a stream of JSON files to NeDB files */ @@ -60,6 +88,7 @@ const jsonToNeDB = () => try { file.contents = Buffer.from( JSON.parse(file.contents.toString()) + .map(cleanPackEntry) .map((entry) => JSON.stringify(entry)) .join("\n") + "\n", ); @@ -97,7 +126,7 @@ const neDBToJSON = () => if (err) { callback(err); } else { - file.contents = Buffer.from(JSON.stringify(docs, undefined, 4) + "\n"); + file.contents = Buffer.from(JSON.stringify(docs.map(cleanPackEntry), undefined, 4) + "\n"); file.path = path.join( path.dirname(file.path), path.basename(file.path, path.extname(file.path)) + ".json",