-
-
Notifications
You must be signed in to change notification settings - Fork 449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add function to tell user if dat version is out of date. Closes #777 #852
Conversation
Also, I do use
Does anyone have any idea why? |
@TimothyStiles I suspect that it's because |
This sounds to me like a function that should always be run, no matter which |
@ralphtheninja I think the issue was that |
Sweet! Let's use something like latest-version instead of npmview to avoid the We could use https://github.com/yeoman/update-notifier but I find the update UI on that a bit harsh. I think they take a similar approach to background notification. |
@joehand I'll switch to latest-version in the next push.
Right now the UI is an exact clone of yarn update notifier you shared in #777. |
As far as integration, you should be able to add it to the exit UI, then somewhere (lib/archive.js ?) set |
@joehand how would you add it to the exit UI? Right now it's integrated by placing a call to function alias (argv) {
var cmd = argv[0]
versionCheck()
if (!config.aliases[cmd]) return argv
argv[0] = config.aliases[cmd]
return argv
} Would I have decompose var versionCheck = require('../version-check')
module.exports = onExit
function onExit (state, bus) {
bus.on('exit:error', onError)
bus.on('exit:warn', function (err) {
onError(err, true)
})
process.on('SIGINT', function () {
state.exiting = true
bus.render()
versionCheck()
process.exit()
})
function onError (err, clear) {
if (clear) bus.clear()
console.error(err)
process.exit(1)
}
} |
Aye, which is what I meant, I think :) |
Ya, the main thing I'd like is for it to print out at the end of a command, not the top. So it seems like the exit is the easiest place to hook into that.
function onExit (state, bus) {
versionCheck(function (err, outdated) {
state.versionOutdated = outdated
})
// ... other stuff
} We have to figure out where to render that... I may make a global ui element. I've been using var onExit = `
${state.versionOutdated ? 'TODO: outdated warning' : ''}
Exiting the Dat program...
`
${state.exiting ? onExit : chalk.dim('Ctrl+C to Exit')} |
|
||
module.exports = function () { | ||
latestVersion('dat').then(function (version) { | ||
fs.writeFile('../.dat-version', version, function (err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to write to a in the home-dir (or somewhere that'll be the same no matter where Dat is run). Maybe write to ~/.dat/cli-version.txt
(we use os-home module elsewhere)?
}) | ||
}) | ||
|
||
if (fs.existsSync('../.dat-version')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's avoid sync functions in this one so we don't block anything else. You can use fs.stat
instead.
}) | ||
|
||
if (fs.existsSync('../.dat-version')) { | ||
var newestVersion = fs.readFileSync('../.dat-version', 'utf8') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fs.readFile(name, cb)
see updated PR; #968 |
* added npmview dependency for latest version checking. * added proof of concept for version checker. * ran standard --fix to fix style so tests can pass. * made version-check exportable. * added version check to 'bin/cli.js'. * removed npmview and added latest-version to package.json * switched npmview with latest-version in version-check.js * use update notifier for upgrade message
Here's a proof of concept to solve issue #777 as described by @joehand and @juliangruber. Right now to run I just execute
node version-check.js
from the command line and it works as described in #777 aside from being run in a separate child process when dat is being used through its CLI.I'm not familiar with child processes in node yet. What's the best way to integrate this so that it runs as a child process when dat is used via the CLI?