Skip to content

Commit

Permalink
Merge pull request #129 from huynhducduy/main
Browse files Browse the repository at this point in the history
Feat: notify users whenever an update available
  • Loading branch information
nvh95 authored Jun 6, 2022
2 parents c6a2085 + 6ef680a commit f5d29fa
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 223 deletions.
22 changes: 22 additions & 0 deletions cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,25 @@ program.description('Start Jest Preview server.').action(() => {
});

program.parse(process.argv);

// Checks for available update and notify user
const updateNotifier = require('update-notifier');
const chalk = require('chalk');

const notifier = updateNotifier({
pkg: require('../package.json'),
updateCheckInterval: 0, // How often to check for updates
shouldNotifyInNpmScript: true, // Allows notification to be shown when running as an npm script
distTag: 'latest', // Can be use to notify user about pre-relase version
});

notifier.notify({
defer: true, // Try not to annoy user by showing the notification after the process has exited
message: [
`${chalk.blue('{packageName}')} has an update available: ${chalk.gray(
'{currentVersion}',
)}${chalk.green('{latestVersion}')}`,
`Please run ${chalk.cyan('`{updateCommand}`')} to update.`,
].join('\n'),
});
// END checks for available update and notify user
Loading

0 comments on commit f5d29fa

Please sign in to comment.