forked from stuartlynn/zooniverse_dating
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rb
executable file
·78 lines (62 loc) · 1.78 KB
/
build.rb
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
#!/usr/bin/env ruby
require 'aws-sdk'
AWS.config access_key_id: ENV['S3_ACCESS_ID'], secret_access_key: ENV['S3_SECRET_KEY']
s3 = AWS::S3.new
bucket = s3.buckets['dating.zooniverse.org']
build_style = ARGV[1] || 'full'
build = <<-BASH
rm -rf build
cp -R public pre_build_public
cp -RL public build_public
rm -rf public
mv build_public public
echo 'Building...'
hem build
mv public build
mv pre_build_public public
BASH
timestamp = `date -u +%Y-%m-%d_%H-%M-%S`.chomp
compress = <<-BASH
echo 'Compressing...'
timestamp=#{ timestamp }
mv build/application.js "build/application-$timestamp.js"
mv build/application.css "build/application-$timestamp.css"
rm build/application.css
BASH
system build
system compress
index = File.read 'build/index.html'
index.gsub! 'application.js', "application-#{ timestamp }.js"
index.gsub! 'application.css', "application-#{ timestamp }.css"
File.open('build/index.html', 'w'){ |f| f.puts index }
working_directory = Dir.pwd
Dir.chdir 'build'
if build_style=='full'
to_upload = Dir['**/*'].reject{ |path| File.directory? path }
else
to_upload = ["application-#{ timestamp }.js", "application-#{ timestamp }.css", "index.html"]
end
to_upload.delete 'index.html'
to_upload << 'index.html'
total = to_upload.length
to_upload.each.with_index do |file, index|
content_type = case File.extname(file)
when '.html'
'text/html'
when '.js'
'application/javascript'
when '.css'
'text/css'
when '.gz'
'application/x-gzip'
when '.ico'
'image/x-ico'
else
`file --mime-type -b #{ file }`.chomp
end
puts "#{ '%2d' % (index + 1) } / #{ '%2d' % total }: Uploading #{ file } as #{ content_type }"
bucket.objects["#{file}"].write file: file, acl: :public_read, content_type: content_type
end
Dir.chdir working_directory
`rm -rf build`
puts 'Done!'