-
Notifications
You must be signed in to change notification settings - Fork 27
/
Rakefile
125 lines (113 loc) · 3.95 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# This file is a rake build file. The purpose of this file is to simplify
# setting up and using Awestruct. It's not required to use Awestruct, though it
# does save you time (hopefully). If you don't want to use rake, just ignore or
# delete this file.
#
# If you're just getting started, execute this command to install Awestruct and
# the libraries on which it depends:
#
# rake setup
#
# To run in Awestruct in editor mode, execute:
#
# rake
#
# To clean the generated site before you build, execute:
#
# rake clean preview
#
# To get a list of all tasks, execute:
#
# rake -T
#
# Now you're Awestruct with rake!
require 'bundler'
task :default => :preview
#####################################################################################
# Bundler and environment related tasks
#####################################################################################
# Perform initialization steps, such as setting up the PATH
task :init do
cmd = "bundle check"
msg cmd
system cmd or raise StandardError, "Bundle dependencies not satisfied. Run 'rake setup' first"
end
desc 'Setup the environment to run Awestruct using Bundler'
task :setup do |task, args|
bundle_command = 'bundle install'
msg "Executing '#{bundle_command}' in clean Bundler environment"
Bundler.with_unbundled_env do
system bundle_command
end
msg 'Bundle installed'
# Don't execute any more tasks, need to reset env
exit 0
end
desc 'Update gems ignoring the previously installed gems specified in Gemfile.lock'
task :update => :init do
system 'bundle update'
# Don't execute any more tasks, need to reset env
exit 0
end
#####################################################################################
# Awestruct related tasks
#####################################################################################
desc 'Build and preview the site locally in development mode. preview[<options>] can be used to pass awestruct options, eg \'preview[--no-generate]\''
task :preview, [:profile, :options] => :init do |task, args|
profile = get_profile args
options = args[:options]
# Must bind to 0.0.0.0 instead of the default "localhost" in order to allow port forwarding in Docker container
run_awestruct "-P #{profile} --server --bind 0.0.0.0 --auto --no-livereload #{options}"
end
desc 'Generate the site using the specified profile, default is \'development\'. Additional options can also be specified, eg \'gen[development, \'-w\']'
task :gen, [:profile, :options] => :init do |task, args|
profile = get_profile args
options = args[:options]
run_awestruct "-P #{profile} -g --force #{options}"
end
desc 'Clean out generated site and temporary files, using [all-keep-deps] removes caches as well, using [all] will also delete local gem files'
task :clean, :option do |task, args|
require 'fileutils'
dirs = ['.awestruct', '.sass-cache', '_site', '_tmp']
if args[:option] == 'all'
dirs << '.wget-cache'
end
dirs.each do |dir|
FileUtils.remove_dir dir unless !File.directory? dir
end
end
#####################################################################################
# Test
#####################################################################################
desc 'Run Rspec tests'
task :test do
all_ok = system "bundle exec rspec _spec --format documentation"
if all_ok == false
fail "RSpec tests failed - aborting build"
end
end
#####################################################################################
# Helper methods
#####################################################################################
# Execute Awestruct
def run_awestruct(args)
cmd = "bundle exec awestruct #{args}"
msg cmd
system cmd or raise StandardError, "ERROR: Running Awestruct failed."
end
def get_profile(args)
if args[:profile].nil?
profile = "development"
else
profile = args[:profile]
end
end
# Print a message to STDOUT
def msg(text, level = :info)
case level
when :warn
puts "\e[31m#{text}\e[0m"
else
puts "\e[33m#{text}\e[0m"
end
end