-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
executable file
·137 lines (126 loc) · 4.27 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
require 'rake'
require 'rake/packagetask'
require 'yaml'
require 'sprockets'
require 'fileutils'
module ActiveJSHelper
ROOT_DIR = File.expand_path(File.dirname(__FILE__))
SRC_DIR = File.join(ROOT_DIR, 'src')
DIST_DIR = File.join(ROOT_DIR, 'dist')
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')))['ACTIVE_JS_VERSION']
INCLUDES = {
:swfaddress => [
File.join(VENDOR_DIR,'swfaddress/swfaddress.js'),
File.join(SRC_DIR,'active_view/routing.js')
],
:active_support_extensions => [
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'),
]
}
DISTRIBUTIONS = {
'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,'active_event.js'),
File.join(SRC_DIR,'active_view.js'),
INCLUDES[:swfaddress]
],
'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,'active_event.js'),
File.join(SRC_DIR,'active_view.js'),
File.join(SRC_DIR,'active_routes.js'),
File.join(SRC_DIR,'active_record.js')
],
#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
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
if !arguments[:copy_locations].nil?
arguments[:copy_locations].split(',').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
end
puts "Task complete."
puts "copy active_record.js to lib"
FileUtils.copy "dist/active_record.js", "../Resources/tests/"
end
task :docs do
require 'vendor/pdoc/lib/pdoc'
PDoc.run({
:source_files => File.join(ActiveJSHelper::DIST_DIR,'active.js'),
:destination => ActiveJSHelper::DOCS_DIR,
:index_page => 'README.markdown',
:syntax_highlighter => :pygments,
:markdown_parser => :maruku
})
end