forked from jeffkreeftmeijer/wysihat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
154 lines (127 loc) · 4.67 KB
/
Rakefile
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
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
WYSIHAT_ROOT = File.expand_path(File.dirname(__FILE__))
WYSIHAT_SRC_DIR = File.join(WYSIHAT_ROOT, 'src')
WYSIHAT_DIST_DIR = File.join(WYSIHAT_ROOT, 'dist')
WYSIHAT_DOC_DIR = File.join(WYSIHAT_ROOT, 'doc')
WYSIHAT_WEBSITE_DIR = File.join(WYSIHAT_ROOT, 'website')
WYSIHAT_TEST_DIR = File.join(WYSIHAT_ROOT, 'test')
WYSIHAT_TEST_UNIT_DIR = File.join(WYSIHAT_TEST_DIR, 'unit')
WYSIHAT_TMP_DIR = File.join(WYSIHAT_TEST_UNIT_DIR, 'tmp')
desc "Update git submodules"
task :update_submodules do
system("git submodule init")
system("git submodule update")
end
task :default => :dist
desc "Builds the distribution."
task :dist => ["sprocketize:prototype", "sprocketize:wysihat"]
task :watch do
ENV['WATCH'] = "1"
Rake::Task["sprocketize:wysihat"].invoke
end
namespace :sprocketize do
task :dist_dir do
FileUtils.mkdir_p(WYSIHAT_DIST_DIR)
end
task :wysihat => [:update_submodules, :dist_dir] do
require File.join(WYSIHAT_ROOT, "vendor", "sprockets", "lib", "sprockets")
require File.join(WYSIHAT_ROOT, "vendor", "sprockwatch", "lib", "sprockwatch")
secretary = Sprockets::Secretary.new(
:root => File.join(WYSIHAT_ROOT, "src"),
:load_path => [WYSIHAT_SRC_DIR],
:source_files => ["wysihat.js"]
)
save = lambda {
secretary.concatenation.save_to(File.join(WYSIHAT_DIST_DIR, "wysihat.js"))
}
ENV['WATCH'] ? secretary.watch!(&save) : save.call
end
task :prototype => [:update_submodules, :dist_dir] do
require File.join(WYSIHAT_ROOT, "vendor", "sprockets", "lib", "sprockets")
prototype_root = File.join(WYSIHAT_ROOT, "vendor", "prototype")
prototype_src_dir = File.join(prototype_root, 'src')
secretary = Sprockets::Secretary.new(
:root => File.join(prototype_root, "src"),
:load_path => [prototype_src_dir],
:source_files => ["prototype.js"]
)
secretary.concatenation.save_to(File.join(WYSIHAT_DIST_DIR, "prototype.js"))
end
end
desc "Empties the output directory and builds the documentation."
task :doc => 'doc:build'
namespace :doc do
desc "Builds the documentation"
task :build => [:update_submodules, :clean] do
require File.join(WYSIHAT_ROOT, "vendor", "sprockets", "lib", "sprockets")
require File.join(WYSIHAT_ROOT, "vendor", "pdoc", "lib", "pdoc")
require 'tempfile'
Tempfile.open("pdoc") do |temp|
secretary = Sprockets::Secretary.new(
:root => File.join(WYSIHAT_ROOT, "src"),
:load_path => [WYSIHAT_SRC_DIR],
:source_files => ["wysihat.js"],
:strip_comments => false
)
secretary.concatenation.save_to(temp.path)
PDoc::Runner.new(temp.path,
:output => WYSIHAT_DOC_DIR,
:templates => WYSIHAT_WEBSITE_DIR
).run
end
end
task :publish => :build do
Dir.chdir(WYSIHAT_DOC_DIR) do
system "git init"
system "git add ."
system "git commit -m \"import docs\""
system "git remote add origin [email protected]:josh/wysihat.git"
system "git checkout -b gh-pages"
system "git push -f origin gh-pages"
end
end
desc "Empties documentation directory"
task :clean do
rm_rf WYSIHAT_DOC_DIR
end
end
desc "Builds the distribution, runs the JavaScript unit tests and collects their results."
task :test => ['test:build', 'test:run']
namespace :test do
task :run 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 => WYSIHAT_TMP_DIR)
Dir[File.join(WYSIHAT_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
require File.join(WYSIHAT_ROOT, "vendor", "unittest_js", "lib", "unittest_js")
builder = UnittestJS::Builder::SuiteBuilder.new({
:input_dir => WYSIHAT_TEST_UNIT_DIR,
:assets_dir => WYSIHAT_DIST_DIR
})
selected_tests = (ENV['TESTS'] || '').split(',')
builder.collect(*selected_tests)
builder.render
end
task :clean do
require File.join(WYSIHAT_ROOT, "vendor", "unittest_js", "lib", "unittest_js")
UnittestJS::Builder.empty_dir!(WYSIHAT_TMP_DIR)
end
end