LoginSignup
5
5

More than 5 years have passed since last update.

git logからAuthorリストを生成してくれるgrunt-git-authorsについて紹介するよ

Posted at

grunt-git-authorsとは

git logからAuthorのリストをName <email>の形式で出力してくれるGruntプラグインです。

https://npmjs.org/package/grunt-git-authors
https://github.com/scottgonzalez/grunt-git-authors

私はjQueryのpackage.jsonを読んでいてこの存在を知りました。
https://github.com/jquery/jquery/blob/master/package.json#L40

何に使えるの?

AUTHORSファイルを作るのに使えます。
ソースを見てもらえば分かるんですが、git logでAuthorのリストを出力しているだけです。

AUTHORSファイルって何よ?

プロジェクトへの作者・寄与者が列挙されたテキストファイルです。
ちなみにgrunt-contrib-coffeeプラグインのAUTHORSはこちら。
https://github.com/gruntjs/grunt-contrib-coffee/blob/master/AUTHORS

npmの場合は、package.jsonの仕様を見ると下記のように書かれています。
https://npmjs.org/doc/json.html

"contributors": [...]

If there is an AUTHORS file in the root of your package, npm will treat each line as a Name (url) format, where email and url are optional. Lines which start with a # or are blank, will be ignored.

package.jsonのcontributorsに寄与者の名前とメールアドレス、URLなどを列挙するんですが、もしAUTHORSファイルがルートにあれば、よろしく読み取ってくれるとなっています。

contributorsを見てみる

例えば、grunt-contrib-coffeeプラグインのcontributorsは下記のように確認できます。

% npm view grunt-contrib-coffee contributors
[ 'Eric Woroshow (http://ericw.ca/)',
  'Tyler Kellen (http://goingslowly.com/)',
  'Chris Talkington (http://christalkington.com/)',
  'Kyle Robinson Young (http://twitter.com/shamakry)',
  'Yegor Pomortsev (https://github.com/illicium)',
  'Sindre Sorhus (http://github.com/sindresorhus)',
  'Callum Locke (https://github.com/callumlocke)',
  'Scott Delamater (https://github.com/scottydawg)',
  'Colin Wren (http://cawren.com)' ]

jQueryの場合はauthorのnameを個人ではなくして、urlがAUTHORSファイルを指すようになってました。

{
  "name": "jquery",
  "title": "jQuery",
  "description": "JavaScript library for DOM operations",
  "version": "2.1.0-pre",
  "main": "dist/jquery.js",
  "homepage": "http://jquery.com",
  "author": {
    "name": "jQuery Foundation and other contributors",
    "url": "https://github.com/jquery/jquery/blob/master/AUTHORS.txt"
  },

導入

インストール

npm installでgrunt-git-authorsをインストールします。package.jsonのdevDependenciesに追加されるように--save-devオプションを忘れずに。

% npm install grunt-git-authors --save-dev

Gruntfile.js

grunt-git-authors タスクをロードするように追記します。

module.exports = function(grunt) {
(略)
  grunt.loadNpmTasks('grunt-git-authors');
(略)
}; 

実行

下記のように実行するとコンソールにAuthorリストが出力されます。

% grunt authors

なので、リダイレクトしてAUTHORSファイルに出力されるようにすると良いと思います。
下記の例では、先頭/最終行のGruntログを削除しています。

% grunt authors | sed -e '1d' | sed -e '$d' > AUTHORS

まとめ

ほとんどの人には役に立たないプラグインではありますが、AUTHORS, grunt-git-authorsについて紹介しました。
npm installgit cloneしてるだけだと見逃してしまいますが、たまにはAUTHORSの情報も見て作者・寄与者の方々に心の中で感謝してはいかがでしょう。

git cloneしてgit shortlog -se | awk -F'\t' '{print $2,$3}'で、いいんじゃね?とか気にしない。

Appendix

Grunt Plugins
http://gruntjs.com/plugins

5
5
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
5
5