dyoder / pages

Waves-based CMS

This URL has Read+Write access

commit  3611209356661cadbefbb8e9625d38bcc0f64d90
tree    48c54cfbeabd3e70a5aea02147f5ce8b5993f3a3
parent  366011771bc90f6c77f07180bf5ca15497a29e9d
pages / Rakefile
100644 138 lines (114 sloc) 3.665 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env ruby
#
# Warning: This file is clobbered when you update your
# application with the waves script. Accordingly, you may
# wish to keep your tasks in .rb or .rake files in lib/tasks
#!/usr/bin/env ruby
require 'rubygems'
waves = [
    (WAVES if defined? WAVES), ENV[ 'WAVES'], './waves'
].compact.map { |dir| File.join(dir, 'lib') }.find(&File.method(:directory?))
if waves
    $: << waves
    waves = File.join( waves, 'waves' )
else
    waves = 'waves'
end
require waves
require 'runtime/console'
begin
  Waves::Console.load(:mode => ENV['mode'])
 
  # load tasks from waves framework
  %w( generate gem ).each { |task| require "tasks/#{task}.rb" }
 
  # load tasks from this app's lib/tasks
  Dir["lib/tasks/*.{rb,rake}"].each { |task| require task }
  
rescue LoadError => e
  if e.message == 'no such file to load -- waves'
    puts "Can't find Waves source. Install gem, freeze Waves, or define WAVES in startup.rb"
    puts
  else
    raise e
  end
end
 
namespace :dep do
 
  desc "check if all the dependencies specified in the configuration"
  task :check do
 
    gems = Gem::SourceIndex.from_installed_gems.to_a.to_s
    missing = Array.new
 
    puts "\nApplication-level dependencies:"
    puts " ('*' means gem is installed and available)"
    
    Waves.config.dependencies.each do |dep|
      pattern = /=#{dep}\s/
      print "\t#{dep}:\t\t["
      unless pattern.match(gems).nil?
        print "*]\n"
      else
        print " ]\n"
      end
    end
  end
  
  desc "install any missing dependencies specified in the configuration"
  task :install do
 
    gems = Gem::SourceIndex.from_installed_gems.to_a.to_s
    missing = Array.new
 
    Waves.config.dependencies.each do |dep|
      pattern = /=#{dep}\s/
      missing << dep if pattern.match(gems).nil?
    end
 
    missing.each do |dep|
      puts "Installing dependency: #{dep}"
      begin
        require 'rubygems/dependency_installer'
        if Gem::RubyGemsVersion =~ /^1\.0\./
          Gem::DependencyInstaller.new(dep).install
        else
          # as of 1.1.0
          Gem::DependencyInstaller.new.install(dep)
        end
      rescue LoadError # < rubygems 1.0.1
        require 'rubygems/remote_installer'
        Gem::RemoteInstaller.new.install(dep)
      end
    end
 
    puts "Environment complete. Nothing to install." if missing.empty?
 
  end
 
end
 
namespace :waves do
  
  desc "freeze src=<wherever> to ./waves"
  task :freeze do
 
    target = "#{Dir.pwd}/waves"
    src = ENV['src']
    raise "Please specify the location of waves using src=wherever" unless src
    raise "No directory found at '#{src}'" unless File.directory?(src)
      
    items = FileList["#{src}/*"]
    puts "Freezing from: #{src}"
    items.each do |item|
      puts "copying #{item}"
      cp_r item, target
    end
    
  end
  
  desc "unfreeze (i.e. delete) the waves source at ./waves"
  task :unfreeze do
    frozen = "#{Dir.pwd}/waves"
    rm_r frozen if File.exist?(frozen)
  end
  
  # Convenience task to allow you to freeze the current Waves
  # source without knowing where it is. This task only gets
  # defined when the Rakefile successfully loaded Waves and if
  # there's nothing in the way at ./waves
  if defined?(WAVES) && !File.exist?("#{Dir.pwd}/waves")
    namespace :freeze do
      desc "freeze current Waves source to ./waves"
      task :current do
        target = "#{Dir.pwd}/waves"
        current = File.expand_path( WAVES )
        items = FileList["#{current}/*"]
        puts "Freezing from: #{current}"
        items.each do |item|
          puts "copying #{item}"
          cp_r item, target
        end
 
      end
    end
  end
  
end