fixes asynchronous error

pull/64/head
macniel 2025-11-01 10:58:44 +01:00
parent 5b46f36c58
commit 7476c55e63
1 changed files with 6 additions and 8 deletions

View File

@ -60,15 +60,15 @@ const convert = async function (from, to, ofType, overwrite = true) {
mkdirSync(DEST)
}
const filewalker = (source) => {
const filewalker = async (source) => {
console.debug("entering directory", source);
readdirSync(source).forEach(file => {
for (let file of readdirSync(source)) {
if (statSync(join(source, file)).isDirectory()) {
filewalker(join(source, file));
await filewalker(join(source, file));
} else {
console.debug("processing file", join(source, file))
let originalSource = JSON.parse(readFileSync(join(source, file), {encoding: "utf8"}));
randomID("DSA_4-1" + TYPE + originalSource.name.trim()).then(id => {
let id = await randomID("DSA_4-1" + TYPE + originalSource.name.trim())
let targetSource = {
_id: id,
@ -82,13 +82,11 @@ 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"});
})
}
});
}
}
filewalker(SOURCE)
return await filewalker(SOURCE)
}
function cleanDist() {