forked from rightjs/rightjs-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
184 lines (155 loc) · 5.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
#
# Here are some ruby based building tasks
#
#
# You can pass options with the building script to exclude some blocks, like that
#
# rake build OPTIONS=no-dom,no-form,no-fx,no-xhr,no-cookie
#
# Use the 'server' option to build the server version
#
# rake build OPTIONS=server
#
# See the $js_sources list keys for the options
#
require 'rake'
require 'fileutils'
require 'util/build/rutil'
RIGHTJS_VERSION = '2.0.0'
BUILD_DIR = 'build'
BUILD_FILE = 'right'
## getting the sources list
initializer = File.read("src/__init__.js")[/\{.+\}/m]
$build_options = []
$js_sources = {}
initializer.scan(/([a-z]+):\s*\[([^\]]+?)\]/).each do |item|
$build_options << item[0]
$js_sources[item[0].to_sym] = item[1].scan(/('|")([\w\d\_\/]+)\1/).collect{ |match|
match[1]
}
end
$options = ((ENV['OPTIONS'] || '').split('=').last || '').split(/\s*,\s*/)
$options.reject!{ |o| o == 'no-olds'} if $options.include?('safe')
######################################################################
# Cleaning up the build directory
######################################################################
desc "Cleans up the build directory"
task :clean do
unless $options == ['server'] && File.exists?(BUILD_DIR)
puts ' * Creating the build dir'
FileUtils.rm_rf BUILD_DIR
Dir.mkdir BUILD_DIR
end
end
######################################################################
# Packing the souce code
######################################################################
desc "Packs the source code"
task :pack do
Rake::Task['clean'].invoke
puts " * Composing the source file"
modules = []
files = []
$build_options.each do |package|
unless $options.include?("no-#{package}")
files += $js_sources[package.to_sym].collect{ |f| "src/#{f}.js" }
modules << package
end
end
# initializing the packing utility
$rutil = RUtil.new("dist/header.js", "dist/layout.js", {
:version => RIGHTJS_VERSION, :modules => modules.join('", "')
})
$rutil.pack(files)
# hooking up the olds patch loader if necessary
if $options.include?('no-olds')
$rutil.patch do |source|
source += File.read("src/olds/loader.js")
end
end
$rutil.write("#{BUILD_DIR}/#{BUILD_FILE}.js")
end
######################################################################
# Running the syntax check
######################################################################
desc "Runs JSLint on the source code"
task :check do
Rake::Task['pack'].invoke
puts " * Running the jslint check"
$rutil.check "dist/lint.js"
end
######################################################################
# Creating a standard build
######################################################################
desc "Builds the source code"
task :build do
if $options.include?('safe')
Rake::Task['build:safe'].invoke
elsif $options.include?('server')
Rake::Task['build:server'].invoke
else
Rake::Task['pack'].invoke
puts " * Compressing the source code"
$rutil.compile
if $options.include?('no-olds')
Rake::Task['build:olds'].invoke
end
end
end
######################################################################
# Creating the olds module
######################################################################
desc "Builds the old browsers support module"
task 'build:olds' do
puts " * Creating the old browsers support module"
@util = RUtil.new("dist/header.olds.js")
@util.pack($js_sources[:olds].collect{|f| "src/#{f}.js"})
@util.write("#{BUILD_DIR}/#{BUILD_FILE}-olds.js")
@util.compile
end
######################################################################
# Creating the safemode build
######################################################################
desc "Builds the safe-mode version"
task 'build:safe' do
# creating a normal build
Rake::Task['pack'].invoke
puts " * Compressing the source code"
$rutil.compile
# creating the safe-mode build
puts " * Creating the safe-mode build"
@rutil = RUtil.new("dist/header.safe.js", "dist/layout.safe.js")
@rutil.pack(["#{BUILD_DIR}/#{BUILD_FILE}.js"]) do |source|
source = source.gsub!(/\A\s*\/\*.*?\*\/\s*/m, '').strip
"'#{source.gsub("\\","\\\\\\\\").gsub("'","\\\\'").gsub("\n", " '+\n'")}'"
end
@rutil.write("#{BUILD_DIR}/#{BUILD_FILE}-safe.js")
@rutil.compile
end
######################################################################
# Creating the server-side build
######################################################################
desc "Bulds the server-side version"
task 'build:server' do
Rake::Task['clean'].invoke
puts " * Creating the server side version"
@util = RUtil.new("dist/header.server.js", "dist/layout.server.js")
@util.pack($js_sources[:core].collect{|f| "src/#{f}.js"}) do |source|
# removing dom related util methods and hacks
source.gsub! /\n\/\/\s+!#server:begin.+?\/\/\s+!#server:end\n/m, ''
source.gsub! /\/\*\*\s+!#server.+?(?=\/\*\*)/m, ''
source.gsub! /\n[^\n]+\/\/\s*!#server\s*(\n)/m, '\1'
source
end
@util.write("#{BUILD_DIR}/#{BUILD_FILE}-server.js")
end
######################################################################
# Checking the Harmony
######################################################################
desc "Checks the Harmony compatibility"
task "harm" do
Rake::Task['pack'].invoke
require 'harmony'
page = Harmony::Page.new
page.load('build/right-src.js')
end