fixes asynchronous error with a pinky promise
parent
7476c55e63
commit
bb35d0d6e7
41
gulpfile.mjs
41
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 SOURCE = from;
|
||||||
const DEST = to;
|
const DEST = to;
|
||||||
const TYPE = ofType;
|
const TYPE = ofType;
|
||||||
|
|
@ -60,6 +59,8 @@ const convert = async function (from, to, ofType, overwrite = true) {
|
||||||
mkdirSync(DEST)
|
mkdirSync(DEST)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let promises = []
|
||||||
|
|
||||||
const filewalker = async (source) => {
|
const filewalker = async (source) => {
|
||||||
console.debug("entering directory", source);
|
console.debug("entering directory", source);
|
||||||
for (let file of readdirSync(source)) {
|
for (let file of readdirSync(source)) {
|
||||||
|
|
@ -68,25 +69,31 @@ const convert = async function (from, to, ofType, overwrite = true) {
|
||||||
} else {
|
} else {
|
||||||
console.debug("processing file", join(source, file))
|
console.debug("processing file", join(source, file))
|
||||||
let originalSource = JSON.parse(readFileSync(join(source, file), {encoding: "utf8"}));
|
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() {
|
function cleanDist() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue