fix(api-generate): API docs generation now is run through a separate npm command ZMS-139 (#659)

* added generate-api-docs npm command and corresponding code changes

* fix typo
This commit is contained in:
NickOvt 2024-04-03 11:43:54 +03:00 committed by GitHub
parent 2d08b6132f
commit 6548f3cd5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

12
api.js
View file

@ -581,7 +581,18 @@ module.exports = done => {
);
}
if (process.env.GENERATE_API_DOCS === 'true') {
server.pre(restifyApiGenerate.restifyApiGenerate(server, restifyApiGenerateConfig));
}
if (process.env.REGENERATE_API_DOCS === 'true') {
// allow 2.5 seconds for services to start and the api doc to be generated, after that exit process
(async function () {
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
await sleep(2500);
process.exit(0);
})();
}
server.on('error', err => {
if (!started) {
@ -605,6 +616,7 @@ module.exports = done => {
}
started = true;
log.info('API', 'Server listening on %s:%s', config.api.host || '0.0.0.0', config.api.port);
done(null, server);
});
};

View file

@ -12,7 +12,8 @@
"apidoc": "apidoc -i lib/api/ -o docs/api/",
"show": "NODE_CONFIG_ONLY=true node server.js",
"start": "node server.js",
"update": "rm -rf node_modules package-lock.json && ncu -u && npm install"
"update": "rm -rf node_modules package-lock.json && ncu -u && npm install",
"generate-api-docs": "GENERATE_API_DOCS=true REGENERATE_API_DOCS=true node server.js"
},
"keywords": [
"imap",