forked from nhowell/jq-wysihat
/
Rakefile
102 lines (74 loc) · 2.51 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
require 'rake'
require 'rake/clean'
require 'rake/testtask'
CLEAN.include 'test/unit/tmp'
CLOBBER.include 'dist'
CLOBBER.include 'doc'
WYSIHAT_ROOT = File.expand_path(File.dirname(__FILE__))
WYSIHAT_SRC_DIR = File.join(WYSIHAT_ROOT, 'src')
# Distribution
file 'dist/jquery.js' => :sprockets do |t|
jquery_src_dir = "#{WYSIHAT_ROOT}/vendor/jquery"
env = Sprockets::Environment.new
env.prepend_path jquery_src_dir
FileUtils.mkdir_p File.dirname(t.name)
File.open(t.name, 'w') {|f| f.write(env['jquery-1.6.4.js'].to_s) }
end
file 'dist/jq-wysihat.js' => Dir['src/**/*'] + [:sprockets] do |t|
env = Sprockets::Environment.new
env.prepend_path WYSIHAT_SRC_DIR
FileUtils.mkdir_p File.dirname(t.name)
File.open(t.name, 'w') {|f| f.write(env['wysihat.js'].to_s) }
end
task :default => :dist
desc "Builds the distribution."
task :dist => ['dist/jquery.js', 'dist/jq-wysihat.js']
# Documentation
desc "Builds the documentation."
file 'doc' => Dir['src/**/*'] + [:sprockets, :pdoc] do
require 'tempfile'
Tempfile.open('pdoc') do |temp|
env = Sprockets::Environment.new
env.prepend_path WYSIHAT_SRC_DIR
File.open(temp.path, 'w') {|f| f.write(env['wysihat.js'].to_s) }
PDoc::Runner.new(temp.path, :destination => "#{WYSIHAT_ROOT}/doc").run
end
end
# Tests
file 'test/unit/tmp/tests' => Dir['test/unit/*.js'] + [:unittest_js, :dist] do
FileUtils.mkdir_p File.dirname('test/unit/tmp/tests')
builder = UnittestJS::Builder::SuiteBuilder.new({
:input_dir => "#{WYSIHAT_ROOT}/test/unit",
:assets_dir => "#{WYSIHAT_ROOT}/dist"
})
builder.collect
builder.render
end
desc "Builds the distribution, runs the JavaScript unit tests and collects their results."
task :test => 'test/unit/tmp/tests'
# Vendored libs
task :sprockets => 'vendor/sprockets/lib/sprockets.rb' do
$:.unshift File.expand_path('vendor/sprockets/lib', WYSIHAT_ROOT)
require 'sprockets'
end
task :pdoc => 'vendor/pdoc/lib/pdoc.rb' do
$:.unshift File.expand_path('vendor/pdoc/lib', WYSIHAT_ROOT)
require 'pdoc'
end
task :unittest_js => 'vendor/unittest_js/lib/unittest_js.rb' do
$:.unshift File.expand_path('vendor/unittest_js/lib', WYSIHAT_ROOT)
require 'unittest_js'
end
file 'vendor/pdoc/lib/pdoc.rb' do
Rake::Task['update_submodules'].invoke
end
file 'vendor/sprockets/lib/sprockets.rb' do
Rake::Task['update_submodules'].invoke
end
file 'vendor/unittest_js/lib/unittest_js.rb' do
Rake::Task['update_submodules'].invoke
end
task :update_submodules do
system "git submodule init"
system "git submodule update"
end