sstephenson / prototype

Prototype JavaScript framework

This URL has Read+Write access

prototype / Rakefile
100755 212 lines (179 sloc) 6.478 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
require 'rake'
require 'rake/packagetask'
 
require 'yaml'
 
PROTOTYPE_ROOT = File.expand_path(File.dirname(__FILE__))
PROTOTYPE_SRC_DIR = File.join(PROTOTYPE_ROOT, 'src')
PROTOTYPE_DIST_DIR = File.join(PROTOTYPE_ROOT, 'dist')
PROTOTYPE_DOC_DIR = File.join(PROTOTYPE_ROOT, 'doc')
PROTOTYPE_TEMPLATES_DIR = File.join(PROTOTYPE_ROOT, 'templates')
PROTOTYPE_PKG_DIR = File.join(PROTOTYPE_ROOT, 'pkg')
PROTOTYPE_TEST_DIR = File.join(PROTOTYPE_ROOT, 'test')
PROTOTYPE_TEST_UNIT_DIR = File.join(PROTOTYPE_TEST_DIR, 'unit')
PROTOTYPE_TMP_DIR = File.join(PROTOTYPE_TEST_UNIT_DIR, 'tmp')
PROTOTYPE_VERSION = YAML.load(IO.read(File.join(PROTOTYPE_SRC_DIR, 'constants.yml')))['PROTOTYPE_VERSION']
 
$:.unshift File.join(PROTOTYPE_ROOT, 'vendor', 'sprockets', 'lib')
 
task :default => [:dist, :dist_helper, :package, :clean_package_source]
 
def sprocketize(path, source, destination = source)
  begin
    require "sprockets"
  rescue LoadError => e
    puts "\nYou'll need Sprockets to build Prototype. Just run:\n\n"
    puts " $ git submodule init"
    puts " $ git submodule update"
    puts "\nand you should be all set.\n\n"
  end
  
  secretary = Sprockets::Secretary.new(
    :root => File.join(PROTOTYPE_ROOT, path),
    :load_path => [PROTOTYPE_SRC_DIR],
    :source_files => [source]
  )
  
  secretary.concatenation.save_to(File.join(PROTOTYPE_DIST_DIR, destination))
end
 
desc "Builds the distribution."
task :dist do
  sprocketize("src", "prototype.js")
end
 
namespace :doc do
  desc "Builds the documentation."
  task :build => [:require] do
    
    TEMPLATES_ROOT = File.join(PROTOTYPE_ROOT, "vendor", "pdoc",
      "new_templates")
    
    TEMPLATES_DIRECTORY = File.join(TEMPLATES_ROOT, "html")
    
    require 'tempfile'
    begin
      require "sprockets"
    rescue LoadError => e
      puts "\nYou'll need Sprockets to build Prototype. Just run:\n\n"
      puts " $ git submodule init"
      puts " $ git submodule update"
      puts "\nand you should be all set.\n\n"
    end
    
    secretary = Sprockets::Secretary.new(
      :root => File.join(PROTOTYPE_ROOT, "src"),
      :load_path => [PROTOTYPE_SRC_DIR],
      :source_files => ["prototype.js"],
      :strip_comments => false
    )
    
    # Might as well re-use the unit tests' temp directory.
    mkdir_p PROTOTYPE_TMP_DIR
    temp_path = File.join(PROTOTYPE_TMP_DIR, "prototype.temp.js")
    secretary.concatenation.save_to(temp_path)
    rm_rf PROTOTYPE_DOC_DIR
    PDoc::Runner.new(temp_path, {
      :output => PROTOTYPE_DOC_DIR,
      :templates => File.join(PROTOTYPE_TEMPLATES_DIR, "html")
    }).run
    
    rm_rf temp_path
  end
  
  task :require do
    lib = 'vendor/pdoc/lib/pdoc'
    unless File.exists?(lib)
      puts "\nYou'll need PDoc to generate the documentation. Just run:\n\n"
      puts " $ git submodule init"
      puts " $ git submodule update"
      puts "\nand you should be all set.\n\n"
    end
    require lib
  end
