fix(jsdoc): wait for async templates to finish before existing

Previously, we could exit before the template finished running, making it impossible to build a truly async template.
This commit is contained in:
Jeff Williams 2019-10-09 14:17:24 -04:00
parent 65406e6d94
commit 58726cb9da
2 changed files with 13 additions and 16 deletions

View File

@ -145,7 +145,7 @@ module.exports = (() => {
};
// TODO: docs
cli.runCommand = cb => {
cli.runCommand = () => {
let cmd;
const opts = env.opts;
@ -166,11 +166,13 @@ module.exports = (() => {
cmd = cli.main;
}
cmd().then(errorCode => {
return cmd().then(errorCode => {
if (!errorCode && props.shouldExitWithError) {
errorCode = 1;
}
cb(errorCode);
cli.logFinish();
cli.exit(errorCode || 0);
});
};
@ -385,6 +387,7 @@ module.exports = (() => {
};
cli.generateDocs = () => {
let message;
const path = require('jsdoc/path');
const resolver = require('jsdoc/tutorial/resolver');
const taffy = require('taffydb').taffy;
@ -421,13 +424,12 @@ module.exports = (() => {
return Promise.resolve(publishPromise);
}
else {
logger.fatal(
`${env.opts.template} does not export a "publish" function. ` +
'Global "publish" functions are no longer supported.'
);
}
message = `${env.opts.template} does not export a "publish" function. ` +
'Global "publish" functions are no longer supported.';
logger.fatal(message);
return Promise.resolve();
return Promise.reject(new Error(message));
}
};
// TODO: docs

View File

@ -45,18 +45,13 @@
*/
global.env = (() => require('./lib/jsdoc/env'))();
(() => {
(async () => {
const cli = require('./cli');
function cb(errorCode) {
cli.logFinish();
cli.exit(errorCode || 0);
}
cli.setVersionInfo()
.loadConfig()
.configureLogger()
.logStart();
cli.runCommand(cb);
await cli.runCommand();
})();