This repository has been archived by the owner on Nov 10, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Rakefile
375 lines (298 loc) · 8.65 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# encoding: utf-8
require "tmpdir"
task :watch do
sh "bundle exec guard"
end
task :default => [
"debug",
"debug/manifest.json",
"debug/lib",
"debug/app.js",
"debug/app_core.js",
"debug/cs_addlink.js",
"img:build",
"ui:build",
"view:build",
"zombie:build",
"write:build",
"test:build",
"jquery:build"
]
task :clean do
rm_f "./read.crx_2.zip"
rm_rf "debug"
Rake::Task["jquery:clean"].invoke
end
task :pack do
require "json"
MANIFEST = JSON.parse(open("src/manifest.json").read)
Rake::Task[:clean].invoke
Rake::Task[:default].invoke
Rake::Task["test:run"].invoke
Rake::Task[:scan].invoke
Dir.mktmpdir do |tmpdir|
cp_r "debug", "#{tmpdir}/debug"
rm_r "#{tmpdir}/debug/test"
puts "秘密鍵のパスを入力して下さい"
pem_path = STDIN.gets
sh "google-chrome --pack-extension=#{tmpdir}/debug --pack-extension-key=#{pem_path}"
mv "#{tmpdir}/debug.crx", "read.crx_2.#{MANIFEST["version"]}.crx"
end
end
task :scan do
sh "clamscan -ir debug"
end
def debug_id
require "digest"
hash = Digest::SHA256.hexdigest(File.absolute_path("debug"))
hash[0...32].tr("0-9a-f", "a-p")
end
def haml(src, output)
sh "bundle exec haml -r ./haml_requirement.rb -q #{src} #{output}"
end
def scss(src, output)
sh "bundle exec scss --style compressed #{src} #{output}"
end
def coffee(src, output)
if src.is_a? Array
src = src.join(" ")
end
sh "node_modules/.bin/coffee -cbj #{output} #{src}"
end
def typescript(src, output)
unless src.is_a? Array
src = [src]
end
src.each {|a|
sh "node_modules/.bin/tsc --target ES5 #{a}"
}
tmp = src.map {|a| a.gsub(/\.ts$/, ".js") }
tmp = tmp.sort {|a, b| a.split(".").length - b.split(".").length }
sh "cat #{tmp.join " "} > #{output}"
rm tmp
end
def file_ct(target, src)
if !src.is_a? Array
src = [src]
end
file target => src do
Dir.mktmpdir do |tmpdir|
coffeeSrc = src.clone
coffeeSrc.reject! {|a| (/\.coffee$/ =~ a) == nil }
tsSrc = src.clone
tsSrc.reject! {|a| (/\.ts$/ =~ a) == nil }
coffee(coffeeSrc, "#{tmpdir}/_coffee.js")
typescript(tsSrc, "#{tmpdir}/ts.js")
sh "cat #{tmpdir}/ts.js #{tmpdir}/_coffee.js > #{target}"
end
end
end
def file_coffee(target, src)
file target => src do
coffee(src, target)
end
end
def file_copy(target, src)
file target => src do
cp src, target
end
end
def file_typescript(target, src)
file target => src do
typescript(src, target)
end
end
rule ".html" => "%{^debug/,src/}X.haml" do |t|
haml(t.prerequisites[0], t.name)
end
rule ".css" => "%{^debug/,src/}X.scss" do |t|
scss(t.prerequisites[0], t.name)
end
rule ".js" => "%{^debug/,src/}X.coffee" do |t|
coffee(t.prerequisites[0], t.name)
end
rule ".png" => "src/image/svg/%{_\\d+x\\d+(?:_[a-fA-F0-9]+)?(?:_r\\-?\\d+)?$,}n.svg" do |t|
/_(\d+)x(\d+)(?:_([a-fA-F0-9]*))?(?:_r(\-?\d+))?\.png$/ =~ t.name
command = "convert -background transparent"
if $3
command += " -fill '##{$3}' -opaque '#333'"
end
if $4
command += " -rotate '#{$4}'"
end
command += " -resize #{$1}x#{$2} #{t.prerequisites[0]} #{t.name}"
sh command
end
directory "debug"
directory "debug/lib"
file_copy "debug/manifest.json", "src/manifest.json"
file_typescript "debug/app.js", "src/app.ts"
file_ct "debug/app_core.js", FileList["src/core/*.coffee", "src/core/*.ts"]
#img
namespace :img do
task :build => [
"debug/img",
"debug/img/favicon.ico",
"debug/img/read.crx_128x128.png",
"debug/img/read.crx_48x48.png",
"debug/img/read.crx_16x16.png",
"debug/img/close_16x16.png",
"debug/img/dummy_1x1.png",
"debug/img/loading.svg",
"debug/img/arrow_19x19_333_r90.png",
"debug/img/arrow_19x19_333_r-90.png",
"debug/img/search2_19x19_777.png",
"debug/img/star_19x19_333.png",
"debug/img/star_19x19_007fff.png",
"debug/img/reload_19x19_333.png",
"debug/img/pencil_19x19_333.png",
"debug/img/menu_19x19_333.png",
"debug/img/arrow_19x19_ddd_r90.png",
"debug/img/arrow_19x19_ddd_r-90.png",
"debug/img/search2_19x19_aaa.png",
"debug/img/star_19x19_ddd.png",
"debug/img/star_19x19_f93.png",
"debug/img/reload_19x19_ddd.png",
"debug/img/pencil_19x19_ddd.png",
"debug/img/menu_19x19_ddd.png"
]
directory "debug/img"
file "debug/img/favicon.ico" => "src/image/svg/read.crx.svg"do |t|
sh "convert #{t.prerequisites[0]}\
\\( -clone 0 -resize 16x16 \\)\
\\( -clone 0 -resize 32x32 \\)\
-delete 0\
#{t.name}"
end
file "debug/img/read.crx_128x128.png" => "src/image/svg/read.crx.svg" do |t|
sh "convert\
-background transparent\
-resize 96x96\
-extent 128x128-16-16\
src/image/svg/read.crx.svg #{t.name}"
end
file_copy "debug/img/loading.svg", "src/image/svg/loading.svg"
end
#ui
namespace :ui do
task :build => ["debug/ui.css", "debug/ui.js"]
file "debug/ui.css" => FileList["src/common.scss"].include("src/ui/*.scss") do |t|
scss("src/ui/ui.scss", t.name)
end
file_ct "debug/ui.js", FileList["src/ui/*.coffee", "src/ui/*.ts"]
end
#View
namespace :view do
directory "debug/view"
view = [
"debug/view",
"debug/view/module.js"
]
FileList["src/view/*.haml"].each {|x|
view.push(x.sub(/^src\//, "debug/").sub(/\.haml$/, ".html"))
}
FileList["src/view/*.coffee"].each {|x|
view.push(x.sub(/^src\//, "debug/").sub(/\.coffee$/, ".js"))
}
FileList["src/view/*.scss"].each {|scss_path|
css_path = scss_path.sub(/^src\//, "debug/").sub(/\.scss$/, ".css")
view.push(css_path)
file css_path => ["src/common.scss", scss_path] do |t|
scss(scss_path, t.name)
end
}
task :build => view
end
#Zombie
namespace :zombie do
task :build => ["debug/zombie.html", "debug/zombie.js"]
end
#Write
namespace :write do
task :build => [
"debug/write",
"debug/write/write.html",
"debug/write/write.css",
"debug/write/write.js",
"debug/write/cs_write.js"
]
directory "debug/write"
file "debug/write/write.css" => [
"src/common.scss",
"src/write/write.scss"
] do |t|
scss("src/write/write.scss", t.name)
end
file_ct "debug/write/write.js", [
"src/core/URL.ts",
"src/core/Ninja.coffee",
"src/write/write.coffee"
]
file_ct "debug/write/cs_write.js", [
"debug/app.js",
"src/core/URL.ts",
"src/write/cs_write.coffee"
]
end
namespace :test do
task :build => [
"debug/test",
"debug/test/jasmine",
"debug/test/jasmine/jasmine.js",
"debug/test/jasmine/jasmine-html.js",
"debug/test/jasmine/jasmine.css",
"debug/test/qunit",
"debug/test/qunit/qunit.js",
"debug/test/qunit/qunit.css",
"debug/test/qunit/qunit-step.js",
"debug/test/jquery.mockjax.js",
"debug/test/test.html",
"debug/test/jasmine-exec.js",
"debug/test/test.js",
"debug/test/spec.js",
"debug/test/message_test.html",
"debug/test/message_test.js"
]
task :run, :filter do |t, args|
require "cgi"
url = "chrome-extension://#{debug_id}/test/test.html"
if args[:filter]
tmp = CGI.escape(args[:filter]).gsub("\+", "%20")
url += "?filter=#{tmp}&spec=#{tmp}"
end
sh "google-chrome '#{url}'"
end
directory "debug/test"
file_copy "debug/test/jquery.mockjax.js", "lib/jquery-mockjax/jquery.mockjax.js"
directory "debug/test/jasmine"
file_copy "debug/test/jasmine/jasmine.js", "lib/jasmine/lib/jasmine-core/jasmine.js"
file_copy "debug/test/jasmine/jasmine-html.js", "lib/jasmine/lib/jasmine-core/jasmine-html.js"
file_copy "debug/test/jasmine/jasmine.css", "lib/jasmine/lib/jasmine-core/jasmine.css"
file_coffee "debug/test/spec.js", FileList["src/test/*.spec.coffee"]
directory "debug/test/qunit"
file_copy "debug/test/qunit/qunit.js", "lib/qunit/qunit/qunit.js"
file_copy "debug/test/qunit/qunit.css", "lib/qunit/qunit/qunit.css"
file_copy "debug/test/qunit/qunit-step.js", "lib/qunit/addons/step/qunit-step.js"
file_coffee "debug/test/test.js", FileList["src/test/test_*.coffee"]
end
namespace :jquery do
task :build => "debug/lib/jquery/jquery.min.js"
task :clean do
rm_rf "debug/lib/jquery"
cd "lib/jquery" do
sh "git checkout -f"
sh "git clean -fdx -e node_modules/"
end
end
file "debug/lib/jquery/jquery.min.js" => "lib/jquery_delegate_middle_click.patch" do
Rake::Task["jquery:clean"].invoke
cd "lib/jquery" do
sh "npm install"
sh "git apply ../jquery_delegate_middle_click.patch"
sh "env PATH=$PATH:../../node_modules/.bin/ grunt"
sh "sed -i -e \"3a /* このファイルはread.crx 2用にawefが改造した物です */\" dist/jquery.min.js"
end
mkdir_p "debug/lib/jquery"
cp "lib/jquery/dist/jquery.min.js", "debug/lib/jquery/jquery.min.js"
end
end