I've created a script that loops through a bunch of folders and processes them each in to webpack bundles. This works great, except that I can't figure out why the Promise
around the loop isn't resolving.
Some things I've tried:
- If I put a
console.log("hello world")
just beforeresolve()
, within the} else { ... }
, it outputs the log. - If I move
resolve()
out of the} else { ... }
, it resolves, but the rest of my gulp task doesn't continue (separate, but related, issue).
I would appreciate some help in figuring this out. Most relevant chunk of code is below, the rest of it's at the link below.
// process all the script folders
const process_script_folders = () => {
return new Promise((resolve) => {
const FOLDER = script_folders.shift();
// lint all scripts, except for critical
if (FOLDER !== "critical") {
const linted = lint_scripts(js_directory, FOLDER + ".js", source_directory + "/" + FOLDER + "/**/*");
merged_streams.add(linted);
}
process_scripts(js_directory, FOLDER + ".js", source_directory + "/" + FOLDER + "/**/*").then((processed) => {
merged_streams.add(processed);
if (script_folders.length > 0) {
process_script_folders();
} else {
// @TODO figure out why this isn't resolving
resolve();
}
});
});
};
return process_script_folders().then(() => {
// ... do stuff
console.log("Testing"); // currently never output
});