From 623752a433237b4df27d1865ca8e5852d61d4b0d Mon Sep 17 00:00:00 2001 From: Matteo Padovano Date: Tue, 9 Jul 2019 17:48:25 +0200 Subject: [PATCH] run api generator after app is booted resolve strongloop/loopback-boot#291 --- export-api-def/index.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/export-api-def/index.js b/export-api-def/index.js index b9fc748..edd6e2c 100644 --- a/export-api-def/index.js +++ b/export-api-def/index.js @@ -35,17 +35,25 @@ module.exports = class ExportAPIDefGenerator extends ActionsMixin(yeoman) { var filePath = this.options.output; var options = {format: this.format, output: filePath}; var app = require(this.destinationRoot()); - var apiDef = apiGenerator.getApiDef(app, options); - // Print to console if no output file specified. - if (filePath) { - mkdirp.sync(path.dirname(filePath)); - fs.writeFileSync(filePath, apiDef); + if (app.booting) { + app.on('booted', runGenerator); } else { - process.stdout.write(apiDef); + runGenerator(); } - // Kill app if still alive - setTimeout(process.exit, 100); + function runGenerator() { + var apiDef = apiGenerator.getApiDef(app, options); + // Print to console if no output file specified. + if (filePath) { + mkdirp.sync(path.dirname(filePath)); + fs.writeFileSync(filePath, apiDef); + } else { + process.stdout.write(apiDef); + } + + // Kill app if still alive + setTimeout(process.exit, 100); + } } };