Skip to content

Commit

Permalink
feat: Add update notification
Browse files Browse the repository at this point in the history
When a newer version is found on the NPM registry, twitch2ma notifies the user on startup.
  • Loading branch information
schw4rzlicht committed Jun 6, 2020
1 parent 9df2c61 commit 23d57b5
Show file tree
Hide file tree
Showing 3 changed files with 2,595 additions and 188 deletions.
41 changes: 28 additions & 13 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,36 @@ import YAML = require("yaml");
import _ = require("lodash");
import chalk = require("chalk");

const semverGt = require('semver/functions/gt')
const packageInformation = require("../../package.json");

new Command()
.name("twitch2ma")
.description(packageInformation.description)
.version(packageInformation.version, "-v, --version", "output the current version")
.arguments("[configFile]")
.action(configFile => {
loadConfig(configFile)
.then(config => new Twitch2Ma(config))
.then(attachEventHandlers)
.then(twitch2Ma => twitch2Ma.start())
.catch(exitWithError);
})
.parse(process.argv);
require("libnpm")
.manifest(packageInformation.name)
.then(notifyUpdate)
.then(init);

function init(): void {
new Command()
.name(packageInformation.name)
.description(packageInformation.description)
.version(packageInformation.version, "-v, --version", "output the current version")
.arguments("[configFile]")
.action(configFile => {
loadConfig(configFile)
.then(config => new Twitch2Ma(config))
.then(attachEventHandlers)
.then(twitch2Ma => twitch2Ma.start())
.catch(exitWithError);
})
.parse(process.argv);
}

function notifyUpdate(manifest: any) {
if(semverGt(manifest.version, packageInformation.version)) {
console.log(chalk`🔔 {blue A new version of ${packageInformation.name} is available!} ` +
chalk`{blue (current: {bold ${packageInformation.version}}, new: {bold ${manifest.version}})}`);
}
}

async function attachEventHandlers(twitch2Ma: Twitch2Ma): Promise<Twitch2Ma> {

Expand Down
Loading

0 comments on commit 23d57b5

Please sign in to comment.