From 756c512c206d96f06a2abf4b79b65fd9634e4560 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Wed, 22 Sep 2021 02:33:20 +0200 Subject: [PATCH] ci: clean pack entries when generating packs or jsons --- gulpfile.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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",