end
 
task :doc => ['doc:build']
 
desc "Builds the updating helper."
task :dist_helper do
  sprocketize("ext/update_helper", "prototype_update_helper.js")
end
 
Rake::PackageTask.new('prototype', PROTOTYPE_VERSION) do |package|
  package.need_tar_gz = true
  package.package_dir = PROTOTYPE_PKG_DIR
  package.package_files.include(
    '[A-Z]*',
    'dist/prototype.js',
    'lib/**',
    'src/**',
    'test/**'
  )
end
 
task :clean_package_source do
  rm_rf File.join(PROTOTYPE_PKG_DIR, "prototype-#{PROTOTYPE_VERSION}")
end
 
task :test => ['test:build', 'test:run']
namespace :test do
  desc 'Runs all the JavaScript unit tests and collects the results'
  task :run => [:require] do
    testcases = ENV['TESTCASES']
    browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
    tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
    runner = UnittestJS::WEBrickRunner::Runner.new(:test_dir => PROTOTYPE_TMP_DIR)
 
    Dir[File.join(PROTOTYPE_TMP_DIR, '*_test.html')].each do |file|
      file = File.basename(file)
      test = file.sub('_test.html', '')
      unless tests_to_run && !tests_to_run.include?(test)
        runner.add_test(file, testcases)
      end
    end
    
    UnittestJS::Browser::SUPPORTED.each do |browser|
      unless browsers_to_test && !browsers_to_test.include?(browser)
        runner.add_browser(browser.to_sym)
      end
    end
    
    trap('INT') { runner.teardown; exit }
    runner.run
  end
  
  task :build => [:clean, :dist] do
    builder = UnittestJS::Builder::SuiteBuilder.new({
      :input_dir => PROTOTYPE_TEST_UNIT_DIR,
      :assets_dir => PROTOTYPE_DIST_DIR
    })
    selected_tests = (ENV['TESTS'] || '').split(',')
    builder.collect(*selected_tests)
    builder.render
  end
  
  task :clean => [:require] do
    UnittestJS::Builder.empty_dir!(PROTOTYPE_TMP_DIR)
  end
  
  task :require do
    lib = 'vendor/unittest_js/lib/unittest_js'
    unless File.exists?(lib)
      puts "\nYou'll need UnittestJS to run the tests. Just run:\n\n"
      puts " $ git submodule init"
      puts " $ git submodule update"
      puts "\nand you should be all set.\n\n"
    end
    require lib
  end
end
 
task :test_units do
  puts '"rake test_units" is deprecated. Please use "rake test" instead.'
end
 
task :build_unit_tests do
  puts '"rake test_units" is deprecated. Please use "rake test:build" instead.'
end
 
task :clean_tmp do
  puts '"rake clean_tmp" is deprecated. Please use "rake test:clean" instead.'
end
 
namespace :caja do
  task :test => ['test:build', 'test:run']
  
  namespace :test do
    task :run => ['rake:test:run']
 
    task :build => [:require, 'rake:test:clean', :dist] do
      builder = UnittestJS::CajaBuilder::SuiteBuilder.new({
        :input_dir => PROTOTYPE_TEST_UNIT_DIR,
        :assets_dir => PROTOTYPE_DIST_DIR,
        :whitelist_dir => File.join(PROTOTYPE_TEST_DIR, 'unit', 'caja_whitelists'),
        :html_attrib_schema => 'html_attrib.json'
      })
      selected_tests = (ENV['TESTS'] || '').split(',')
      builder.collect(*selected_tests)
      builder.render
    end
  end
  task :require => ['rake:test:require'] do
    lib = 'vendor/caja_builder/lib/caja_builder'
    unless File.exists?(lib)
      puts "\nYou'll need UnittestJS to run the tests. Just run:\n\n"
      puts " $ git submodule init"
      puts " $ git submodule update"
      puts "\nand you should be all set.\n\n"
    end
    require lib
  end
end