[Grunt & Yeoman] grunt-init でプロジェクトのひな型を scaffold する

grunt プロジェクトを始めるときに楽したい。
いわゆる scaffold 的なツールでカスタムテンプレートも登録できる。

[markdown]
なんとなく使ってなかったのですが、どんなものかやってみました。

## インストール

> * [Project Scaffolding – Grunt: The JavaScript Task Runner](http://gruntjs.com/project-scaffolding)
> * [プロジェクトのScaffolding | Grunt 日本語リファレンス | js STUDIO](http://js.studio-kingdom.com/grunt/adv/project_scaffolding)

“`prettyprinted
% npm install -g grunt-init
/usr/local/bin/grunt-init -> /usr/local/lib/node_modules/grunt-init/bin/grunt-init
grunt-init@0.3.2 /usr/local/lib/node_modules/grunt-init
:
“`

## テンプレートを登録する

この状態では template が空なので、basic Gruntfile を作ってくれるテンプレートを登録します。

> * [gruntjs/grunt-init-gruntfile](https://github.com/gruntjs/grunt-init-gruntfile)

`~/.grunt-init/` 以下にテンプレートを配置します。

“`prettyprinted
% git clone https://github.com/gruntjs/grunt-init-gruntfile.git ~/.grunt-init/gruntfile
“`

## つかいかた

scaffold して、Gruntfiles.js と package.json を作成します。
全てエンターで進めました。

“`prettyprinted
% grunt-init gruntfile
:
Please answer the following:
[?] Is the DOM involved in ANY way? (Y/n)
[?] Will files be concatenated or minified? (Y/n)
[?] Will you have a package.json file? (Y/n)
[?] Do you need to make any changes to the above before continuing? (y/N)
Writing Gruntfile.js…OK
Writing package.json…OK
Initialized from template “gruntfile”.
Done, without errors.
“`

途中の設問の選択は、こんな結果になるようです。

> * [grunt-init-gruntfile/template.js at master · gruntjs/grunt-init-gruntfile](https://github.com/gruntjs/grunt-init-gruntfile/blob/master/template.js)

“`prettyprinted
.
├── Gruntfile.js
└── package.json
“`

package.json ができたので `npm install` します。

“`prettyprinted
% npm install
“`

grunt コマンドが使えるようになりました。

“`prettyprinted
% grunt
Running “jshint:gruntfile” (jshint) task
>> 1 file lint free.
Running “jshint:lib_test” (jshint) task
>> 0 files linted. Please check your ignored files.
Running “qunit:files” (qunit) task
Warning: 0/0 assertions ran (0ms) Use –force to continue.
Aborted due to warnings.
“`

自分の場合は .coffee ファイルに変換しました。

## カスタムテンプレート

カスタムテンプレートを作成するときは、こちらが参考になりそうです。

> * [grunt-initを使ったオリジナルひな形作成で時間節約Webサイト制作! | september creator](http://www.september-creator.com/2013/06/grunt-init/)
[/markdown]