forked from martinwells/objects.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThorfile
74 lines (59 loc) · 2.23 KB
/
Thorfile
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
require 'json/pure'
class Build < Thor
# This is the list of files to concatenate. The first file will appear at the top of the final file. All files are relative to the lib directory.
FILES = [
"src/class.js", "src/gamecore.js", "src/device.js", "src/jhashtable.js", "src/hashlist.js",
"src/linkedlist.js", "src/queue.js", "src/pooled.js", "src/perf.js", "src/stacktrace.js"
]
desc "dev", "Concatenate all the js files into /dist/gamecore-VERSION.js."
method_option :date, :aliases => "-d", :required => false, :type => :string, :desc => "The release date"
def dev(version)
file_name = "dist/gamecore-#{version}.js"
puts ":: Deleting other development files..."
Dir.foreach("dist") do |file|
puts ":: Building the file /#{file}..."
if file.match(/.*[^(min)]\.js/)
File.delete("dist/" + file)
end
end
puts ":: Building the file /#{file_name}..."
File.open(file_name, "w") do |file|
file.puts concatenate(version, options[:date])
end
puts " -> Done!"
end
desc "prod", "Concatenate all the js files in into /dist/gamecore-VERSION.min.js and minify it."
method_option :date, :aliases => "-d", :required => false, :type => :string, :desc => "The release date"
def prod(version)
file_name = "dist/gamecore-#{version}.min.js"
puts ":: Deleting other development files..."
Dir.foreach("dist") do |file|
if file.match(/.*min\.js/)
File.delete("dist/" + file)
end
end
puts ":: Building the file /#{file_name}..."
require 'json/pure'
require 'uglifier'
File.open(file_name, "w") do |file|
uglify = Uglifier.compile(concatenate(version, options[:date]))
uglify.sub!(/\*\/ .+ \*\//xm, "*/")
file.puts uglify
end
puts ":: Minifying the file /#{file_name}..."
puts " -> Done!"
end
private
def concatenate(version, date)
date ||= Time.now.strftime("%b %d %Y")
content = ""
FILES.each do |file|
content << IO.read(File.expand_path(file)) << "\n"
end
# Add the version number
content.sub!("@version", version)
# Add the date
content.sub!("@date", date)
return content
end
end