jwhitmire / sake-tasks forked from drnic/sake-tasks

Your own personal sake tasks, ripe for sharing.

commit  df1af813ff2b5b01f06ff3c25cfcf77db7dd24c6
tree    2c5616df152867215b74afd7078a61298f1ca0dc
parent  4463ae97ec27f4261693b6480c79cd333ca258f0 parent  039a9f93eaff1248e4e6539dfc15a396a4e986fc
sake-tasks / Rakefile
100644 79 lines (64 sloc) 2.066 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require 'rubygems'
require 'sake'
 
namespace :install do
  
  desc "Install all tasks contained in this directory and it's subdirectories"
  task :all do
    Dir['**/*.sake'].each do |task_file|
      tasks = Sake::TasksFile.parse(task_file).tasks
      uninstall_tasks(tasks)
      puts `sake -i #{task_file}`
    end
  end
  
  desc "Install the sake file that was updated last"
  task :latest do
    sorted_tasks = Dir['**/*.sake'].sort_by do |task|
      File.ctime(task)
    end
    
    task_file = sorted_tasks.last
    tasks = Sake::TasksFile.parse(task_file).tasks
    uninstall_tasks(tasks)
    puts `sake -i #{task_file}`
  end
  
  desc "Install specified file(s) [f=load,params] (no need to include .sake extension)"
  task :file do
    files = ENV['f'].split(',') rescue []
    files.collect { |f| f.sub('.sake', '') }
  
    Dir["**/*.sake"].find do |task_file|
      stripped_name = task_file.sub('.sake', '')
      if files.include?(stripped_name)
        tasks = Sake::TasksFile.parse(task_file).tasks
        uninstall_tasks(tasks)
        puts `sake -i #{task_file}`
      end
    end
  end
  
  # Not exactly the most effecient method, but it works
  desc "Install specified task(s) [t=git:push,git:pull]"
  task :task do
    specified_tasks = ENV['t'].split(',') rescue []
    uninstall_tasks(specified_tasks)
    
    Dir["**/*.sake"].each do |task_file|
      tasks = Sake::TasksFile.parse(task_file).tasks
      tasks.each do |task|
        if specified_tasks.include?(task.to_s)
         puts `sake -i #{task_file} #{task}`
        end
      end
    end
    
  end
  
  def uninstall_tasks(tasks)
    tasks.each {|t| `sake -u #{t}`}
  end
end
 
 
desc "Run latest source of task"
task :testrun do
  task_names = ARGV.grep(/(.+:)+/)
  
  task_names.each do |task_name|
    sake_file = task_name.gsub(':','/') + '.sake'
    import(sake_file) if File.exists?(sake_file)
 
    Rake.application.load_imports
    (task_names << Rake::Task[task_name].prerequisites).flatten!
  end
end
 
task :install => "install:all"
task :default => "install:all"