ci: clean pack entries when generating packs or jsons
This commit is contained in:
parent
675922ad98
commit
756c512c20
1 changed files with 30 additions and 1 deletions
31
gulpfile.js
31
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",
|
||||
|
|
Loading…
Reference in a new issue