forked from philipwalton/solved-by-flexbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
90 lines (65 loc) · 2.02 KB
/
Rakefile
File metadata and controls
90 lines (65 loc) · 2.02 KB
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
require "rubygems"
require "rake"
require 'fileutils'
require 'uglifier'
require 'pry-debugger'
desc "Load a local server and watch for any changes"
task :preview, :port do |t, args|
port = args.port || 4000
annotate "Starting server on port #{port} and watching for changes."
jekyll_pid = Process.spawn("jekyll serve -w --drafts --port #{port}")
compass_pid = Process.spawn("compass watch")
trap("INT") {
[jekyll_pid, compass_pid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
exit 0
}
[jekyll_pid, compass_pid].each { |pid| Process.wait(pid) }
end
desc "Concat and uglify JavaScript"
task :uglify do
# TODO: figure out a way to do this within Jekyll nicely
annotate "Concatenating and minifying scripts"
scripts = [
"scripts/track-events.js",
"scripts/highlight.js",
"scripts/flexbox-detect.js",
]
files = scripts.map do |file|
File.read(file)
end
File.open("scripts/scripts.min.js", "w") do |file|
file.write Uglifier.new.compile(files.join)
end
end
desc "Compile and generate all site files"
task :generate do
annotate "Compiling Sass"
system "compass compile ."
annotate "Generating site files"
system "jekyll build"
end
task :deploy => [:generate] do
annotate "Updating gh-pages branch"
# Create a temp repo to pull the latest remote gh-pages files from
mkdir "_tmp"
cd "_tmp" do
system "git init"
system "git remote add origin git@github.com:philipwalton/solved-by-flexbox.git"
system "git pull origin gh-pages"
system "rm -rf *" # remove all files
system "cp -r ../_site/ ./" # copy over all the newly deployed files
system "git add . && git add -u"
system "git commit -m 'Site deployed at #{Time.now.utc}'"
system "git branch -m gh-pages"
system "git push origin gh-pages"
end
annotate "Cleaning up"
# Remove the `_site` and `_tmp` directories, destroy the temp repo
rm_rf "_site"
rm_rf "_tmp"
annotate "Successfully deployed site!"
end
private
def annotate(text)
puts "\n### #{text} ###\n\n"
end