From 6548f3cd5efcf3a768dced5661ef9c61c797a45a Mon Sep 17 00:00:00 2001 From: NickOvt Date: Wed, 3 Apr 2024 11:43:54 +0300 Subject: [PATCH] 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 --- api.js | 14 +++++++++++++- package.json | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/api.js b/api.js index f23d0d9d..f8d1cdca 100644 --- a/api.js +++ b/api.js @@ -581,7 +581,18 @@ module.exports = done => { ); } - server.pre(restifyApiGenerate.restifyApiGenerate(server, restifyApiGenerateConfig)); + 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); }); }; diff --git a/package.json b/package.json index a14dd039..dc41c054 100644 --- a/package.json +++ b/package.json @@ -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",