forked from zooniverse-glacier/notesFromNature
-
Notifications
You must be signed in to change notification settings - Fork 3
/
staging-build.rb
71 lines (59 loc) · 1.7 KB
/
staging-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
#!/usr/bin/env ruby
require 'aws-sdk'
s3 = AWS::S3.new
bucket = s3.buckets['zooniverse-demo']
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...'
coffee build.coffee
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/nfn/build.js "build/nfn/build-$timestamp.js"
./node_modules/clean-css/bin/cleancss build/application.css -o "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! 'build.js', "build-#{ 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'
to_upload = Dir['**/*'].reject{ |path| File.directory? path }
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["notes_from_nature/#{ file }"].write file: file, acl: :public_read, content_type: content_type
end
Dir.chdir working_directory
`rm -rf build`
puts 'Done!'