Last active
July 25, 2016 11:05
-
-
Save doloopwhile/ccb05c5dd63be28ab6fe to your computer and use it in GitHub Desktop.
gulpにもmakeにも不満なWebデベロッパーためのRake(コンパイル・パターンマッチ・ファイル監視・通知) ref: http://qiita.com/doloopwhile/items/6088ad6c1753806da7c0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo apt install ruby2.0 # Ubuntuの場合 | |
$ brew install ruby # OS Xの場合 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 も削除される |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rakefile | |
task :rsync do |t| | |
sh "rsync -rax dist/ appsvr:/var/www/html/" | |
end | |
task :default => :rsync |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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