Created
July 8, 2011 11:51
-
-
Save matthijsgroen/1071668 to your computer and use it in GitHub Desktop.
Rake file for executing guard to prepare your environment
This file contains 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
desc "compiles all coffeescripts and scss stylesheets in the project" | |
task :prepare => 'prepare:all'.to_sym | |
namespace :prepare do | |
desc "compiles all coffeescripts in the project" | |
task :coffeescript do | |
run_guards "Guard::CoffeeScript" | |
end | |
desc "compiles all coffeescripts in the project" | |
task :sass do | |
run_guards "Guard::Sass" | |
end | |
desc "compiles all coffeescripts and scss stylesheets in the project" | |
task :all do | |
run_guards "Guard::CoffeeScript", "Guard::Sass" | |
end | |
end | |
def run_guards *guards | |
require 'guard' | |
Guard.setup | |
Guard::Dsl.evaluate_guardfile | |
Guard::guards.reject! { |guard| !guards.include? guard.class.name } | |
Guard::guards.each do |guard| | |
guard.run_all if guards.include? guard.class.name | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Override task behaviour.
http://metaskills.net/2010/05/26/the-alias_method_chain-of-rake-override-rake-task/
Rake::TaskManager.class_eval do
def alias_task(fq_name)
new_name = "#{fq_name}:original"
@tasks[new_name] = @tasks.delete(fq_name)
end
end
def alias_task(fq_name)
Rake.application.alias_task(fq_name)
end
def override_task(_args, &block)
name, params, deps = Rake.application.resolve_args(args.dup)
fq_name = Rake.application.instance_variable_get(:@scope).dup.push(name).join(':')
alias_task(fq_name)
Rake::Task.define_task(_args, &block)
end
override_task :environment do
Rake::Task["prepare:all"].execute
Rake::Task["environment:original"].execute
end