[npm & Bower] npm-check-updates: package.json 内の npm version を一括で最新に書き換える
package.json 内の ~0.5.0 といったバージョン番号を、コマンド一発で最新バージョン番号に書き換えてくれます。
[markdown]
## インストール
> * [npm-check-updates](https://www.npmjs.org/package/npm-check-updates)
“`prettyprinted
% npm install -g npm-check-updates
“`
## つかいかた
### global npm packages
グローバルに入れたパッケージをチェックします。
“`prettyprinted
% npm-check-updates -g
“npm” can be updated from 1.4.23 to 1.4.24
“`
npm 自身だったので、とりあえず普通にアップデートします。
“`prettyprinted
% npm update -g
“`
### package.json
`npm outdated` でチェックするとこんな一覧出力。
“`prettyprinted
% npm outdated
Package Current Wanted Latest Location
grunt-contrib-clean 0.5.0 0.5.0 0.6.0 grunt-contrib-clean
grunt-contrib-copy 0.4.1 0.4.1 0.5.0 grunt-contrib-copy
grunt-contrib-concat 0.3.0 0.3.0 0.5.0 grunt-contrib-concat
grunt-contrib-cssmin 0.6.2 0.6.2 0.10.0 grunt-contrib-cssmin
grunt-contrib-htmlmin 0.1.3 0.1.3 0.3.0 grunt-contrib-htmlmin
:
“`
`npm-check-updates` は、オプションなしでカレントディレクトリの package.json をチェックしてくれるよう。
数が多いと可読性が悪いかな。
“`prettyprinted
% npm-check-updates
“grunt-bower-task” can be updated from ~0.3.4 to ~0.4.0 (Installed: 0.3.4, Latest: 0.4.0)
“grunt-simple-ejs” can be updated from ~0.3.0 to ~0.4.0 (Installed: 0.3.0, Latest: 0.4.0)
“grunt” can be updated from ~0.4.2 to ~0.4.5 (Installed: 0.4.5, Latest: 0.4.5)
“grunt-contrib-concat” can be updated from ~0.3.0 to ~0.5.0 (Installed: 0.3.0, Latest: 0.5.0)
“grunt-contrib-copy” can be updated from ~0.4.1 to ~0.5.0 (Installed: 0.4.1, Latest: 0.5.0)
:
“time-grunt” can be updated from ~0.2.7 to ~0.4.0 (Installed: 0.2.10, Latest: 0.4.0)
Run ‘npm-check-updates -u’ to upgrade your package.json automatically
“`
`-u` オプションを付けると、package.json をアップデートしてくれます。
“`prettyprinted
% npm-check-updates -u
“grunt-bower-task” can be updated from ~0.3.4 to ~0.4.0 (Installed: 0.3.4, Latest: 0.4.0)
“grunt-simple-ejs” can be updated from ~0.3.0 to ~0.4.0 (Installed: 0.3.0, Latest: 0.4.0)
“grunt” can be updated from ~0.4.2 to ~0.4.5 (Installed: 0.4.5, Latest: 0.4.5)
“grunt-contrib-concat” can be updated from ~0.3.0 to ~0.5.0 (Installed: 0.3.0, Latest: 0.5.0)
“grunt-contrib-copy” can be updated from ~0.4.1 to ~0.5.0 (Installed: 0.4.1, Latest: 0.5.0)
:
“time-grunt” can be updated from ~0.2.7 to ~0.4.0 (Installed: 0.2.10, Latest: 0.4.0)
package.json upgraded
“`
package.json を確認してみると、最新バージョン番号に変更されています!
“`json:package.json
“devDependencies”: {
“grunt-bower-task”: “~0.4.0”,
“grunt-simple-ejs”: “~0.4.0”,
“grunt”: “~0.4.5”,
“grunt-contrib-concat”: “~0.5.0”,
“grunt-contrib-copy”: “~0.5.0”,
“`
あとは `npm update` すればOKですね。
“`prettyprinted
% npm update
% npm-check-updates
All dependencies match the latest package versions 🙂
“`
これは、はかどりますね。
[/markdown]