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
184
185
186
|
# File 'lib/swiftly/create_wordpress.rb', line 28
def get_wordpress()
inside @project_path do
get 'https://wordpress.org/latest.zip', 'latest.zip' unless File.exist? 'wordpress'
unzip 'latest.zip', 'wordpress' unless File.exist? 'wordpress'
remove_file 'latest.zip' unless !File.exist? 'latest.zip'
Dir['wordpress/*'].each do |e|
FileUtils.mv( e, @project_path ) unless File.exist? e.gsub(/^wordpress/, @project_path )
end
remove_file 'wordpress' unless !(Dir.entries('wordpress') - %w{ . .. }).empty?
inside File.join( 'wp-content', 'themes') do
if @template[:location] =~ /^#{URI::regexp}\.zip$/
zipfile = get @template[:location], File.basename( @template[:location] )
unzip zipfile, @template[:name] unless File.exist? @template[:name]
remove_file zipfile unless !File.exist? zipfile
else
FileUtils.cp_r( File.join( @template[:location], @template[:name] ), '.' )
end
FileUtils.mv( @template[:name], @project_name ) unless !File.exists? @template[:name].capitalize
inside @project_name do
[
'.git',
'_resources',
'.gitignore',
'.htaccess',
".#{APP_NAME}",
".#{APP_NAME}ignore"
].each do |e|
remove_file e
end
[
'.htaccess',
'wp-config.php',
'bower.json',
'config.rb',
'Guardfile',
'Gemfile',
'Gemfile.lock'
].each do |file|
gsub_file file, /(#{@template[:name]})/, @project_name unless !File.exists? file
FileUtils.mv( file, @project_path ) unless !File.exists? file
end
FileUtils.mv(
"#{@template[:name]}-specific-plugin",
File.join( @project_path, "wp-content", "plugins", "#{@project_name}-specific-plugin")
) unless !File.exists? "#{@template[:name]}-specific-plugin"
FileUtils.mv(
File.join( "wp-login-logo-#{@template[:name]}.png" ) ,
File.join( "wp-login-logo-#{@project_name}.png" )
) unless !File.exists? File.join( "wp-login-logo-#{@template[:name]}.png" )
gsub_file 'functions.php', /(#{@template[:name]})/, @project_name
end
end
inside File.join( "wp-content", "plugins", "#{@project_name}-specific-plugin") do
FileUtils.mv(
"#{@template[:name]}-plugin.php",
"#{@project_name}-plugin.php"
) unless !File.exists? "#{@template[:name]}-plugin.php"
gsub_file "#{@project_name}-plugin.php", /(#{@template[:name]})/, @project_name.capitalize unless !File.exists? "#{@template[:name]}-plugin.php"
end
inside File.join( "wp-content", "plugins" ) do
plugins = Swiftly::Package.load_plugins :wordpress
if plugins
plugins.each do |plugin|
if plugin[:location] =~ /^#{URI::regexp}\.zip$/
zipfile = get plugin[:location], File.basename( plugin[:location] )
unzip zipfile, plugin[:name] unless File.exist? plugin[:name]
remove_file zipfile unless !File.exist? zipfile
else
FileUtils.cp_r( File.join( plugin[:location], plugin[:name] ), '.' ) unless File.exist? plugin[:name]
end
end
end
end
remove_file "wp-config-sample.php"
gsub_file 'wp-config.php', /\/\/\s*Insert_Salts_Below/, Net::HTTP.get('api.wordpress.org', '/secret-key/1.1/salt')
gsub_file 'wp-config.php', /(table_prefix\s*=\s*')(wp_')/, '\1' + @project_name[0,3] + "_'"
settings = Swiftly::Config.load :swiftly
if !settings.nil? &&
!settings[:local][:db_host].nil? &&
!settings[:local][:db_user].nil? &&
!settings[:local][:db_pass].nil?
gsub_file 'wp-config.php', /(\$local\s*?=[\s|\S]*?)({[\s|\S]*?})/ do |match|
'$local = \'{
"db_name": "' + @project_name + '_local_wp",
"db_host": "' + settings[:local][:db_host] + '",
"db_user": "' + settings[:local][:db_user] + '",
"db_pass": "' + settings[:local][:db_pass] + '",
"domain": "http://' + @project_name + '.dev",
"wp_home": "http://' + @project_name + '.dev"
}'
end
end
database = Swiftly::Database.new( @project_name )
database.create( :local )
run('bundle') unless !File.exists? 'Gemfile'
run('bundle exec guard') unless !File.exists? 'Guardfile'
run('bower update') unless !File.exists? 'bower.json'
end
end
|