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

@@ -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');
})