forked from sky-uk/web-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rakefile
77 lines (63 loc) · 2.09 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
require 'aws-sdk'
require 'cgi'
def s3
$s3 ||= AWS::S3.new(access_key_id: ENV["S3_ACCESS_KEY_ID"] , secret_access_key: ENV["S3_ACCESS_KEY"], region: 'eu-west-1')
end
def bucket
$bucket ||= s3.buckets['prod-sky-web-toolkit']
end
def latest_version_number
$latest_version_number ||= File.open('_config.yml').read.match(/version:(.+)/)[1].strip
end
def version_already_exists?
bucket.objects.any?{|obj|obj.key.include? latest_version_number}
end
def files_to_upload
files = ["stylesheets/toolkit.css", "fonts/skycons.css", "fonts/skycons.eot", "fonts/skycons.svg", "fonts/skycons.ttf", "scripts/toolkit.js", "scripts/toolkit.js.map", "images/icon.png"]
end
def content_type(file)
case File.extname(file)
when '.svg'
content_type = 'image/svg+xml'
when '.eot'
content_type = 'application/vnd.ms-fontobject'
when '.ttf'
content_type = 'font/ttf'
when '.woff'
content_type = 'application/x-font-woff'
when '.map'
content_type = 'text/javascript'
when '.js'
content_type = 'text/javascript'
when '.css'
content_type = 'text/css'
when '.png'
content_type = 'image/png'
when '.html'
content_type = 'text/html'
else
content_type = 'image/jpeg'
end
content_type
end
desc 'Deploys a new version to the CDN'
task :deploy_new_version do
if version_already_exists?
puts "Version #{latest_version_number} already exists. Exiting."
next
end
#ensure at least the public css/js/images are grunt ready for akamai!
system "grunt"
system "git add ./dist"
system "git commit -m 'Rake deploy - adding grunted files'"
system "git push origin HEAD:master"
#push new build to .io site
system "git checkout gh-pages"
system "git push origin master:gh-pages"
doc_resources = []
puts 'Uploading doc files'
cd "dist"
files_to_upload.each do |file|
doc_resources << bucket.objects["#{latest_version_number}/#{file}"].write(File.open(file).read, cache_control: 'public, max-age=2592000', content_type: content_type(file), acl: :public_read )
end
end