6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

update-notifierを使ってnpmのような更新通知機能をつける

Last updated at Posted at 2018-09-04

よくnpmを使っていて下と似たような通知を受けることがあると思います。

npm/cli: a package manager for JavaScript

これがupdate-notifierです。npmをはじめ、色々なcliツールで使われています。

yeoman/update-notifier: Update notifications for your CLI app

このツールは非常に手軽に導入できます。

const updateNotifier = require('update-notifier');
const pkg = require('./package.json');

updateNotifier({pkg}).notify();

これだけです。

デフォルトだと、更新の確認は実行時に行われ、かつインターバルが1日なので、頻繁に通知がくることはありません。

自分の場合は、cliのオプションのパーサにmeowを使うことが多いので、以下のように書くことが多いです。

const meow = require('meow')
const updateNotifier = require('update-notifier')

const cli = meow(
  `
	Usage
	  $ hello [name]

	Examples
	  $ hello
`,
  {
    flags: {
      name: {
        type: 'boolean',
      },
    },
  }
)

updateNotifier({ pkg: cli.pkg }).notify()


// ...
6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?