public
Description: Test-driven implementation of Transmission BitTorrent Client Web Interface
Homepage:
Clone URL: git://github.com/duncanbeevers/transmission-web-ui.git
transmission-web-ui / Rakefile
100644 125 lines (100 sloc) 4.064 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
require 'rubygems'
begin
  require 'rake'
rescue LoadError
  puts 'This script should only be accessed via the "rake" command.'
  puts 'Installation: gem install rake -y'
  exit
end
require 'rake'
require 'rake/clean'
 
$:.unshift File.dirname(__FILE__) + "/lib"
 
APP_VERSION = '0.0.1'
APP_NAME = 'transmission-web-ui'
RUBYFORGE_PROJECT = APP_NAME
APP_TEMPLATE = "#{APP_NAME}.js.erb"
APP_FILE_NAME= "#{APP_NAME}.js"
 
APP_ROOT = File.expand_path(File.dirname(__FILE__))
APP_SRC_DIR = File.join(APP_ROOT, 'src')
APP_DIST_DIR = File.join(APP_ROOT, 'dist')
APP_PKG_DIR = File.join(APP_ROOT, 'pkg')
 
 
unless ENV['rakefile_just_config']
 
task :default => [:dist, :package, :clean_package_source]
 
desc "Builds the distribution"
task :dist do
  $:.unshift File.join(APP_ROOT, 'lib')
  require 'protodoc'
  require 'fileutils'
  require 'sprockets'
  require 'json'
  FileUtils.mkdir_p APP_DIST_DIR
  
  secretary = Sprockets::Secretary.new(
    :root => APP_SRC_DIR,
    :asset_root => APP_DIST_DIR,
    :load_path => [ File.join(APP_SRC_DIR, '**/*') ],
    :source_files => [ File.join(APP_SRC_DIR, 'controllers/web_ui.js') ]
  )
  secretary.environment.constants.merge!('CONFIG_JSON' => secretary.environment.constants.to_json)
  Dir.chdir(APP_DIST_DIR) do
    secretary.concatenation.save_to(APP_FILE_NAME)
    FileUtils.copy_file APP_FILE_NAME, "#{APP_NAME}-#{APP_VERSION}.js"
  end
  FileUtils.copy_file "dist/#{APP_FILE_NAME}", "public/#{APP_FILE_NAME}"
  if File.directory?("website")
    FileUtils.mkdir_p "website/dist"
    FileUtils.copy_file "dist/#{APP_FILE_NAME}", "website/dist/#{APP_FILE_NAME}"
    FileUtils.copy_file "dist/#{APP_FILE_NAME}", "website/dist/#{APP_NAME}-#{APP_VERSION}.js"
  end
end
task :dist => :compress_script_loader
 
desc "Builds the distribution, runs the JavaScript unit + functional tests and collects their results."
task :test => [:dist, :test_units, :test_functionals]
 
require 'jstest'
desc "Runs all the JavaScript unit tests and collects the results"
JavaScriptTestTask.new(:test_units, 4711) do |t|
  testcases = ENV['TESTCASES']
  tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
  browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
 
  t.mount("/dist")
  t.mount("/src")
  t.mount("/test")
 
  Dir["test/unit/*_test.html"].sort.each do |test_file|
    tests = testcases ? { :url => "/#{test_file}", :testcases => testcases } : "/#{test_file}"
    test_filename = test_file[/.*\/(.+?)\.html/, 1]
    t.run(tests) unless tests_to_run && !tests_to_run.include?(test_filename)
  end
 
  %w( safari firefox ie konqueror opera ).each do |browser|
    t.browser(browser.to_sym) unless browsers_to_test && !browsers_to_test.include?(browser)
  end
end
 
desc "Runs all the JavaScript functional tests and collects the results"
JavaScriptTestTask.new(:test_functionals, 4712) do |t|
  testcases = ENV['TESTCASES']
  tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
  browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
 
  t.mount("/dist")
  t.mount("/src")
  t.mount("/test")
 
  Dir["test/functional/*_test.html"].sort.each do |test_file|
    tests = testcases ? { :url => "/#{test_file}", :testcases => testcases } : "/#{test_file}"
    test_filename = test_file[/.*\/(.+?)\.html/, 1]
    t.run(tests) unless tests_to_run && !tests_to_run.include?(test_filename)
  end
 
  %w( safari firefox ie konqueror opera ).each do |browser|
    t.browser(browser.to_sym) unless browsers_to_test && !browsers_to_test.include?(browser)
  end
end
 
task :clean_package_source do
  rm_rf File.join(APP_PKG_DIR, "#{APP_NAME}-#{APP_VERSION}")
end
 
 
task :compress_script_loader do
  root = File.dirname(__FILE__)
  src = File.join(root, 'src/lib/script_loader.js')
  jar = File.join(root, 'vendor/yuicompressor-2.4.2.jar')
  out = File.join(root, 'public/sl.js')
  pub = File.join(root, 'public/script_loader.js')
  
  system('java', '-jar', jar, '--type', 'js', '-o', out, src)
  FileUtils.cp(src, pub)
end
 
 
 
Dir['tasks/**/*.rake'].each { |rake| load rake }
end