From dab0775c9d04fa35b00b847258743eb6ae690796 Mon Sep 17 00:00:00 2001 From: Yucel Okcu Date: Wed, 15 Jan 2020 17:10:52 +0300 Subject: [PATCH] Add update notifier --- package.json | 2 ++ src/app.ts | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f459b4a..f571360 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "@types/jest": "^24.0.18", "@types/jsonwebtoken": "^8.3.4", "@types/node": "^12.7.5", + "@types/update-notifier": "^2.5.0", "@types/url-join": "^4.0.0", "@types/winston": "^2.4.4", "@typescript-eslint/eslint-plugin": "^2.3.0", @@ -68,6 +69,7 @@ "mask-json": "^1.0.3", "strip-ansi": "^6.0.0", "ts-dedent": "^1.1.0", + "update-notifier": "^4.0.0", "url-join": "^4.0.1", "winston": "^3.2.1" } diff --git a/src/app.ts b/src/app.ts index 151b622..3af969f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,15 +1,24 @@ #!/usr/bin/env node import commander from "commander"; +import updateNotifier from "update-notifier"; import { defaults } from "./config/defaults"; -import { bin, version } from "../package.json"; +import { bin, name, version } from "../package.json"; import { connect, ConnectOptions } from "./commands/connect"; import { login } from "./commands/login"; import { commandRunner } from "./util/command"; import { activateVerbose } from "./util/env"; import logger from "./util/logger"; -const program = new commander.Command(); +function beforeCommand(): void { + const un = updateNotifier({ + pkg: { + name, + version + } + }); + un.notify(); +} function createCollector(): (arg1: string, arg2: string[]) => string[] { let cleared = false; @@ -27,6 +36,8 @@ function createCollector(): (arg1: string, arg2: string[]) => string[] { return collectionValue; } +const program = new commander.Command(); + program .name(Object.keys(bin)[0]) .version(version); @@ -67,4 +78,5 @@ program.on("command:*", () => { program.outputHelp(); }); +beforeCommand(); program.parseAsync(process.argv);