gentheme 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/gentheme/gem.rb +338 -0
- data/lib/gentheme/version.rb +1 -1
- data/lib/gentheme.rb +1 -302
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a68befe2c149938a7d112486ecc8063116919dba
|
|
4
|
+
data.tar.gz: d343b2d3824f5de9cee66b73119fddbcdaafb53a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c5c634bf6ce47801b27d3ff26f12e26a509a716b18c48a5cc9157e06173bf25620f4c561b823d130f829e3b6a29d938b40c956103bd4db5f4bfe38962844bcc5
|
|
7
|
+
data.tar.gz: abf036079eeab8b62849072447c407274c5c8b37dcc4773bbaebaa66ba3dd0083634950c959a3128720861ef7b6602b935775965f670957e0ff39156bd4bca30
|
data/lib/gentheme/gem.rb
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
module Gentheme
|
|
2
|
+
class Generator
|
|
3
|
+
|
|
4
|
+
attr_reader :root_path
|
|
5
|
+
|
|
6
|
+
def initialize(name, options)
|
|
7
|
+
@name = name
|
|
8
|
+
@root_path = File.expand_path(options[:path])
|
|
9
|
+
@verbose = options[:verbose]
|
|
10
|
+
@npm = false
|
|
11
|
+
@wp_cli = false
|
|
12
|
+
@virtualhost = false
|
|
13
|
+
|
|
14
|
+
# Define the defaults
|
|
15
|
+
|
|
16
|
+
@status_file = "gentheme.conf"
|
|
17
|
+
@default_status = {
|
|
18
|
+
general: {
|
|
19
|
+
project_name: name,
|
|
20
|
+
generator: 'gentheme',
|
|
21
|
+
generator_version: Gentheme::VERSION,
|
|
22
|
+
created_at: Time.now,
|
|
23
|
+
updated_at: Time.now
|
|
24
|
+
},
|
|
25
|
+
mysql: {
|
|
26
|
+
db_host: "127.0.0.1",
|
|
27
|
+
db_user: "root",
|
|
28
|
+
db_pass: "",
|
|
29
|
+
db_name: name
|
|
30
|
+
},
|
|
31
|
+
packages: {
|
|
32
|
+
|
|
33
|
+
}}
|
|
34
|
+
|
|
35
|
+
# Read the current status file or create it now
|
|
36
|
+
@status = read_status
|
|
37
|
+
if @status.nil?
|
|
38
|
+
@status = @default_status
|
|
39
|
+
|
|
40
|
+
# Touch the status file in the current directory
|
|
41
|
+
# The app installation will be done in the ./ folder without creating a new folder.
|
|
42
|
+
FileUtils.touch(@status_file) if ['./', '.'].include?(options[:path])
|
|
43
|
+
|
|
44
|
+
# Generate the app directory
|
|
45
|
+
generate_app_directory
|
|
46
|
+
|
|
47
|
+
# save the default status
|
|
48
|
+
write_status
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def start
|
|
55
|
+
|
|
56
|
+
if check_requirements
|
|
57
|
+
|
|
58
|
+
# Generate the app directory
|
|
59
|
+
#if !get_status(:app_directory, :packages)
|
|
60
|
+
# generate_app_directory
|
|
61
|
+
#else
|
|
62
|
+
# puts 'App directory already created.'
|
|
63
|
+
#end
|
|
64
|
+
|
|
65
|
+
# Create database
|
|
66
|
+
if !get_status(:create_database, :packages)
|
|
67
|
+
create_database
|
|
68
|
+
else
|
|
69
|
+
puts 'Database already created.'
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Install gulp-webapp
|
|
73
|
+
if !get_status(:gulp_webapp, :packages)
|
|
74
|
+
install_gulp_webapp if install_yeoman
|
|
75
|
+
else
|
|
76
|
+
puts 'Gulp-webapp is already installed'
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
#install wordpress
|
|
80
|
+
if !get_status(:wordpress, :packages)
|
|
81
|
+
install_wordpress
|
|
82
|
+
else
|
|
83
|
+
puts 'Wordpress is already installed'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# append wp gitignore
|
|
87
|
+
if !get_status(:wp_gitignore, :packages)
|
|
88
|
+
add_wp_gitignore
|
|
89
|
+
else
|
|
90
|
+
puts 'Wordpress is already added to gitignore'
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# create a virtualhost
|
|
94
|
+
if !get_status(:virtualhost, :packages)
|
|
95
|
+
create_virtualhost
|
|
96
|
+
else
|
|
97
|
+
puts 'Virtualhost already created'
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# create a starter theme
|
|
101
|
+
if !get_status(:starter_theme, :packages)
|
|
102
|
+
create_starter_theme
|
|
103
|
+
else
|
|
104
|
+
puts 'Starter theme already created'
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def get_status(field, namespace)
|
|
113
|
+
if read_status && !namespace.nil? && !field.nil?
|
|
114
|
+
@status[namespace.to_sym][field.to_sym] rescue nil
|
|
115
|
+
else
|
|
116
|
+
nil
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def set_status(field, value, namespace)
|
|
121
|
+
if !namespace.nil? && !field.nil?
|
|
122
|
+
@status[namespace.to_sym][field.to_sym] = value
|
|
123
|
+
write_status
|
|
124
|
+
else
|
|
125
|
+
nil
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def read_status
|
|
130
|
+
YAML::load_file("#{base_path}/#{@status_file}") rescue nil
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def write_status
|
|
134
|
+
system("#{enter_base_path}")
|
|
135
|
+
File.open("#{base_path}/#{@status_file}", 'w') { |f| f.puts @status.to_yaml }
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def name
|
|
140
|
+
sanitized_name
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def say_hello
|
|
145
|
+
shell = TTY::Shell.new
|
|
146
|
+
answer = shell.ask "What is your name?" do
|
|
147
|
+
argument :required
|
|
148
|
+
default 'Piotr'
|
|
149
|
+
validate /\w+\s\w+/
|
|
150
|
+
#valid ['Piotr', 'Piotrek']
|
|
151
|
+
modify :capitalize
|
|
152
|
+
end.read_string
|
|
153
|
+
puts "Hello world! #{@name}, this is your answer: #{answer}"
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def check_requirements
|
|
157
|
+
@npm = TTY::Which.which('npm')
|
|
158
|
+
@wp_cli = TTY::Which.which('wp')
|
|
159
|
+
@virtualhost = TTY::Which.which('virtualhost.sh')
|
|
160
|
+
satisfy_requirements = (@npm.empty? && @wp_cli.empty? ? false : true)
|
|
161
|
+
if !satisfy_requirements
|
|
162
|
+
puts 'Error: Before proceding, you\'ve to install:'
|
|
163
|
+
puts '- npm: Node.js Packet Manager ' if @npm.empty?
|
|
164
|
+
puts '- wp_cli: Wordpress Command Line Tool ' if @wp_cli.empty?
|
|
165
|
+
puts '- virtualhost.sh: add a virtual host to your apache conf' if @virtualhost.empty?
|
|
166
|
+
else
|
|
167
|
+
puts 'Requirement satisfied! Good, now we could proceed installing wp...'
|
|
168
|
+
end
|
|
169
|
+
return satisfy_requirements
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def create_database
|
|
173
|
+
if !get_status(:create_database, :packages)
|
|
174
|
+
puts 'Creating database'
|
|
175
|
+
db_host = get_status(:db_host, :mysql)
|
|
176
|
+
db_user = get_status(:db_user, :mysql)
|
|
177
|
+
db_pass = get_status(:db_pass, :mysql)
|
|
178
|
+
db_name = get_status(:db_name, :mysql)
|
|
179
|
+
client = Mysql2::Client.new(:host => db_host, :username => db_user, :password => db_pass)
|
|
180
|
+
|
|
181
|
+
if client && (!db_host.nil? && !db_user.nil?)
|
|
182
|
+
#client.query("DROP DATABASE IF EXISTS #{db_name}")
|
|
183
|
+
client.query("CREATE DATABASE #{db_name}") rescue 'DB already exists'
|
|
184
|
+
client.close
|
|
185
|
+
puts "Database #{name} created successfully."
|
|
186
|
+
set_status(:create_database, true, :packages)
|
|
187
|
+
else
|
|
188
|
+
puts "Can't connect to your database."
|
|
189
|
+
puts "Please edit #{@base_root}/gentheme.conf your mysql account connection and add the mysql lines:"
|
|
190
|
+
puts @default_status.to_yaml
|
|
191
|
+
end
|
|
192
|
+
else
|
|
193
|
+
puts "Database already created!"
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def install_yeoman
|
|
200
|
+
installed_packages = []
|
|
201
|
+
yo = false
|
|
202
|
+
generator = false
|
|
203
|
+
installed = get_status(:yeoman, :packages)
|
|
204
|
+
if installed
|
|
205
|
+
puts 'Yeoman already installed...'
|
|
206
|
+
return true
|
|
207
|
+
else
|
|
208
|
+
if !@npm.empty?
|
|
209
|
+
puts 'Checking for yeoman and generator-gulp-webapp generator...'
|
|
210
|
+
#{}`#{npm} install --global yo generator-gulp-webapp`
|
|
211
|
+
result = `#{@npm} ll --global --parseable --silent yo generator-gulp-webapp`
|
|
212
|
+
raw_installed_packages = result.split("\n")
|
|
213
|
+
raw_installed_packages.each do |packs|
|
|
214
|
+
p = packs.split(':')
|
|
215
|
+
name = p[1].split('@')[0]
|
|
216
|
+
path = p[0]
|
|
217
|
+
version = p[1].split('@')[1]
|
|
218
|
+
installed_packages << {name: name, path: path, version: version}
|
|
219
|
+
|
|
220
|
+
generator = true if name == 'generator-gulp-webapp'
|
|
221
|
+
yo = true if name == 'yo'
|
|
222
|
+
end
|
|
223
|
+
if generator == false || yo == false
|
|
224
|
+
puts "Installing #{'yo' if !yo} #{'generator-gulp-webapp' if !generator}..."
|
|
225
|
+
result = system("#{@npm} install --silent #{'yo' if !yo} #{'generator-gulp-webapp' if !generator}")
|
|
226
|
+
puts result
|
|
227
|
+
else
|
|
228
|
+
puts 'OK: yeoman and generator-gulp-webapp found on your system'
|
|
229
|
+
end
|
|
230
|
+
set_status(:yeoman, true, :packages)
|
|
231
|
+
return true
|
|
232
|
+
else
|
|
233
|
+
puts 'Error: npm not found on you system.'
|
|
234
|
+
return false
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def install_gulp_webapp
|
|
240
|
+
if !get_status(:gulp_webapp, :packages)
|
|
241
|
+
puts 'Installing gulp-webapp scaffold...'
|
|
242
|
+
puts "#{enter_base_path} && yo gulp-webapp"
|
|
243
|
+
system("#{enter_base_path} && yo gulp-webapp")
|
|
244
|
+
set_status(:gulp_webapp, true, :packages)
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def install_wordpress
|
|
249
|
+
puts 'Installing Wordpress...'
|
|
250
|
+
if @wp_cli && !get_status(:wordpress, :packages)
|
|
251
|
+
system("#{enter_base_path} && mkdir -p wordpress && #{@wp_cli} core download --path=./wordpress/")
|
|
252
|
+
set_status(:wordpress, true, :packages)
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def add_wp_gitignore
|
|
258
|
+
puts 'appending wordpress to gitignore...'
|
|
259
|
+
if !get_status(:wp_gitignore, :packages)
|
|
260
|
+
system("#{enter_base_path} && echo '## Mac\n.DS_Store\n\n## WordPress\nwordpress\n' >> .gitignore")
|
|
261
|
+
set_status(:wp_gitignore, true, :packages)
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def create_virtualhost
|
|
267
|
+
puts 'Creating virtualhost...'
|
|
268
|
+
if @virtualhost && !get_status(:virtualhost, :packages)
|
|
269
|
+
system("virtualhost.sh #{name} #{base_path}/wordpress")
|
|
270
|
+
set_status(:virtualhost, true, :packages)
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def create_starter_theme
|
|
276
|
+
puts 'Creating starter theme...'
|
|
277
|
+
if !get_status(:starter_theme, :packages)
|
|
278
|
+
system("#{enter_base_path} && cd wordpress && wp core config --dbname=#{name} --dbuser=root --dbhost=127.0.0.1 --skip-check")
|
|
279
|
+
system("#{enter_base_path} && cd wordpress && wp core install --title=#{name} --admin_user=admin --admin_password=#{name} --admin_email=youremail@#{name}.example.com --url=http://#{name} ")
|
|
280
|
+
system("#{enter_base_path} && rm wordpress/wp-content/themes/#{name}")
|
|
281
|
+
system("#{enter_base_path} && mv app app_#{rand(10000)}")
|
|
282
|
+
system("#{enter_base_path} && mkdir app")
|
|
283
|
+
system("#{enter_base_path} && cd wordpress && wp scaffold _s #{name} --activate")
|
|
284
|
+
system("#{enter_base_path} && mv wordpress/wp-content/themes/#{name}/* app/")
|
|
285
|
+
system("#{enter_base_path} && rmdir wordpress/wp-content/themes/#{name}")
|
|
286
|
+
system("#{enter_base_path} && ln -s #{base_path}/app/ wordpress/wp-content/themes/#{name}")
|
|
287
|
+
set_status(:starter_theme, true, :packages)
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
private
|
|
293
|
+
|
|
294
|
+
def base_path
|
|
295
|
+
# I'm already inside the project?
|
|
296
|
+
if File.exist?(File.join(@root_path, @status_file))
|
|
297
|
+
@root_path
|
|
298
|
+
else
|
|
299
|
+
File.join(@root_path, @name)
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
def enter_base_path
|
|
304
|
+
#cmd = "mkdir -p #{base_path} && cd $_"
|
|
305
|
+
cmd = "cd #{base_path}"
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
def path_to(target)
|
|
309
|
+
"#{base_path}/#{target}"
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
def sanitized_name
|
|
313
|
+
@name.gsub(/([A-Z])([a-z])/, '_\1\2').sub(/^_/, '').downcase
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def generate_app_directory
|
|
318
|
+
FileUtils.mkdir(base_path) if !Dir.exist?(base_path)
|
|
319
|
+
set_status(:app_directory, true, :packages)
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def generate_subdirectories
|
|
323
|
+
['build'].each do |dir|
|
|
324
|
+
FileUtils.mkdir(path_to(dir))
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
def generate_file(source, output)
|
|
329
|
+
source_file = File.expand_path("../../../templates/#{source}", __FILE__)
|
|
330
|
+
|
|
331
|
+
erb = ERB.new(File.read(source_file))
|
|
332
|
+
File.open(path_to(output), 'w') { |f| f << erb.result(binding) }
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
end
|
data/lib/gentheme/version.rb
CHANGED
data/lib/gentheme.rb
CHANGED
|
@@ -6,305 +6,4 @@ require 'yaml'
|
|
|
6
6
|
require 'mysql2'
|
|
7
7
|
|
|
8
8
|
require "gentheme/version"
|
|
9
|
-
|
|
10
|
-
module Gentheme
|
|
11
|
-
class Generator
|
|
12
|
-
|
|
13
|
-
attr_reader :root_path
|
|
14
|
-
|
|
15
|
-
def initialize(name, options)
|
|
16
|
-
@name = name
|
|
17
|
-
@root_path = options[:path]
|
|
18
|
-
@verbose = options[:verbose]
|
|
19
|
-
@npm = false
|
|
20
|
-
@wp_cli = false
|
|
21
|
-
@virtualhost = false
|
|
22
|
-
|
|
23
|
-
@status_file = "gentheme.conf"
|
|
24
|
-
@default_status = {
|
|
25
|
-
general: {
|
|
26
|
-
project_name: name,
|
|
27
|
-
generator: 'gentheme',
|
|
28
|
-
generator_version: Gentheme::VERSION,
|
|
29
|
-
created_at: Time.now,
|
|
30
|
-
updated_at: Time.now
|
|
31
|
-
},
|
|
32
|
-
mysql: {
|
|
33
|
-
db_host: "127.0.0.1",
|
|
34
|
-
db_user: "root",
|
|
35
|
-
db_pass: "",
|
|
36
|
-
db_name: name
|
|
37
|
-
},
|
|
38
|
-
packages: {
|
|
39
|
-
|
|
40
|
-
}}
|
|
41
|
-
@status = read_status
|
|
42
|
-
if @status.nil?
|
|
43
|
-
@status = @default_status
|
|
44
|
-
write_status
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def start
|
|
51
|
-
|
|
52
|
-
if check_requirements
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
# Create database
|
|
57
|
-
if !get_status(:create_database, :packages)
|
|
58
|
-
create_database
|
|
59
|
-
else
|
|
60
|
-
puts 'Database already created.'
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# Install gulp-webapp
|
|
64
|
-
if !get_status(:gulp_webapp, :packages)
|
|
65
|
-
install_gulp_webapp if install_yeoman
|
|
66
|
-
else
|
|
67
|
-
puts 'Gulp-webapp is already installed'
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
#install wordpress
|
|
71
|
-
if !get_status(:wordpress, :packages)
|
|
72
|
-
install_wordpress
|
|
73
|
-
else
|
|
74
|
-
puts 'Wordpress is already installed'
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# append wp gitignore
|
|
78
|
-
if !get_status(:wp_gitignore, :packages)
|
|
79
|
-
add_wp_gitignore
|
|
80
|
-
else
|
|
81
|
-
puts 'Wordpress is already added to gitignore'
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
# create a virtualhost
|
|
85
|
-
if !get_status(:virtualhost, :packages)
|
|
86
|
-
create_virtualhost
|
|
87
|
-
else
|
|
88
|
-
puts 'Virtualhost already created'
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
# create a starter theme
|
|
92
|
-
if !get_status(:starter_theme, :packages)
|
|
93
|
-
create_starter_theme
|
|
94
|
-
else
|
|
95
|
-
puts 'Starter theme already created'
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def get_status(field, namespace)
|
|
104
|
-
if read_status && !namespace.nil? && !field.nil?
|
|
105
|
-
@status[namespace.to_sym][field.to_sym] rescue nil
|
|
106
|
-
else
|
|
107
|
-
nil
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def set_status(field, value, namespace)
|
|
112
|
-
if !namespace.nil? && !field.nil?
|
|
113
|
-
@status[namespace.to_sym][field.to_sym] = value
|
|
114
|
-
write_status
|
|
115
|
-
else
|
|
116
|
-
nil
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def read_status
|
|
121
|
-
YAML::load_file("#{base_path}/#{@status_file}") rescue nil
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def write_status
|
|
125
|
-
system("#{enter_base_path}")
|
|
126
|
-
File.open("#{base_path}/#{@status_file}", 'w') { |f| f.puts @status.to_yaml }
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
def name
|
|
131
|
-
sanitized_name
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
def say_hello
|
|
136
|
-
shell = TTY::Shell.new
|
|
137
|
-
answer = shell.ask "What is your name?" do
|
|
138
|
-
argument :required
|
|
139
|
-
default 'Piotr'
|
|
140
|
-
validate /\w+\s\w+/
|
|
141
|
-
#valid ['Piotr', 'Piotrek']
|
|
142
|
-
modify :capitalize
|
|
143
|
-
end.read_string
|
|
144
|
-
puts "Hello world! #{@name}, this is your answer: #{answer}"
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
def check_requirements
|
|
148
|
-
@npm = TTY::Which.which('npm')
|
|
149
|
-
@wp_cli = TTY::Which.which('wp')
|
|
150
|
-
@virtualhost = TTY::Which.which('virtualhost.sh')
|
|
151
|
-
satisfy_requirements = (@npm.empty? && @wp_cli.empty? ? false : true)
|
|
152
|
-
if !satisfy_requirements
|
|
153
|
-
puts 'Error: Before proceding, you\'ve to install:'
|
|
154
|
-
puts '- npm: Node.js Packet Manager ' if @npm.empty?
|
|
155
|
-
puts '- wp_cli: Wordpress Command Line Tool ' if @wp_cli.empty?
|
|
156
|
-
puts '- virtualhost.sh: add a virtual host to your apache conf' if @virtualhost.empty?
|
|
157
|
-
else
|
|
158
|
-
puts 'Requirement satisfied! Good, now we could proceed installing wp...'
|
|
159
|
-
end
|
|
160
|
-
return satisfy_requirements
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
def create_database
|
|
164
|
-
if !get_status(:create_database, :packages)
|
|
165
|
-
puts 'Creating database'
|
|
166
|
-
db_host = get_status(:db_host, :mysql)
|
|
167
|
-
db_user = get_status(:db_user, :mysql)
|
|
168
|
-
db_pass = get_status(:db_pass, :mysql)
|
|
169
|
-
db_name = get_status(:db_name, :mysql)
|
|
170
|
-
client = Mysql2::Client.new(:host => db_host, :username => db_user, :password => db_pass)
|
|
171
|
-
|
|
172
|
-
if client && (!db_host.nil? && !db_user.nil?)
|
|
173
|
-
#client.query("DROP DATABASE IF EXISTS #{db_name}")
|
|
174
|
-
client.query("CREATE DATABASE #{db_name}") rescue 'DB already exists'
|
|
175
|
-
client.close
|
|
176
|
-
puts "Database #{name} created successfully."
|
|
177
|
-
set_status(:create_database, true, :packages)
|
|
178
|
-
else
|
|
179
|
-
puts "Can't connect to your database."
|
|
180
|
-
puts "Please edit #{@base_root}/gentheme.conf your mysql account connection and add the mysql lines:"
|
|
181
|
-
puts @default_status.to_yaml
|
|
182
|
-
end
|
|
183
|
-
else
|
|
184
|
-
puts "Database already created!"
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
def install_yeoman
|
|
191
|
-
installed_packages = []
|
|
192
|
-
yo = false
|
|
193
|
-
generator = false
|
|
194
|
-
installed = get_status(:yeoman, :packages)
|
|
195
|
-
if installed
|
|
196
|
-
puts 'Yeoman already installed...'
|
|
197
|
-
return true
|
|
198
|
-
else
|
|
199
|
-
if !@npm.empty?
|
|
200
|
-
puts 'Checking for yeoman and generator-gulp-webapp generator...'
|
|
201
|
-
#{}`#{npm} install --global yo generator-gulp-webapp`
|
|
202
|
-
result = `#{@npm} ll --global --parseable --silent yo generator-gulp-webapp`
|
|
203
|
-
raw_installed_packages = result.split("\n")
|
|
204
|
-
raw_installed_packages.each do |packs|
|
|
205
|
-
p = packs.split(':')
|
|
206
|
-
name = p[1].split('@')[0]
|
|
207
|
-
path = p[0]
|
|
208
|
-
version = p[1].split('@')[1]
|
|
209
|
-
installed_packages << {name: name, path: path, version: version}
|
|
210
|
-
|
|
211
|
-
generator = true if name == 'generator-gulp-webapp'
|
|
212
|
-
yo = true if name == 'yo'
|
|
213
|
-
end
|
|
214
|
-
if generator == false || yo == false
|
|
215
|
-
puts "Installing #{'yo' if !yo} #{'generator-gulp-webapp' if !generator}..."
|
|
216
|
-
result = system("#{@npm} install --silent #{'yo' if !yo} #{'generator-gulp-webapp' if !generator}")
|
|
217
|
-
puts result
|
|
218
|
-
else
|
|
219
|
-
puts 'OK: yeoman and generator-gulp-webapp found on your system'
|
|
220
|
-
end
|
|
221
|
-
set_status(:yeoman, true, :packages)
|
|
222
|
-
return true
|
|
223
|
-
else
|
|
224
|
-
puts 'Error: npm not found on you system.'
|
|
225
|
-
return false
|
|
226
|
-
end
|
|
227
|
-
end
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
def install_gulp_webapp
|
|
231
|
-
if !get_status(:gulp_webapp, :packages)
|
|
232
|
-
puts 'Installing gulp-webapp scaffold...'
|
|
233
|
-
system("#{enter_base_path} && yo gulp-webapp")
|
|
234
|
-
set_status(:gulp_webapp, true, :packages)
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
def install_wordpress
|
|
239
|
-
puts 'Installing Wordpress...'
|
|
240
|
-
if @wp_cli && !get_status(:wordpress, :packages)
|
|
241
|
-
system("#{enter_base_path} && mkdir -p wordpress && #{@wp_cli} core download --path=./wordpress/")
|
|
242
|
-
set_status(:wordpress, true, :packages)
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
def add_wp_gitignore
|
|
248
|
-
puts 'appending wordpress to gitignore...'
|
|
249
|
-
if !get_status(:wp_gitignore, :packages)
|
|
250
|
-
system("#{enter_base_path} && echo '## Mac\n.DS_Store\n\n## WordPress\nwordpress\n' >> .gitignore")
|
|
251
|
-
set_status(:wp_gitignore, true, :packages)
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
def create_virtualhost
|
|
257
|
-
puts 'Creating virtualhost...'
|
|
258
|
-
if @virtualhost && !get_status(:virtualhost, :packages)
|
|
259
|
-
system("virtualhost.sh #{name} #{base_path}/wordpress")
|
|
260
|
-
set_status(:virtualhost, true, :packages)
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
end
|
|
264
|
-
|
|
265
|
-
def create_starter_theme
|
|
266
|
-
puts 'Creating starter theme...'
|
|
267
|
-
if !get_status(:starter_theme, :packages)
|
|
268
|
-
system("#{enter_base_path} && cd wordpress && wp core config --dbname=#{name} --dbuser=root --dbhost=127.0.0.1 --skip-check")
|
|
269
|
-
system("#{enter_base_path} && cd wordpress && wp core install --title=#{name} --admin_user=admin --admin_password=#{name} --admin_email=youremail@#{name}.example.com --url=http://#{name} ")
|
|
270
|
-
system("#{enter_base_path} && rm wordpress/wp-content/themes/#{name}")
|
|
271
|
-
system("#{enter_base_path} && mv app app_#{rand(10000)}")
|
|
272
|
-
system("#{enter_base_path} && mkdir app")
|
|
273
|
-
system("#{enter_base_path} && cd wordpress && wp scaffold _s #{name} --activate")
|
|
274
|
-
system("#{enter_base_path} && mv wordpress/wp-content/themes/#{name}/* app/")
|
|
275
|
-
system("#{enter_base_path} && rmdir wordpress/wp-content/themes/#{name}")
|
|
276
|
-
system("#{enter_base_path} && ln -s #{base_path}/app/ wordpress/wp-content/themes/#{name}")
|
|
277
|
-
set_status(:starter_theme, true, :packages)
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
end
|
|
281
|
-
|
|
282
|
-
private
|
|
283
|
-
|
|
284
|
-
def base_path
|
|
285
|
-
|
|
286
|
-
# I'm already inside the project?
|
|
287
|
-
if File.exist?( File.join(@root_path, @status_file) )
|
|
288
|
-
@root_path
|
|
289
|
-
else
|
|
290
|
-
File.join(@root_path, @name)
|
|
291
|
-
end
|
|
292
|
-
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
def enter_base_path
|
|
296
|
-
cmd = "mkdir -p #{base_path} && cd $_"
|
|
297
|
-
#{}`#{cmd}`
|
|
298
|
-
#cmd
|
|
299
|
-
end
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
def sanitized_name
|
|
303
|
-
@name.gsub(/([A-Z])([a-z])/, '_\1\2').sub(/^_/, '').downcase
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
end
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
end
|
|
9
|
+
require "gentheme/gem"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gentheme
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michele Gobbi
|
|
@@ -132,6 +132,7 @@ files:
|
|
|
132
132
|
- bin/setup
|
|
133
133
|
- gentheme.gemspec
|
|
134
134
|
- lib/gentheme.rb
|
|
135
|
+
- lib/gentheme/gem.rb
|
|
135
136
|
- lib/gentheme/version.rb
|
|
136
137
|
homepage: https://github.com/dynamick/gentheme
|
|
137
138
|
licenses:
|