-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
78 lines (64 loc) · 1.52 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
require "rubygems"
require "bundler"
Bundler.setup
require "dotenv"
Dotenv.load
aws_key = ENV["AWS_ACCESS_KEY"]
aws_secret = ENV["AWS_SECRET_KEY"]
s3_bucket = ENV["AWS_BUCKET"]
cf_dist_id = ENV["CLOUDFRONT_DIST_ID"]
desc "Builds, deploys to S3, and invalidates CloudFront Edge caches"
task deploy: [:build, :upload, :invalidate]
desc "Basically just calls middleman build"
task :build do
puts "*** Middleman build go! ***"
system "middleman build"
end
desc "Uploads new files to S3"
task :upload do
begin
s3cmd = `which s3cmd`.chomp
puts "*** Middleman deploy go! ***"
rescue
abort "*** `brew install s3cmd` plz ***"
end
cmd = [
s3cmd,
"--access_key=#{aws_key}",
"--secret_key=#{aws_secret}",
# "--dry-run",
"--delete-removed",
"sync",
"build/",
"s3://#{s3_bucket}"
]
system cmd.join " "
end
task :invalidate do
begin
cfcmd = `which cloudfront-invalidator`.chomp
puts "*** CloudFront Invalidator go! ***"
rescue
abort "*** Could not find `cloudfront-invalidator` command ***"
end
indexes = Dir["build/**/index.html"]
.map { |path| path.gsub "build", "" }
.map { |path|
# we need the indexes as well as the directories that contain them
[path, path.gsub("index.html", "")]
}.flatten
cmd = [
cfcmd,
"invalidate",
aws_key,
aws_secret,
cf_dist_id,
indexes.join(" ")
]
system cmd.join " "
end
desc "Run middleman server"
task :server do
puts "*** Middleman server go! ***"
system "middleman server"
end