This repository has been archived by the owner on Apr 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
111 lines (99 loc) · 2.8 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
require "yaml"
require "./lib/better_ftp"
root = File.dirname(__FILE__)
deploy = YAML::load_file(File.join(root, "deploy.yml"))
deploy_to = deploy["deploy_to"]
task :deploy => [
:test,
:export_to_site
]
task :test => [
:fetch_recent_code,
:replace_tabs_with_2_spaces,
:check_for_non_sass_urls,
:create_site_manifest
]
task :fetch_recent_code do
`git pull origin master`
end
task :replace_tabs_with_2_spaces do
js_files = Dir.glob("#{root}/javascripts/**/*.js")
scss_files = Dir.glob("#{root}/sass/**/*.scss")
php_files = Dir.glob("#{root}/**/*.php")
files = js_files + scss_files + php_files
update_count = 0
files.each do |file|
has_tabs = false
new_content = ""
open(file,"r") do |f|
if !f.grep(/\t/).count.zero?
has_tabs = true
f.rewind
new_content = f.read.gsub(/\t/," ")
end
end
if has_tabs
open(file,"w") {|f| f.write new_content}
puts "REPLACED WITH SPACES: #{file}"
`git add #{file.gsub(root + "/","")}`
update_count = update_count + 1
end
end
raise "PENDING TAB CONVERSIONS" unless update_count.zero?
end
task :run_w3c_validations do
true
end
task :check_for_non_sass_urls do
scss_files = Dir.glob("#{root}/sass/**/*.scss")
scss_files.each do |scss|
open(scss) do |f|
if !f.grep(/[^-]url\(/).count.zero?
puts "CONTAINS NON-SASS URLS: #{scss}"
raise "NON_SASS_URLS_FOUND"
end
end
end
end
task :check_for_broken_links do
end
task :export_to_site do
puts "[EXPORT_TO_SITE TIMESTAMP] #{Time.now.to_s}"
ftp = BetterFTP.open(deploy["host"], deploy["username"], deploy["password"])
files = `git ls-files`.split("\n").map {|f| "#{root}/#{f}"}
`compass compile`
css_files = Dir.glob("#{root}/stylesheets/**/*.css")
files = files + css_files
files.each do |abs_path|
f = File.open(abs_path)
relative_path = abs_path.gsub(root,"")
puts "Uploading: #{relative_path}"
begin
ftp.put(f, "#{deploy_to}/#{relative_path}")
rescue => e
if ftp.directory?("#{deploy_to}/#{File.dirname(relative_path)}")
puts "Error: #{e.to_s}"
else
puts "Making directory: #{deploy_to}/#{File.dirname(relative_path)}"
ftp.mkdir_p("#{deploy_to}/#{File.dirname(relative_path)}")
begin
# Try to upload again now that directory exists
ftp.put(f, "#{deploy_to}/#{relative_path}")
rescue => e2
puts e2.to_s
end
end
end
f.close
end
ftp.quit
end
task :create_site_manifest do
files = Dir.glob("**/*.php").reject {|f| f.match(/includes\//)}
urls = files.map {|f| "http://staging.familygivingtree.org/#{f}" }
open("MANIFEST","w") do |f|
f.write urls.join("\n").to_s
end
res = `git add MANIFEST`
raise "MANIFEST CHANGED, PLEASE COMMIT" unless res.empty?
end