From bb35d0d6e7bf057513c497acd4d966041ad2cdac Mon Sep 17 00:00:00 2001 From: macniel Date: Sat, 1 Nov 2025 11:08:29 +0100 Subject: [PATCH] fixes asynchronous error with a pinky promise --- gulpfile.mjs | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/gulpfile.mjs b/gulpfile.mjs index dc7cd172..b0acfe63 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -46,8 +46,7 @@ function randomID(reference = "", length = 16) { }); } -const convert = async function (from, to, ofType, overwrite = true) { - +const convert = function (from, to, ofType, overwrite = true) { const SOURCE = from; const DEST = to; const TYPE = ofType; @@ -60,6 +59,8 @@ const convert = async function (from, to, ofType, overwrite = true) { mkdirSync(DEST) } + let promises = [] + const filewalker = async (source) => { console.debug("entering directory", source); for (let file of readdirSync(source)) { @@ -68,25 +69,31 @@ const convert = async function (from, to, ofType, overwrite = true) { } else { console.debug("processing file", join(source, file)) let originalSource = JSON.parse(readFileSync(join(source, file), {encoding: "utf8"})); - let id = await randomID("DSA_4-1" + TYPE + originalSource.name.trim()) + promises.push(new Promise((resolve2) => { + randomID("DSA_4-1" + TYPE + originalSource.name.trim()).then(id => { + let targetSource = { + _id: id, + _key: "!items!" + id, + type: TYPE, + img: originalSource.image, + name: originalSource.name.trim(), + system: {...originalSource}, + } + delete targetSource.system.image; + let target = JSON.stringify(targetSource, null, 2); + let newFileName = "./" + join(DEST, id + ".json"); + writeFileSync(newFileName, target, {encoding: "utf8"}); + resolve2() + }) - let targetSource = { - _id: id, - _key: "!items!" + id, - type: TYPE, - img: originalSource.image, - name: originalSource.name.trim(), - system: {...originalSource}, - } - delete targetSource.system.image; - let target = JSON.stringify(targetSource, null, 2); - let newFileName = "./" + join(DEST, id + ".json"); - writeFileSync(newFileName, target, {encoding: "utf8"}); - } + })) } + } } - return await filewalker(SOURCE) + filewalker(SOURCE) + + return Promise.allSettled(promises) } function cleanDist() {