Having trouble figuring out why the 'describeDir' promise chain is not then-able.. Anyone have an idea what I messed up here? All of the code seems to execute, but any promise api function such as then or finally never gets executed. Two of the top level functions are shown below. The github repo is located 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) => {
//var descriptor = new Object();
//console.log(JSON.stringify(descriptor));
descriptorFile[wsName] = new Object();
//console.log(JSON.stringify(descriptor));
//var worksheet = 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);
});
}
Then I call the functions here. The code seems to execute just fine, but the then() is never called. Please note that I'm using bluebird in this latest revision.
//generate the output files, then copy them to the destination
docProcessor.describeDir(folder, path.join(__dirname, '..')).then((value)=>{
console.log('docProcessor then entered: ' + value);
});