-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdeploy.rb
98 lines (84 loc) · 2.12 KB
/
deploy.rb
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
require 'pathname'
require 'fileutils'
class Deploy
class Transform
def initialize(to_replace_regex, replacement_str, file_path_str)
@to_replace_regex = to_replace_regex
@replacement_str = replacement_str
@file_path_str = file_path_str
end
def perform
# puts "transforming #{@to_replace_regex.inspect} to #{@replacement_str} in #{@file_path_str}"
newhtml = File.read(@file_path_str).gsub(@to_replace_regex, @replacement_str)
File.open(@file_path_str, 'w'){|f| f.write newhtml}
end
end
class IronWebsite
def initialize(deployment_dir)
@dir = deployment_dir
end
def deploy
# puts "Deploying #{self.class.content_dir}"
copy
transform_css_paths
transform_image_paths
end
def transform_css_paths
Dir["#{@dir}/**/*.html"].each do |html|
Transform.new(/\.\.\/css/, "css", html).perform
end
end
def transform_image_paths
Dir["#{@dir}/**/*.html"].each do |html|
Transform.new(/\.\.\/images/, 'images', html).perform
end
end
def copy
FileUtils.mkdir_p @dir
FileUtils.cp_r "#{self.class.content_dir}/.", @dir
FileUtils.cp_r 'css', @dir
FileUtils.cp_r 'images', @dir
FileUtils.cp 'Web.config', @dir
Pathname.glob("#{Pathname(@dir) + 'images'}/*").each do |p|
p.delete if p.basename.to_s =~ /iron/ && p.basename.to_s !~ /#{self.class.content_dir}/
end
end
def self.content_dir
throw "Must be implemented in a base-class"
end
end
module Sites
class IronRubyNet < IronWebsite
def self.content_dir
"ruby"
end
end
class IronPythonNet < IronWebsite
def self.content_dir
"python"
end
end
end
def initialize
@sites = Sites.constants.map do |site|
Sites.const_get(site).new("deploy/#{site}")
end
end
def clean
# puts "Cleaning"
d = Pathname('deploy')
d.rmtree if d.exist?
end
def deploy
clean
@sites.each{|s| s.deploy}
end
end
if __FILE__ == $0
d = Deploy.new
if ARGV.include?('-clean')
d.clean
else
d.deploy
end
end