fixes asynchronous error with a pinky promise
parent
7476c55e63
commit
bb35d0d6e7
17
gulpfile.mjs
17
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,8 +69,8 @@ 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,
|
||||
|
|
@ -82,11 +83,17 @@ const convert = async function (from, to, ofType, overwrite = true) {
|
|||
let target = JSON.stringify(targetSource, null, 2);
|
||||
let newFileName = "./" + join(DEST, id + ".json");
|
||||
writeFileSync(newFileName, target, {encoding: "utf8"});
|
||||
resolve2()
|
||||
})
|
||||
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return await filewalker(SOURCE)
|
||||
filewalker(SOURCE)
|
||||
|
||||
return Promise.allSettled(promises)
|
||||
}
|
||||
|
||||
function cleanDist() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue