ci: clean pack entries when generating packs or jsons

This commit is contained in:
Johannes Loher 2021-09-22 02:33:20 +02:00
parent 675922ad98
commit 756c512c20

View file

@ -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",