Having trouble understanding why the 'describeDir' promise chain is not working properly. Can anyone help me figure out what I did wrong here? Everything in the code seems to run, but functions like then or finally from the promise API never get executed. Below are two of the main functions. You can find the code repository on Github at https://github.com/PhoenixContactUSA/pcworx-doc-gen
function updateDescriptor(fileloc, wsName, outdir){
console.log('Updating descriptor file for: ' + wsName);
return new Promise(function(resolve, reject){
return getDescriptor(outdir).then(
(value) => {
let descriptorFile = value;
var comments = getComments(fileloc);
var variables = getVariables(fileloc);
//wait until both are completed before continuing
return Promise.all([comments, variables]).then((values) => {
descriptorFile[wsName] = new Object();
descriptorFile[wsName].comments = values[0];
descriptorFile[wsName].variables = values[1];
//save the file
return saveDescriptor(descriptorFile, outdir).then((value) => {
console.log('Completed ' + wsName + ' ' + value);
resolve(value);
}, (reason) => {console.log(reason)})
}, (reason) => {
console.log(reason);
}
)
},
(reason) => {console.log(reason)}
)
})
}
function describeDir(filedir, outdir){
var files = findFilesInDir(filedir, '.XML');
for (var k=0;k<files.length;k++){
if ((files[k].indexOf('@HW') !== -1) || (files[k].indexOf('@LIBS') !== -1) || (files[k].indexOf('@ROOT') !== -1) || (files[k].indexOf('run') !== -1)) {
files.splice(k,1);
}
}
return Promise.each(files, function(file){
return updateDescriptor(file, path.basename(file), outdir);
});
}
After calling the functions here, everything seems to work correctly, but the then() function is not being called. Note that I'm using bluebird in this latest version.
docProcessor.describeDir(folder, path.join(__dirname, '..')).then((value)=> {
console.log('docProcessor then entered: ' + value);
});