Skip to content

Commit

Permalink
Merge pull request #292 from snyk/feat/cli_upgrade_message
Browse files Browse the repository at this point in the history
feat: add a CLI message when newer version is available
  • Loading branch information
yuliabaron authored Dec 6, 2018
2 parents 294f002 + 5053c4e commit daebb6a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"tempfile": "^2.0.0",
"then-fs": "^2.0.0",
"undefsafe": "^2.0.0",
"update-notifier": "^2.5.0",
"uuid": "^3.2.1"
},
"devDependencies": {
Expand Down
27 changes: 27 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@ import spinner = require('../lib/spinner');
import errors = require('../lib/error');
import ansiEscapes = require('ansi-escapes');
import {isPathToPackageFile} from '../lib/detect';
import * as updateNotifier from 'update-notifier';
import * as fs from 'fs';
import * as p from 'path';

function updateCheck() {
const root = p.resolve(__dirname, p.normalize('../..'));
const pkgPath = p.resolve(root, 'package.json');
const isPkgFilePresent = fs.existsSync(pkgPath);

if (!isPkgFilePresent) {
return;
}

const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));

// if there's no version (f.e. during tests) - do not proceed
if (!pkg.version) {
return;
}

// Checks for available update and returns an instance
// Default updateCheckInterval is once a day
const notifier = updateNotifier({pkg});
notifier.notify();
return;
}

async function runCommand(args) {
const result = await args.method(...args.options._);
Expand Down Expand Up @@ -108,6 +134,7 @@ function checkPaths(args) {
}

async function main() {
updateCheck();
checkRuntime();

const args = argsLib(process.argv);
Expand Down

0 comments on commit daebb6a

Please sign in to comment.