From d05b5d48418a411a2ff57da626ac24c5642bdb3d Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Wed, 16 Aug 2017 13:26:49 -0400 Subject: [PATCH 1/8] added npmview dependency for latest version checking. --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index e934aeda..6812d1e5 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "dat-registry": "^3.0.3", "debug": "^3.0.0", "neat-log": "^1.1.0", + "npmview": "^0.0.4", "prettier-bytes": "^1.0.3", "progress-string": "^1.2.1", "prompt": "^1.0.0", From 0783a725749971a289acbccaee8bdf79e34c3883 Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Wed, 16 Aug 2017 13:30:29 -0400 Subject: [PATCH 2/8] added proof of concept for version checker. --- src/version-check.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/version-check.js diff --git a/src/version-check.js b/src/version-check.js new file mode 100644 index 00000000..3830e207 --- /dev/null +++ b/src/version-check.js @@ -0,0 +1,29 @@ +var fs = require('fs') +var chalk = require('chalk') +var npmview = require('npmview') + +npmview('dat', function (err, version, moduleInfo) { + if (err) { + console.error(err) + return + } + + fs.writeFile('../.dat-version', version, function (err) { + if (err) { + console.error(err) + } + }) +}) + + +if (fs.existsSync('../.dat-version')) { + var latestVersion= fs.readFileSync('../.dat-version', 'utf8') + var pkg = require('../package.json') + if (pkg.version !== latestVersion) { + console.log(chalk.yellow('warning') + ' your version of Dat is ' + + 'out of date. The latest version is "' + + latestVersion + '" while you are on "' + pkg.version + '".\n' + + chalk.cyan('info') + ' To upgrade, run the following command:\n' + + chalk.gray('$ npm install dat -g ')) + } +} From 67c8bc4535add86b359d34067789de47d7705224 Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Wed, 16 Aug 2017 16:27:38 -0400 Subject: [PATCH 3/8] ran standard --fix to fix style so tests can pass. --- src/version-check.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/version-check.js b/src/version-check.js index 3830e207..ea8a07b6 100644 --- a/src/version-check.js +++ b/src/version-check.js @@ -15,9 +15,8 @@ npmview('dat', function (err, version, moduleInfo) { }) }) - if (fs.existsSync('../.dat-version')) { - var latestVersion= fs.readFileSync('../.dat-version', 'utf8') + var latestVersion = fs.readFileSync('../.dat-version', 'utf8') var pkg = require('../package.json') if (pkg.version !== latestVersion) { console.log(chalk.yellow('warning') + ' your version of Dat is ' + @@ -25,5 +24,5 @@ if (fs.existsSync('../.dat-version')) { latestVersion + '" while you are on "' + pkg.version + '".\n' + chalk.cyan('info') + ' To upgrade, run the following command:\n' + chalk.gray('$ npm install dat -g ')) - } + } } From 86ba3fc2cac6d2895de4cc0c6b001b392cf0096c Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Thu, 17 Aug 2017 15:18:47 -0400 Subject: [PATCH 4/8] made version-check exportable. --- src/version-check.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/version-check.js b/src/version-check.js index ea8a07b6..bb0bdb83 100644 --- a/src/version-check.js +++ b/src/version-check.js @@ -2,27 +2,29 @@ var fs = require('fs') var chalk = require('chalk') var npmview = require('npmview') -npmview('dat', function (err, version, moduleInfo) { - if (err) { - console.error(err) - return - } - - fs.writeFile('../.dat-version', version, function (err) { +module.exports = function () { + npmview('dat', function (err, version, moduleInfo) { if (err) { console.error(err) + return } + + fs.writeFile('../.dat-version', version, function (err) { + if (err) { + console.error(err) + } + }) }) -}) -if (fs.existsSync('../.dat-version')) { - var latestVersion = fs.readFileSync('../.dat-version', 'utf8') - var pkg = require('../package.json') - if (pkg.version !== latestVersion) { - console.log(chalk.yellow('warning') + ' your version of Dat is ' + + if (fs.existsSync('../.dat-version')) { + var latestVersion = fs.readFileSync('../.dat-version', 'utf8') + var pkg = require('../package.json') + if (pkg.version !== latestVersion) { + console.log(chalk.yellow('warning') + ' your version of Dat is ' + 'out of date. The latest version is "' + latestVersion + '" while you are on "' + pkg.version + '".\n' + chalk.cyan('info') + ' To upgrade, run the following command:\n' + chalk.gray('$ npm install dat -g ')) + } } } From 6cf9aa77cc13aa176184a87f90864730d37778c6 Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Thu, 17 Aug 2017 15:19:37 -0400 Subject: [PATCH 5/8] added version check to 'bin/cli.js'. --- bin/cli.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/cli.js b/bin/cli.js index 4ae46ff3..8fb0cf8b 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -3,6 +3,7 @@ var subcommand = require('subcommand') var debug = require('debug')('dat') var usage = require('../src/usage') +var versionCheck = require('../src/version-check') process.title = 'dat' @@ -83,6 +84,7 @@ match(alias(process.argv.slice(2))) function alias (argv) { var cmd = argv[0] + versionCheck() if (!config.aliases[cmd]) return argv argv[0] = config.aliases[cmd] return argv From f3191460f854164575b8aa42ca106080f57c0169 Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Thu, 17 Aug 2017 15:40:02 -0400 Subject: [PATCH 6/8] removed npmview and added latest-version to package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6812d1e5..ec24b93a 100644 --- a/package.json +++ b/package.json @@ -45,8 +45,8 @@ "dat-node": "^3.5.0", "dat-registry": "^3.0.3", "debug": "^3.0.0", + "latest-version": "^3.1.0", "neat-log": "^1.1.0", - "npmview": "^0.0.4", "prettier-bytes": "^1.0.3", "progress-string": "^1.2.1", "prompt": "^1.0.0", From 61f2f0973eda61e893c1b1d6b3d15ab2da608b9b Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Thu, 17 Aug 2017 15:40:41 -0400 Subject: [PATCH 7/8] switched npmview with latest-version in version-check.js --- src/version-check.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/version-check.js b/src/version-check.js index bb0bdb83..0b65ac6e 100644 --- a/src/version-check.js +++ b/src/version-check.js @@ -1,14 +1,9 @@ var fs = require('fs') var chalk = require('chalk') -var npmview = require('npmview') +var latestVersion = require('latest-version') module.exports = function () { - npmview('dat', function (err, version, moduleInfo) { - if (err) { - console.error(err) - return - } - + latestVersion('dat').then(function (version) { fs.writeFile('../.dat-version', version, function (err) { if (err) { console.error(err) @@ -17,12 +12,12 @@ module.exports = function () { }) if (fs.existsSync('../.dat-version')) { - var latestVersion = fs.readFileSync('../.dat-version', 'utf8') + var newestVersion = fs.readFileSync('../.dat-version', 'utf8') var pkg = require('../package.json') - if (pkg.version !== latestVersion) { + if (pkg.version !== newestVersion) { console.log(chalk.yellow('warning') + ' your version of Dat is ' + 'out of date. The latest version is "' + - latestVersion + '" while you are on "' + pkg.version + '".\n' + + newestVersion + '" while you are on "' + pkg.version + '".\n' + chalk.cyan('info') + ' To upgrade, run the following command:\n' + chalk.gray('$ npm install dat -g ')) } From 628304c2ca8e03a7fd9493fc3575604e3495bcf5 Mon Sep 17 00:00:00 2001 From: Joe Hand Date: Tue, 27 Mar 2018 11:19:50 -0700 Subject: [PATCH 8/8] use update notifier for upgrade message --- bin/cli.js | 19 ++++++++++++++++--- package.json | 2 +- src/version-check.js | 25 ------------------------- 3 files changed, 17 insertions(+), 29 deletions(-) delete mode 100644 src/version-check.js diff --git a/bin/cli.js b/bin/cli.js index 8fb0cf8b..4d684714 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -3,7 +3,7 @@ var subcommand = require('subcommand') var debug = require('debug')('dat') var usage = require('../src/usage') -var versionCheck = require('../src/version-check') +var pkg = require('../package.json') process.title = 'dat' @@ -12,6 +12,21 @@ var NODE_VERSION_SUPPORTED = 4 var nodeMajorVer = process.version.match(/^v([0-9]+)\./)[1] var invalidNode = nodeMajorVer < NODE_VERSION_SUPPORTED if (invalidNode) exitInvalidNode() +else { + var notifier = require('update-notifier') + notifier({pkg: pkg}) + .notify({ + defer: true, + isGlobal: true, + boxenOpts: { + align: 'left', + borderColor: 'green', + borderStyle: 'classic', + padding: 1, + margin: {top: 1, bottom: 1} + } + }) +} if (debug.enabled) { debug('Dat DEBUG mode engaged, enabling quiet mode') @@ -73,7 +88,6 @@ var config = { } if (debug.enabled) { - var pkg = require('../package.json') debug('dat', pkg.version) debug('node', process.version) } @@ -84,7 +98,6 @@ match(alias(process.argv.slice(2))) function alias (argv) { var cmd = argv[0] - versionCheck() if (!config.aliases[cmd]) return argv argv[0] = config.aliases[cmd] return argv diff --git a/package.json b/package.json index 70c0dc89..8b01a4a9 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,6 @@ "dat-node": "^3.5.5", "dat-registry": "^4.0.0", "debug": "^3.0.0", - "latest-version": "^3.1.0", "neat-log": "^1.1.0", "prettier-bytes": "^1.0.3", "progress-string": "^1.2.1", @@ -57,6 +56,7 @@ "speedometer": "^1.0.0", "subcommand": "^2.1.0", "throttle": "^1.0.3", + "update-notifier": "^2.3.0", "xtend": "^4.0.1" }, "devDependencies": { diff --git a/src/version-check.js b/src/version-check.js deleted file mode 100644 index 0b65ac6e..00000000 --- a/src/version-check.js +++ /dev/null @@ -1,25 +0,0 @@ -var fs = require('fs') -var chalk = require('chalk') -var latestVersion = require('latest-version') - -module.exports = function () { - latestVersion('dat').then(function (version) { - fs.writeFile('../.dat-version', version, function (err) { - if (err) { - console.error(err) - } - }) - }) - - if (fs.existsSync('../.dat-version')) { - var newestVersion = fs.readFileSync('../.dat-version', 'utf8') - var pkg = require('../package.json') - if (pkg.version !== newestVersion) { - console.log(chalk.yellow('warning') + ' your version of Dat is ' + - 'out of date. The latest version is "' + - newestVersion + '" while you are on "' + pkg.version + '".\n' + - chalk.cyan('info') + ' To upgrade, run the following command:\n' + - chalk.gray('$ npm install dat -g ')) - } - } -}