forked from ericdrowell/KineticJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thorfile
75 lines (60 loc) · 2.57 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
75
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 = [
"license.js", "src/Global.js", "src/Transition.js", "src/filters/Grayscale.js",
"src/util/Type.js", "src/util/Canvas.js", "src/util/Class.js", "src/util/Tween.js", "src/util/Transform.js",
"src/Animation.js", "src/Node.js", "src/Container.js", "src/Stage.js", "src/Layer.js", "src/Group.js", "src/Shape.js",
"src/shapes/Rect.js", "src/shapes/Ellipse.js", "src/shapes/Image.js", "src/shapes/Polygon.js", "src/shapes/Text.js", "src/shapes/Line.js", "src/shapes/Sprite.js", "src/shapes/Star.js", "src/shapes/RegularPolygon.js", "src/shapes/Path.js", "src/shapes/TextPath.js"
]
desc "dev", "Concatenate all the js files into /dist/kinetic-VERSION.js."
method_option :date, :aliases => "-d", :required => false, :type => :string, :desc => "The release date"
def dev(version)
file_name = "dist/kinetic-#{version}.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}..."
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/kinetic-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/kinetic-#{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