mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
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:
@@ -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');
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user