forked from tildeio/router.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
80 lines (59 loc) · 2.01 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
directory "dist"
def replace_debug(file)
content = File.read(file)
content.gsub!(%r{^ *// DEBUG GROUP (.*) *$}, 'console.group(\1);')
content.gsub!(%r{^ *// END DEBUG GROUP *$}, 'console.groupEnd();')
content.gsub!(%r{^( *)// DEBUG (.*) *$}, '\1debug(\2);')
content.gsub!(%r{^ */\*\* IF DEBUG\n}, "")
content.gsub!(%r{ *END IF \*\*/\n}, "")
content
end
require "bundler/setup"
require "js_module_transpiler"
require 'qunit-cli-runner'
directory "dist"
def file_task(type)
filename = ["dist/router"]
filename << type unless type == "globals"
filename << "js"
filename = filename.join(".")
file filename => ["dist", "lib/router.js"] do
router = File.read("lib/router.js")
open filename, "w" do |file|
converter = JsModuleTranspiler::Compiler.new(router, "router", into: "Router", imports: { "route-recognizer" => "RouteRecognizer" })
file.puts converter.send("to_#{type}")
end
end
debug_filename = filename.sub(/\.js$/, ".debug.js")
file debug_filename => ["dist", "lib/router.js"] do
router = replace_debug("lib/router.js")
open debug_filename, "w" do |file|
converter = JsModuleTranspiler::Compiler.new(router, "router", into: "Router", imports: { "route-recognizer" => "RouteRecognizer" })
file.puts converter.send("to_#{type}")
end
end
min_filename = filename.sub(/\.js$/, ".min.js")
file min_filename => filename do
output = `cat #{filename} | uglifyjs`
open min_filename, "w" do |file|
file.puts output
end
end
end
file_task "globals"
file_task "amd"
file_task "cjs"
task :debug => ["dist/router.debug.js", "dist/router.amd.debug.js", "dist/router.cjs.debug.js"]
task :build => ["dist/router.js", "dist/router.amd.js", "dist/router.cjs.js"]
task :release => [:debug, :build]
task :browser_test, :debug do |task, args|
if args["debug"]
sh "open tests/index.debug.html"
else
sh "open tests/index.html"
end
end
task :browser_test => :release
QunitCliRunner::Task.new('test')
task :test => :release
task :default => :test