-
Notifications
You must be signed in to change notification settings - Fork 34
/
Rakefile
207 lines (194 loc) · 7.33 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
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
require 'rubygems'
require 'vendor/sprockets/lib/sprockets'
require 'rake'
require 'rake/packagetask'
require 'yaml'
require 'fileutils'
module ActiveJSHelper
ROOT_DIR = File.expand_path(File.dirname(__FILE__))
ASSETS_DIR = File.join(ROOT_DIR, 'assets')
SRC_DIR = File.join(ROOT_DIR, 'src')
DIST_DIR = File.join(ROOT_DIR, 'assets/downloads')
DOCS_DIR = File.join(ROOT_DIR, 'docs')
TEST_DIR = File.join(ROOT_DIR, 'test')
VENDOR_DIR = File.join(ROOT_DIR, 'vendor')
VERSION = YAML.load(IO.read(File.join(SRC_DIR, 'constants.yml')))['VERSION']
SOURCE_FILE_FOR_DOCS = File.join(DIST_DIR, 'source_for_docs.js')
INCLUDES = {
:swfaddress => [
File.join(VENDOR_DIR,'swfaddress/swfaddress.js')
],
:active_support_extensions => [
File.join(SRC_DIR,'dom.js'),
File.join(SRC_DIR,'active_support/inflector.js'),
File.join(SRC_DIR,'active_support/date.js'),
File.join(SRC_DIR,'active_support/json.js'),
File.join(SRC_DIR,'active_support/callback_queue.js'),
File.join(SRC_DIR,'active_support/request.js'),
File.join(SRC_DIR,'active_support/initializer.js')
]
}
DISTRIBUTION_FOR_DOC_GENERATION = [
File.join(SRC_DIR,'active_support.js'),
File.join(SRC_DIR,'builder.js'),
INCLUDES[:active_support_extensions],
File.join(SRC_DIR,'active_event.js'),
File.join(SRC_DIR,'active_routes.js'),
File.join(SRC_DIR,'active_record.js'),
File.join(SRC_DIR,'active_view.js')
]
DISTRIBUTIONS = {
'dom.js' => [
File.join(SRC_DIR,'dom.js')
],
'builder.js' => [
File.join(SRC_DIR,'dom.js')
],
'active_support.js' => [
File.join(SRC_DIR,'active_support.js'),
INCLUDES[:active_support_extensions]
],
'active_event.js' => [
File.join(SRC_DIR,'active_support.js'),
File.join(SRC_DIR,'active_event.js')
],
'active_view.js' => [
File.join(SRC_DIR,'active_support.js'),
File.join(SRC_DIR,'dom.js'),
File.join(SRC_DIR,'builder.js'),
File.join(SRC_DIR,'active_event.js'),
File.join(SRC_DIR,'active_view.js')
],
'active_routes.js' => [
File.join(SRC_DIR,'active_support.js'),
File.join(SRC_DIR,'active_event.js'),
File.join(SRC_DIR,'active_routes.js')
],
'active_record.js' => [
File.join(SRC_DIR,'active_support.js'),
INCLUDES[:active_support_extensions],
File.join(SRC_DIR,'active_event.js'),
File.join(SRC_DIR,'active_record.js')
],
'active.js' => [
File.join(SRC_DIR,'active_support.js'),
INCLUDES[:active_support_extensions],
File.join(SRC_DIR,'builder.js'),
File.join(SRC_DIR,'active_event.js'),
File.join(SRC_DIR,'active_routes.js'),
File.join(SRC_DIR,'active_view.js'),
File.join(SRC_DIR,'active_record.js'),
INCLUDES[:swfaddress]
],
#ActiveJS combined tests
File.join('..','..','test','test.js') => [
Dir[File.join(TEST_DIR,'**/setup.js')],
Dir[File.join(TEST_DIR,'**/*.js')].reject{|item| item.match(/setup\.js$/)}
].flatten.reject{|item| item.match(/\/test.js$/)}
}
#individual test building
[
'active_event',
'active_view',
'active_routes',
'active_record',
'active_support'
].each do |group|
DISTRIBUTIONS[File.join('..','..','test',group,'test.js')] = [
Dir[File.join(TEST_DIR,group + '/setup.js')],
Dir[File.join(TEST_DIR,group + '/*.js')].reject{|item| item.match(/setup\.js$/)}
].flatten.reject{|item| item.match(/\/test.js$/)}
end
def self.sprocketize
load_path = [SRC_DIR]
DISTRIBUTIONS.each_pair do |distribution_name,source_files|
flattened_source_files = source_files.clone.flatten
flattened_source_files.unshift('LICENSE')
secretary = Sprockets::Secretary.new(
:root => ROOT_DIR,
:load_path => load_path,
:source_files => flattened_source_files,
:strip_comments => false
)
secretary.concatenation.save_to(File.join(DIST_DIR, distribution_name))
end
end
def self.sprocketize_for_docs
flattened_source_files = DISTRIBUTION_FOR_DOC_GENERATION.clone.flatten
secretary = Sprockets::Secretary.new(
:root => ROOT_DIR,
:load_path => [SRC_DIR],
:source_files => flattened_source_files,
:strip_comments => false
)
secretary.concatenation.save_to(SOURCE_FILE_FOR_DOCS)
end
end
desc "Builds the distribution."
task :dist, :copy_locations do |task,arguments|
puts "Building ActiveJS distributions with Sprockets"
ActiveJSHelper.sprocketize
ActiveJSHelper::DISTRIBUTIONS.each_pair do |target,payload|
puts "Built #{File.expand_path(File.join(ActiveJSHelper::DIST_DIR,target))}"
end
copy_locations = (arguments[:copy_locations] || '').split(',')
copy_locations.each do |location_pair|
source, target = location_pair.split(':')
source = File.expand_path(File.join(ActiveJSHelper::DIST_DIR,source))
target = File.expand_path(target)
FileUtils.copy(
source,
target
)
puts "Copied #{source} to #{target}"
end
puts "Task complete."
end
desc "Builds the documentation"
task :docs do
require 'vendor/pdoc/lib/pdoc'
rm_rf Dir.glob(File.join(ActiveJSHelper::DOCS_DIR, "*"))
ActiveJSHelper.sprocketize_for_docs
PDoc.run({
:source_files => [ActiveJSHelper::SOURCE_FILE_FOR_DOCS],
:destination => ActiveJSHelper::DOCS_DIR,
:syntax_highlighter => :pygments,
:markdown_parser => :bluecloth,
:src_code_href => proc { |doc|
"http://github.com/aptana/activejs/blob/#{hash}/#{doc.file}#LID#{doc.line_number}"
},
:pretty_urls => false,
:bust_cache => false,
:name => 'ActiveJS',
:short_name => 'ActiveJS',
:home_url => 'http://activejs.org',
:doc_url => 'http://activejs.org',
:version => ActiveJSHelper::VERSION,
:index_title => 'ActiveJS: JavaScript Application Framework',
:index_page => 'README.markdown',
:index_header => '<a href="http://activejs.org/downloads/active.js" id="header_logo"><img src="http://activejs.org/images/activejs.gif"/></a>',
:footer => '<div id="footer_logos"><a href="http://syntacticx.com"><img src="http://activejs.org/images/syntacticx.gif" style="border:none;"/></a><a href="http://aptana.org/"><img src="http://activejs.org/images/aptana.gif" style="border:none;"/></a><a href="http://dashwire.com/"><img src="http://activejs.org/images/dashwire.gif" style="border:none;"/></a></div>',
:stylesheets => ['docs']
})
FileUtils.rm(ActiveJSHelper::SOURCE_FILE_FOR_DOCS)
FileUtils.cp_r(Dir.glob(File.join(ActiveJSHelper::ASSETS_DIR,"**")), ActiveJSHelper::DOCS_DIR)
end
desc "Builds the distributions, and documentation, and copies the generated docs to a location of your choosing"
task :deploy, :target do |task,arguments|
Rake::Task["dist"].reenable
Rake::Task["dist"].invoke
Rake::Task["docs"].reenable
Rake::Task["docs"].invoke
rm_rf Dir.glob(File.join(arguments[:target],"*"))
FileUtils.cp_r(Dir.glob(File.join(ActiveJSHelper::DOCS_DIR,"*")),File.join(arguments[:target]))
end
task :compress do
require 'yui/compressor'
compressor = YUI::JavaScriptCompressor.new(:munge => true)
ActiveJSHelper::DISTRIBUTIONS.each_pair do |name,payload|
src = File.read(File.join(ActiveJSHelper::DIST_DIR,name))
File.open(File.join(ActiveJSHelper::DIST_DIR,name.gsub(/\.js$/,'.min.js')),'w') do |file|
file.write(compressor.compress(src))
end
end
end