-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
185 lines (121 loc) · 3.61 KB
/
Rakefile
File metadata and controls
185 lines (121 loc) · 3.61 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
require 's3_website'
require 'yaml'
Setting = YAML.load_file('config.yml')
SourceDir = "source" # source file directory
PublicDir = "public" # public file directory
DeployDir = "_deploy" # deploy file directory
repo_url = "git@github.com:logdown/themes.git"
task :generate do
system "jekyll build --source #{SourceDir}/ --destination #{PublicDir}/"
Dir.entries("#{SourceDir}").select do |theme|
if File.directory?("#{SourceDir}/#{theme}") && !(theme =='.' || theme == '..')
puts theme
system "compass compile --css-dir #{PublicDir}/#{theme}/stylesheets" +
" --sass-dir #{SourceDir}/#{theme}/_sass" +
" --images-dir #{PublicDir}/#{theme}/images" +
" --fonts-dir #{PublicDir}/#{theme}/fonts" +
" --relative-assets" +
" --output-style compressed"
end
end
end
task :watch, :theme do |t, args|
theme = args[:theme]
if File.directory?("#{SourceDir}/#{theme}") && !(theme =='.' || theme == '..')
puts "Watching Theme: #{theme}\n"
system "compass watch --css-dir #{PublicDir}/#{theme}/stylesheets" +
" --sass-dir #{SourceDir}/#{theme}/_sass" +
" --images-dir #{PublicDir}/#{theme}/images" +
" --fonts-dir #{PublicDir}/#{theme}/fonts" +
" --relative-assets"
end
end
task :new do |t, args|
name = get_stdin("Enter a name for your new theme: ")
name = theme_name_sanitize(name)
if !validate_theme_name(name)
abort "invalid theme name: #{name}"
end
puts "Creating new theme: #{name}"
mkdir "#{SourceDir}/#{name}"
cd "#{SourceDir}/#{name}" do
mkdir "images"
mkdir "javascripts"
mkdir "stylesheets"
mkdir "_sass"
sh "touch index.liquid"
end
end
task :deploy_github do
if /nothing to commit/ !~ `git status`
abort "Directory not clean, please commit and push it first"
end
system "git fetch"
push_testing = `git diff --stat origin/master`
if push_testing.length > 0
abort "Some commits not push, please push it first"
end
cd DeployDir do
system "git pull"
end
(Dir["#{DeployDir}/*"]).each { |f| rm_rf(f) }
Rake::Task[:generate].execute
cp_r "#{PublicDir}/.", DeployDir
cd "#{DeployDir}" do
system "git add -A"
puts "\n## Commiting: Site updated at #{Time.now.utc}"
message = "Site updated at #{Time.now.utc}"
system "git commit -m \"#{message}\""
puts "\n## Pushing generated #{DeployDir} website"
system "git push origin gh-pages"
puts "\n## Github Pages deploy complete"
end
end
task :deploy do
if /nothing to commit/ !~ `git status`
abort "Directory not clean, please commit and push it first"
end
system "git fetch"
push_testing = `git diff --stat origin/master`
if push_testing.length > 0
abort "Some commits not push, please push it first"
end
Rake::Task[:generate].execute
config = {
"s3_id" => Setting["s3_id"],
"s3_secret" => Setting["s3_secret"],
"s3_bucket" => Setting["s3_bucket"],
"s3_endpoint" => "ap-northeast-1",
"gzip" => true
}
is_headless = true
S3Website::Uploader.run('./public', config, is_headless)
end
task :setup_github_pages do
rm_rf DeployDir
mkdir DeployDir
cd DeployDir do
system "git init"
system "git remote add origin #{repo_url}"
system "git fetch origin"
system "git checkout gh-pages"
end
end
def get_stdin(message)
print message
STDIN.gets.chomp
end
def theme_name_sanitize(name)
name = name.downcase
name.gsub!(/[^a-z-]/, "_")
return name
end
def validate_theme_name(name)
if !name
return false
end
if File.directory?("#{SourceDir}/#{name}")
return false
end
return true
end