- Notifications
You must be signed in to change notification settings - Fork12
/
Copy pathRakefile
147 lines (108 loc) · 2.74 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
require'open3'
require'fileutils'
Encoding.default_external='UTF-8'
ROOT_DIR=File.dirname(__FILE__)
JS_DIR="#{ROOT_DIR}/js"
CSS_DIR="#{ROOT_DIR}/css"
LIB_DIR="#{ROOT_DIR}/lib"
BUILD_DIR="#{ROOT_DIR}/build"
JS_BUILD_FILE='tegaki.js'
CSS_BUILD_FILE='tegaki.css'
TEGAKI_LANG=ifENV['TEGAKI_LANG'] &&ENV['TEGAKI_LANG'] =~/\A[a-z]+\z/
ENV['TEGAKI_LANG']
else
'en'
end
NO_REPLAY=ENV['TEGAKI_NO_REPLAY'] =='1'
desc'Concatenate JavaScript'
task:concatdo
if !File.directory?(BUILD_DIR)
FileUtils.mkdir(BUILD_DIR)
end
out_file="#{BUILD_DIR}/#{JS_BUILD_FILE}"
src=String.new
src <<'/*! tegaki.js, MIT License */'
src <<"'use strict';"
file="#{JS_DIR}/strings/#{TEGAKI_LANG}.js"
puts"<--#{file}"
src <<File.binread(file)
%w[
tool
brush
pencil
airbrush
pen
bucket
tone
pipette
blur
eraser
].eachdo |tool|
file="#{JS_DIR}/tools/#{tool}.js"
puts"<--#{file}"
src <<File.binread(file)
end
replay_src=['replayrecorder.js','replayviewer.js']
Dir.glob("#{JS_DIR}/*.js").eachdo |file|
nextif(NO_REPLAY &&replay_src.include?(File.basename(file)))
puts"<--#{file}"
src <<File.binread(file)
end
if !NO_REPLAY
file="#{LIB_DIR}/UZIP/UZIP.js"
puts"<--#{file}"
src <<File.binread(file)
end
File.binwrite(out_file,src)
puts"\n-->#{out_file}"
end
desc'Minify JavaScript and CSS'
task:minify=>['minify:js']#, 'minify:css']
namespace:minifydo
desc'Minify JavaScript'
task:jsdo
require'uglifier'
file="#{BUILD_DIR}/#{JS_BUILD_FILE}"
if !File.exist?(file)
abort("#{file} not found. Run 'rake concat' first")
end
min_file="#{BUILD_DIR}/#{File.basename(JS_BUILD_FILE,'.js')}.min.js"
u=Uglifier.new({
:compress=>{
:drop_console=>true
},
:output=>{
:comments=>/^\/*!/
},
:harmony=>true,
})
js=u.compile(File.read(file))
File.binwrite(min_file,js)
puts"-->#{min_file}"
end
desc'Minify CSS'
task:cssdo
file="#{CSS_DIR}/#{CSS_BUILD_FILE}"
min_file="#{CSS_DIR}/#{File.basename(JS_BUILD_FILE,'.js')}.min.css"
output,outerr,status=Open3.capture3('cleancss','-o',min_file,file)
ifstatus !=0
putsouterr
abort
end
puts"-->#{min_file}"
end
end
desc'Run JShint'
task:jshintdo
Dir.glob("#{JS_DIR}/**/*.js").eachdo |file|
puts"-->#{File.basename(file)}"
output,outerr,status=Open3.capture3('jshint',file)
ifouterr !=''
putsouterr
abort
else
putsoutput
end
end
end
task:default=>[:concat]