Skip to content

Commit fd18d3d

Browse files
committed
run api generator after app is booted
resolve strongloop/loopback-boot#291
1 parent a12d373 commit fd18d3d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

export-api-def/index.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,25 @@ module.exports = class ExportAPIDefGenerator extends ActionsMixin(yeoman) {
3535
var filePath = this.options.output;
3636
var options = {format: this.format, output: filePath};
3737
var app = require(this.destinationRoot());
38-
var apiDef = apiGenerator.getApiDef(app, options);
3938

40-
// Print to console if no output file specified.
41-
if (filePath) {
42-
mkdirp.sync(path.dirname(filePath));
43-
fs.writeFileSync(filePath, apiDef);
39+
if (app.booting) {
40+
app.on('booted', runGenerator);
4441
} else {
45-
process.stdout.write(apiDef);
42+
runGenerator();
4643
}
4744

48-
// Kill app if still alive
49-
setTimeout(process.exit, 100);
45+
function runGenerator() {
46+
var apiDef = apiGenerator.getApiDef(app, options);
47+
// Print to console if no output file specified.
48+
if (filePath) {
49+
mkdirp.sync(path.dirname(filePath));
50+
fs.writeFileSync(filePath, apiDef);
51+
} else {
52+
process.stdout.write(apiDef);
53+
}
54+
55+
// Kill app if still alive
56+
setTimeout(process.exit, 100);
57+
}
5058
}
5159
};

0 commit comments

Comments
 (0)