Support for notifying user if an update is available for Directus CLI (#6852)

* Notify user if an update is available

* Replaced console log with logger

* Fix lint error

* Update api/src/start.ts

* Make update check non-blocking

* Remove unused async call

Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
This commit is contained in:
Saad Irfan ⚡️
2021-07-27 04:36:16 +05:00
committed by GitHub
parent 256b0b66bf
commit afdeb980cb
3 changed files with 15 additions and 1 deletions

View File

@@ -137,6 +137,7 @@
"rollup": "^2.52.1",
"sharp": "^0.28.3",
"stream-json": "^1.7.1",
"update-check": "^1.5.4",
"uuid": "^8.3.2",
"uuid-validate": "0.0.3"
},

View File

@@ -1,6 +1,8 @@
import emitter, { emitAsyncSafe } from './emitter';
import env from './env';
import logger from './logger';
import checkForUpdate from 'update-check';
import pkg from '../package.json';
// If this file is called directly using node, start the server
if (require.main === module) {
@@ -18,6 +20,16 @@ export default async function start(): Promise<void> {
server
.listen(port, () => {
checkForUpdate(pkg)
.then((update) => {
if (update) {
logger.warn(`Update available: ${pkg.version} -> ${update.latest}`);
}
})
.catch(() => {
// No need to log/warn here. The update message is only an informative nice-to-have
});
logger.info(`Server started at port ${port}`);
emitAsyncSafe('server.start');
})

View File

@@ -10,7 +10,8 @@
"strict": true,
"lib": ["es2019"],
"skipLibCheck": true,
"declaration": true
"declaration": true,
"resolveJsonModule": true
},
"exclude": ["node_modules", "dist"]
}