forked from ericdrowell/KineticJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thorfile
160 lines (128 loc) · 5.03 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
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
require 'json/pure'
require 'uglifier'
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/Global.js", "src/util/Type.js", "src/Canvas.js", "src/util/Tween.js", "src/util/Transform.js", "src/util/Collection.js",
"src/filters/Grayscale.js", "src/filters/Brighten.js", "src/filters/Invert.js", "src/filters/Blur.js",
"src/Node.js", "src/Animation.js", "src/DragAndDrop.js", "src/Transition.js", "src/Container.js", "src/Shape.js", "src/Stage.js", "src/Layer.js", "src/Group.js",
"src/shapes/Rect.js", "src/shapes/Circle.js", "src/shapes/Wedge.js", "src/shapes/Ellipse.js", "src/shapes/Image.js", "src/shapes/Polygon.js", "src/shapes/Text.js", "src/shapes/Line.js", "src/shapes/Spline.js", "src/shapes/Blob.js", "src/shapes/Sprite.js",
"src/plugins/Path.js", "src/plugins/TextPath.js", "src/plugins/RegularPolygon.js", "src/plugins/Star.js", "src/plugins/Label.js"
]
UNIT_TESTS = [
"tests/js/unit/animationTests.js",
"tests/js/unit/globalTests.js",
"tests/js/unit/nodeTests.js",
"tests/js/unit/stageTests.js",
"tests/js/unit/containerTests.js",
"tests/js/unit/layerTests.js",
"tests/js/unit/shapeTests.js",
"tests/js/unit/ddTests.js",
"tests/js/unit/transitionTests.js",
"tests/js/unit/shapes/rectTests.js",
"tests/js/unit/shapes/circleTests.js",
"tests/js/unit/shapes/wedgeTests.js",
"tests/js/unit/shapes/ellipseTests.js",
"tests/js/unit/shapes/imageTests.js",
"tests/js/unit/shapes/polygonTests.js",
"tests/js/unit/shapes/lineTests.js",
"tests/js/unit/shapes/splineTests.js",
"tests/js/unit/shapes/blobTests.js",
"tests/js/unit/shapes/textTests.js",
"tests/js/unit/shapes/spriteTests.js",
"tests/js/unit/plugins/pathTests.js",
"tests/js/unit/plugins/regularPolygonTests.js",
"tests/js/unit/plugins/starTests.js",
"tests/js/unit/plugins/textPathTests.js",
"tests/js/unit/plugins/labelTests.js"
]
if !File.directory?("dist")
puts ":: Creating dist directory..."
Dir.mkdir("dist")
end
# dev build
desc "dev", "Concatenate all the js files into /dist/kinetic-vVERSION.js."
def dev(version)
file_name = "dist/kinetic-v#{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 full source file /#{file_name}..."
File.open(file_name, "w") do |file|
file.puts replace_tokens(concatenate, version)
end
puts " -> Done!"
end
# test build
desc "test", "Concatenate all the unit test js files into tests/js/unitTests.js"
def test()
file_name = "tests/js/unitTests.js"
puts ":: Deleting old unitTests.js..."
if File.file?("tests/js/unitTests.js")
File.delete("tests/js/unitTests.js")
end
puts ":: Building new unitTests.js..."
File.open(file_name, "w") do |file|
file.puts concatenateUnitTests
end
puts " -> Done!"
end
#prod build
desc "prod", "Concatenate all the js files in into /dist/kinetic-vVERSION.min.js and minify it."
def prod(version)
file_name = "dist/kinetic-v#{version}.min.js"
puts ":: Deleting other prod files..."
Dir.foreach("dist") do |file|
if file.match(/.*min\.js/)
File.delete("dist/" + file)
end
end
puts ":: Building full prod file /#{file_name}..."
#build full minfiied prod file
File.open(file_name, "w") do |file|
uglify = Uglifier.compile(concatenate())
uglify.sub!(/\*\/ .+ \*\//xm, "*/")
file.puts replace_tokens(uglify, version)
end
#build modular minified files
puts ":: Building minified modules..."
FILES.each do |file|
content = IO.read(File.expand_path(file)) << "\n"
mod = File.basename(file)
mod[".js"] = ""
module_filename = "dist/kinetic-#{mod}-v#{version}.min.js"
File.open(module_filename, "w") do |file2|
uglify = Uglifier.compile(content, :copyright => mod == "Global")
file2.puts replace_tokens(uglify, version)
end
end
puts " -> Done!"
end
private
def concatenate()
content = ""
FILES.each do |file|
content << IO.read(File.expand_path(file)) << "\n"
end
return content
end
def concatenateUnitTests()
content = ""
UNIT_TESTS.each do |file|
content << IO.read(File.expand_path(file)) << "\n"
end
return content
end
def replace_tokens(content, version)
date = Time.now.strftime("%b %d %Y")
content.gsub!("{{version}}", version)
content.sub!("{{date}}", date)
content.gsub!("{{NodeParams}}", IO.read("configParams/NodeParams.txt"))
content.gsub!("{{ContainerParams}}", IO.read("configParams/ContainerParams.txt"))
content.gsub!("{{ShapeParams}}", IO.read("configParams/ShapeParams.txt"))
return content
end
end