Skip to content

Instantly share code, notes, and snippets.

@doloopwhile
Last active July 25, 2016 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doloopwhile/ccb05c5dd63be28ab6fe to your computer and use it in GitHub Desktop.
Save doloopwhile/ccb05c5dd63be28ab6fe to your computer and use it in GitHub Desktop.
gulpにもmakeにも不満なWebデベロッパーためのRake(コンパイル・パターンマッチ・ファイル監視・通知) ref: http://qiita.com/doloopwhile/items/6088ad6c1753806da7c0
# Rakefile
# パターンにマッチするファイルのリストを生成
Src = FileList['src/*.js']
# dist.jsの生成にはSrcに含まれるファイルが必要と定義
# do〜endの中で具体的な生成方法を定義
file 'dist.js' => Src do |t|
# t.sourcesがソースファイルのリストなので、それをスペースで連結したコマンドラインを生成
sh "browserify -o dist.js #{t.sources.join(' ')}"
end
# デフォルトのタスクはdist.jsの生成と定義
task :default => 'dist.js'
$ sudo apt install ruby2.0 # Ubuntuの場合
$ brew install ruby # OS Xの場合
# Rakefile
# パターンにマッチするファイルのリストを生成
Src = FileList['src/*.js']
# dist.jsの生成にはSrcに含まれるファイルが必要と定義
# do〜endの中で具体的な生成方法を定義
file 'dist.js' => Src do |t|
# t.sourcesがソースファイルのリストなので、それをスペースで連結したコマンドラインを生成
sh "browserify -o dist.js #{t.sources.join(' ')}"
end
# デフォルトのタスクはdist.jsの生成と定義
task :default => 'dist.js'
# Rakefile
SRC = FileList['src/*.scss']
# SRC を規則的に変換
DIST = SRC.pathmap('%{^src,dist}X.css')
# Rubyの標準機能を使ってやることもできる
# DST = SRC.map do |path|
# path.sub! /^src\//, 'dist/'
# path.sub! /\.scss/, 'css'
# end
# rule を使うと規則的な変換が定義できる
rule /dist\/.*\.css/ => '%{^dist,src}X.scss' do |t|
sh "scss #{t.source} #{t}"
end
task :default => DIST
# Rakefile
require 'rake/clean'
Src = FileList["*.c"]
Obj = Src.ext('o')
CLEAN.include(Obj)
CLOBBER.include('hello')
file 'hello' => Obj do |t|
sh "gcc -o #{t.name} #{t.sources.join(' ')}"
end
rule '.o' => '.c' do |t|
sh "gcc -c #{t.source}"
end
task :default => 'hello'
# rake clean で *.oが削除される
# rake clobber で hello も削除される
# Rakefile
task :rsync do |t|
sh "rsync -rax dist/ appsvr:/var/www/html/"
end
task :default => :rsync
# Rakefile
task :rsync do |t|
sh "rsync -rax dist appsvr:/var/www/html/"
end
task :watch do |t|
sh %w{fswatch -r w/ | xargs -I{} sh -c "rake && notify-send 'rsync success' || notify-send 'rsync failure'"}
end
task :default => :rsync
# 以下のコマンドで監視開始
# $ rake watch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment