This repository has been archived by the owner on Jan 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathRakefile
259 lines (209 loc) · 6.15 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
require 'digest'
require 'front_end_tasks'
require 'front_end_tasks/cli'
require 'front_end_tasks/documents'
class FileList
BUILD_ROOT = './build'
DEV_ROOT = './app'
BITCOIN_ROOT = './app/vendor/bitcoin'
SPEC_ROOT = './spec'
INDEX_HTML = File.join(DEV_ROOT, 'index.html')
WORKER_JS = File.join(DEV_ROOT, 'js/workers/bitcoin_worker.js')
ASSETS = [
File.join(DEV_ROOT, 'apple-touch-icon.png'),
File.join(DEV_ROOT, 'apple-touch-icon-76x76.png'),
File.join(DEV_ROOT, 'apple-touch-icon-120x120.png'),
File.join(DEV_ROOT, 'apple-touch-icon-152x152.png'),
]
def base_files
[INDEX_HTML] + ASSETS
end
def app_scripts
FrontEndTasks.list_scripts(INDEX_HTML, DEV_ROOT)
end
def app_vendor_scripts
app_scripts.select { |s| s.include?('/vendor/') }
end
def app_source_scripts
app_scripts.reject { |s| s.include?('/vendor/') }
end
def app_spec_helpers
Dir.glob(File.join(SPEC_ROOT, '/helpers/**/*.js'))
end
def app_specs
Dir.glob(File.join(SPEC_ROOT, '/**/*Spec.js')) - worker_specs
end
def worker_script
WORKER_JS
end
def worker_specs
Dir.glob(File.join(SPEC_ROOT, '/workers/**/*Spec.js'))
end
def bitcoin_vendor_scripts
sjcl_scripts = [ "sjcl.js", "bitArray.js", "codecString.js",
"aes.js", "sha256.js", "random.js", "bn.js", "ecc.js",
"codecBase64.js", "codecHex.js", "codecBytes.js", "hmac.js",
"pbkdf2.js", "ccm.js", "convenience.js",
]
sjcl_scripts.map { |s| File.join(DEV_ROOT, 'vendor/sjcl/core/', s) }
end
def bitcoin_source_scripts
Dir.glob(File.join(DEV_ROOT, 'vendor/bitcoin/src/**/*.js'))
end
def bitcoin_scripts
bitcoin_vendor_scripts + bitcoin_source_scripts
end
def bitcoin_specs
Dir.glob(File.join(DEV_ROOT, 'vendor/bitcoin/spec/**/*Spec.js'))
end
def build_files
Dir.glob(File.join(BUILD_ROOT, '**/*')).select { |f| File.file?(f) }
end
end
file_list = FileList.new
task :build => :clean do
FrontEndTasks.build(
FileList::DEV_ROOT,
FileList::BUILD_ROOT,
file_list.base_files
)
end
task :build_debug => :clean do
FrontEndTasks.build(
FileList::DEV_ROOT,
FileList::BUILD_ROOT,
file_list.base_files,
:js_concat_only => true
)
end
task :build_gzip => :build do
blacklist_extensions = ['.woff', '.eot', '.gz']
files = file_list.build_files.reject do |f|
blacklist_extensions.include?(File.extname(f))
end
if files.any?
FrontEndTasks.gzip(*files)
end
end
task :build_prod => [:build_gzip, :manifest, :release_notes]
task :clean do
rm_r FileList::BUILD_ROOT if File.directory?(FileList::BUILD_ROOT)
end
namespace :lint do
task :app do
FrontEndTasks.lint(*file_list.app_source_scripts)
end
task :workers do
FrontEndTasks.lint(file_list.worker_script)
end
task :bitcoin do
FrontEndTasks.lint(*file_list.bitcoin_source_scripts)
end
task :build => 'rake:build' do
build_javascripts = [
'./build/js/scripts.min.js',
'./build/js/workers/bitcoin_worker.js'
]
FrontEndTasks.lint(*build_javascripts)
end
end
task :lint => ['lint:app', 'lint:workers', 'lint:bitcoin']
namespace :spec do
task :app do
FrontEndTasks.spec({
:source_files => file_list.app_scripts,
:helper_files => file_list.app_spec_helpers,
:spec_files => file_list.app_specs,
:port => 8001
})
end
task :workers do
FrontEndTasks.spec({
:worker_file => file_list.worker_script,
:public_root => FileList::DEV_ROOT,
:spec_files => file_list.worker_specs,
:port => 8002
})
end
task :bitcoin do
sh 'testem ci -f bitcoin_testem.json'
end
task :app_build => 'rake:build' do
FrontEndTasks.spec({
:source_files => ['./build/js/scripts.min.js'],
:helper_files => file_list.app_spec_helpers,
:spec_files => file_list.app_specs,
:port => 8001
})
end
task :worker_build => 'rake:build' do
FrontEndTasks.spec({
:worker_file => './build/js/workers/bitcoin_worker.js',
:public_root => FileList::BUILD_ROOT,
:spec_files => file_list.worker_specs,
:port => 8002
})
end
task :build => [:app_build, :worker_build]
end
task :spec => ['spec:app', 'spec:workers', 'spec:bitcoin']
namespace :server do
task :debug => :build_debug do
FrontEndTasks.server(:public_dir => './build', :port => 8000)
end
task :prod => :build_prod do
FrontEndTasks.server(:public_dir => './build', :port => 8000)
end
end
task :server do
FrontEndTasks.server(:public_dir => './app', :port => 8000)
end
task :commits, :since_tag do |task, args|
tag = ENV["SINCE_TAG"] || args[:since_tag] || `git describe --abbrev=0 --tags`
puts
puts '## Commits'
puts `git log #{tag.strip}..HEAD --oneline`
puts
end
task :checksum => :build_gzip do
file_hash = {}
left_column_length = 0
build_files = file_list.build_files.reject { |f| File.extname(f) == '.gz' }
build_files.each do |f|
hash = Digest::SHA256.hexdigest(File.read(f))
file = f.gsub(FileList::BUILD_ROOT + '/', '')
file_hash[file] = hash
left_column_length = file.length if file.length > left_column_length
end
puts
puts "## Checksums"
puts "```"
file_hash.each_pair do |file, hash|
puts "#{file.ljust(left_column_length)} #{hash}"
end
puts "```"
end
task :manifest => :build_gzip do
manifest_file = File.open(File.join(FileList::BUILD_ROOT, 'coinpocketapp.manifest'), 'w')
file_hash = {}
left_column_length = 0
build_files = file_list.build_files.reject { |f| File.extname(f) == '.gz' || File.extname(f) == '.manifest' }
build_files.each do |f|
hash = Digest::SHA256.hexdigest(File.read(f))
file = f.gsub(FileList::BUILD_ROOT + '/', '')
file_hash[file] = hash
left_column_length = file.length if file.length > left_column_length
end
manifest_file.puts "CACHE MANIFEST"
manifest_file.puts
manifest_file.puts "CACHE:"
file_hash.each_pair do |file, hash|
manifest_file.puts "#{file.ljust(left_column_length)} # #{hash}"
end
manifest_file.puts
manifest_file.puts "NETWORK:"
manifest_file.puts "*"
manifest_file.close
end
task :release_notes => [:checksum, :commits]
task :default => ['lint', 'spec']