LoginSignup
7
6

More than 5 years have passed since last update.

ビルドツール prunt を作ってみました

Last updated at Posted at 2013-06-24

仕事で grunt を使っていましたが、日日肥大化する Gruntfile を生理的に受け付けなく、自分でビルドツールを作ってみました。

じゃあどんなのが欲しいのか

  • ビジュアル的に分かりやすいワークフロー
  • ファイルの読み書きは最初と最後だけ
  • シンプルなプラグイン
  • Cakefileや他のCLIとの互換性

Prunt

Githubリポジトリ: hden/prunt
インストールはnpm install prunt

A prunt is a small blob of glass fused to another piece of glass to help provide a firm grip in the absence of a handle.
-- modified from Wikipedia.

この記事を読んで分かること

  • pruntを作ったきっかけ
  • 基本的な使い方

ビジュアル的に分かりやすいワークフロー

Promiseを使って.thenメソッドチェーンを使いました。

# pseudocode
read('src/*.coffee') # returns a promise
  .then(concat)
  .then(compile)
  .then(uglify)
  .done(write) # write to disk

ファイルの読み書きは最初と最後だけ

Gruntを使っているときに中間生産物をハードディスクに書き出す事が有りますね?それを次のタスクのsrcに指定して使う事を非合理に思います。一回ファイルを読み込み、色々いじって、最後にだけ書き出す。

シンプルなプラグイン

現在入っているプラグインは以下の通りです

  • Concatenate files
  • Clean files and folders
  • Compile coffee-script
  • Compile LESS
  • Minify JavaScript
  • Minify CSS

使い方はいかにも簡単、先ほどのサンプルとあまり変わりません。

# real code
{read} = prunt = require 'prunt'

concat = prunt.concat {filename: 'index.coffee'}
coffee = prunt.coffee()
write = prunt.write()

read('src/*.coffee')
  .then(concat)
  .then(coffee)
  .done(write)

これから導入する予定は

Cakefileや他のCLIとの互換性

pruntにはCLI機能が入っていません、お好きなものを使ってください。coffee-scriptユーザーにはCakefileに入れたら丁度良いでしょう。

以下がprunt自身のCakefileです、見ての通り先ほどのサンプルとあまり変わりません。そのシンプルさが売りです!

{read} = prunt = require 'prunt'

concat = prunt.concat {filename: 'index.coffee', dirname: '.'}
coffee = do prunt.coffee
write = do prunt.write

task 'build', 'build prunt', ->
  read('src/*.coffee')
    .then(concat)
    .then(coffee)
    .done(write)

次の投稿で話す予定

  • pruntプラグインの書き方
  • Cakeや他のCLIとのコラボ
7
6
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
7
6