theme-juice 0.6.18 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +106 -75
  3. data/bin/tj +5 -5
  4. data/lib/theme-juice.rb +32 -16
  5. data/lib/theme-juice/cli.rb +191 -298
  6. data/lib/theme-juice/command.rb +14 -13
  7. data/lib/theme-juice/commands/create.rb +214 -9
  8. data/lib/theme-juice/commands/delete.rb +45 -10
  9. data/lib/theme-juice/commands/deploy.rb +20 -0
  10. data/lib/theme-juice/config.rb +43 -0
  11. data/lib/theme-juice/env.rb +25 -0
  12. data/lib/theme-juice/io.rb +323 -0
  13. data/lib/theme-juice/project.rb +35 -0
  14. data/lib/theme-juice/task.rb +42 -0
  15. data/lib/theme-juice/tasks/create_confirm.rb +33 -0
  16. data/lib/theme-juice/tasks/create_success.rb +42 -0
  17. data/lib/theme-juice/tasks/database.rb +50 -0
  18. data/lib/theme-juice/tasks/delete_confirm.rb +24 -0
  19. data/lib/theme-juice/tasks/delete_success.rb +31 -0
  20. data/lib/theme-juice/tasks/dns.rb +45 -0
  21. data/lib/theme-juice/tasks/dot_env.rb +53 -0
  22. data/lib/theme-juice/tasks/entry.rb +50 -0
  23. data/lib/theme-juice/tasks/hosts.rb +43 -0
  24. data/lib/theme-juice/tasks/import_database.rb +28 -0
  25. data/lib/theme-juice/tasks/landrush.rb +33 -0
  26. data/lib/theme-juice/tasks/list.rb +50 -0
  27. data/lib/theme-juice/tasks/location.rb +23 -0
  28. data/lib/theme-juice/tasks/nginx.rb +51 -0
  29. data/lib/theme-juice/tasks/repo.rb +49 -0
  30. data/lib/theme-juice/tasks/synced_folder.rb +30 -0
  31. data/lib/theme-juice/tasks/theme.rb +34 -0
  32. data/lib/theme-juice/tasks/vm.rb +30 -0
  33. data/lib/theme-juice/tasks/vm_customfile.rb +42 -0
  34. data/lib/theme-juice/tasks/vm_location.rb +32 -0
  35. data/lib/theme-juice/tasks/vm_plugins.rb +32 -0
  36. data/lib/theme-juice/tasks/vm_provision.rb +39 -0
  37. data/lib/theme-juice/tasks/vm_restart.rb +25 -0
  38. data/lib/theme-juice/tasks/wp_cli.rb +52 -0
  39. data/lib/theme-juice/util.rb +45 -0
  40. data/lib/theme-juice/version.rb +1 -1
  41. metadata +66 -34
  42. data/LICENSE +0 -339
  43. data/lib/theme-juice/commands/install.rb +0 -16
  44. data/lib/theme-juice/commands/list.rb +0 -16
  45. data/lib/theme-juice/commands/subcommand.rb +0 -16
  46. data/lib/theme-juice/environment.rb +0 -15
  47. data/lib/theme-juice/interaction.rb +0 -445
  48. data/lib/theme-juice/interactions/create.rb +0 -278
  49. data/lib/theme-juice/interactions/delete.rb +0 -48
  50. data/lib/theme-juice/interactions/teejay.rb +0 -12
  51. data/lib/theme-juice/service.rb +0 -224
  52. data/lib/theme-juice/services/config.rb +0 -44
  53. data/lib/theme-juice/services/create.rb +0 -376
  54. data/lib/theme-juice/services/delete.rb +0 -113
  55. data/lib/theme-juice/services/list.rb +0 -40
@@ -1,44 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module ThemeJuice
4
- class Service::Config < ::ThemeJuice::Service
5
-
6
- #
7
- # @param {Hash} opts
8
- #
9
- def initialize(opts = {})
10
- super
11
- end
12
-
13
- #
14
- # Run installation from config
15
- #
16
- # @return {Void}
17
- #
18
- def install
19
- load_config
20
-
21
- @config["commands"]["install"].each do |command|
22
- run ["cd #{@config_path}", command], false
23
- end
24
- end
25
-
26
- #
27
- # Run subcommand from config
28
- #
29
- # @param {String} subcommand
30
- # @param {String} command
31
- #
32
- # @return {Void}
33
- #
34
- def subcommand(subcommand, command)
35
- load_config
36
-
37
- if @config["commands"][subcommand]
38
- run ["#{@config["commands"][subcommand]} #{command}"], false
39
- else
40
- @interaction.error "Unable to find '#{subcommand}' command in '#{@config_path}/tj.yml'. Aborting mission."
41
- end
42
- end
43
- end
44
- end
@@ -1,376 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module ThemeJuice
4
- class Service::Create < ::ThemeJuice::Service
5
-
6
- #
7
- # @param {Hash} opts
8
- #
9
- def initialize(opts = {})
10
- opts = ::ThemeJuice::Interaction::Create.setup_site_options(opts)
11
- super
12
- end
13
-
14
- #
15
- # Set up local development environment and site
16
- #
17
- # @return {Void}
18
- #
19
- def create
20
- @interaction.notice "Running setup for '#{@opts[:site_name]}'"
21
-
22
- setup_project_dir unless project_dir_is_setup?
23
- setup_starter_theme unless starter_theme_is_setup?
24
- setup_vvv unless vvv_is_setup?
25
- setup_wildcard_subdomains unless wildcard_subdomains_is_setup?
26
- setup_hosts unless hosts_is_setup?
27
- setup_database unless database_is_setup?
28
- setup_nginx unless nginx_is_setup?
29
- setup_dev_site unless dev_site_is_setup?
30
- setup_env unless env_is_setup?
31
- setup_synced_folder unless synced_folder_is_setup?
32
- setup_wpcli unless wpcli_is_setup?
33
- setup_repo if using_repo?
34
-
35
- if setup_was_successful?
36
- @interaction.success "Setup complete!"
37
- @interaction.speak "In order to finish creating your site, you need to provision Vagrant. Do it now? (y/N)", {
38
- :color => [:black, :on_blue],
39
- :icon => :restart,
40
- :row => true
41
- }
42
-
43
- if @interaction.agree? "", { :simple => true }
44
-
45
- if restart_vagrant
46
- @interaction.success "Success!"
47
-
48
- # Output setup info
49
- @interaction.list "Your settings :", :blue, [
50
- "Site name: #{@opts[:site_name]}",
51
- "Site location: #{@opts[:site_location]}",
52
- "Starter theme: #{@opts[:site_starter_theme]}",
53
- "Development location: #{@opts[:site_dev_location]}",
54
- "Development url: http://#{@opts[:site_dev_url]}",
55
- "Initialized repository: #{@opts[:site_repository]}",
56
- "Database host: #{@opts[:site_db_host]}",
57
- "Database name: #{@opts[:site_db_name]}",
58
- "Database username: #{@opts[:site_db_user]}",
59
- "Database password: #{@opts[:site_db_pass]}"
60
- ]
61
-
62
- @interaction.speak "Do you want to open up your new site 'http://#{@opts[:site_dev_url]}' now? (y/N)", {
63
- :color => [:black, :on_blue],
64
- :icon => :restart,
65
- :row => true
66
- }
67
-
68
- if @interaction.agree? "", { :simple => true }
69
- run ["open http://#{@opts[:site_dev_url]}"]
70
- end
71
- end
72
- else
73
- @interaction.notice "Remember, Vagrant needs to be provisioned before you can use your new site. Exiting..."
74
- exit
75
- end
76
- else
77
- @interaction.error "Setup failed. Running cleanup" do
78
- ::ThemeJuice::Service::Delete.new({ :site_name => @opts[:site_name], :restart => false }).delete
79
- end
80
- end
81
- end
82
-
83
- private
84
-
85
- #
86
- # Install Vagrant plugins and clone VVV
87
- #
88
- # @return {Void}
89
- #
90
- def setup_vvv
91
- @interaction.log "Installing VVV"
92
-
93
- run [
94
- "vagrant plugin install vagrant-hostsupdater",
95
- "vagrant plugin install vagrant-triggers",
96
- "vagrant plugin install landrush",
97
- "git clone https://github.com/Varying-Vagrant-Vagrants/VVV.git #{@environment.vvv_path}",
98
- "touch #{@environment.vvv_path}/database/init-custom.sql"
99
- ]
100
- end
101
-
102
- #
103
- # Ensure project directory structure
104
- #
105
- # @return {Void}
106
- #
107
- def setup_project_dir
108
- @interaction.log "Creating project directory tree"
109
-
110
- run ["mkdir -p #{@opts[:site_location]}"]
111
- end
112
-
113
- #
114
- # Enable Landrush for wildcard subdomains
115
- #
116
- # This will write a Landrush activation block to the global Vagrantfile
117
- # if one does not already exist.
118
- #
119
- # @return {Void}
120
- #
121
- def setup_wildcard_subdomains
122
- @interaction.log "Setting up wildcard subdomains"
123
-
124
- File.open File.expand_path("#{@environment.vvv_path}/Vagrantfile"), "a+" do |file|
125
- file.puts "\n"
126
- file.puts "###"
127
- file.puts "# Enable wildcard subdomains"
128
- file.puts "#"
129
- file.puts "# This block is automatically generated by Theme Juice. Do not edit."
130
- file.puts "###"
131
- file.puts "Vagrant.configure('2') do |config|"
132
- file.puts "\tconfig.landrush.enabled = true"
133
- file.puts "\tconfig.landrush.tld = 'dev'"
134
- file.puts "end"
135
- file.puts "\n"
136
- end
137
- end
138
-
139
- #
140
- # Create a new directory for site that will be symlinked with the local install
141
- #
142
- # @return {Void}
143
- #
144
- def setup_dev_site
145
- @interaction.log "Setting up new site in VM"
146
-
147
- run [
148
- "cd #{@environment.vvv_path}/www",
149
- "mkdir tj-#{@opts[:site_name]}",
150
- ]
151
- end
152
-
153
- #
154
- # Create tj.yml file for theme settings
155
- #
156
- # @return {Void}
157
- #
158
- def setup_config
159
- @interaction.log "Creating config"
160
-
161
- watch = @interaction.prompt "Watch command to use", :indent => 2, :default => "bundle exec guard"
162
- server = @interaction.prompt "Deployment command to use", :indent => 2, :default => "bundle exec cap"
163
- vendor = @interaction.prompt "Vendor command to use", :indent => 2, :default => "composer"
164
- install = @interaction.prompt "Commands to run on theme install (comma-delimited)", :indent => 2, :default => "composer install"
165
-
166
- File.open "#{@config_path}/tj.yml", "w" do |file|
167
- file.puts "commands:"
168
- file.puts "\s\swatch: #{watch}"
169
- file.puts "\s\sserver: #{server}"
170
- file.puts "\s\svendor: #{vendor}"
171
- file.puts "\s\sinstall:"
172
- install.split(",").map!(&:strip).each do |command|
173
- file.puts "\s\s\s\s- #{command}"
174
- end
175
- end
176
-
177
- unless config_is_setup?
178
- @interaction.error "Could not create 'tj.yml' file. Make sure you have write capabilities to '#{@opts[:site_location]}'."
179
- end
180
- end
181
-
182
- #
183
- # Create vvv-hosts file
184
- #
185
- # @return {Void}
186
- #
187
- def setup_hosts
188
- @interaction.log "Setting up hosts"
189
-
190
- File.open "#{@opts[:site_location]}/vvv-hosts", "w" do |file|
191
- file.puts @opts[:site_dev_url]
192
- end
193
-
194
- unless hosts_is_setup?
195
- @interaction.error "Could not create 'vvv-hosts' file. Make sure you have write capabilities to '#{@opts[:site_location]}'."
196
- end
197
- end
198
-
199
- #
200
- # Add database block to init-custom.sql, create if not exists
201
- #
202
- # @return {Void}
203
- #
204
- def setup_database
205
- @interaction.log "Setting up database"
206
-
207
- File.open File.expand_path("#{@environment.vvv_path}/database/init-custom.sql"), "a+" do |file|
208
- file.puts "### Begin '#{@opts[:site_name]}'"
209
- file.puts "#"
210
- file.puts "# This block is automatically generated by Theme Juice. Do not edit."
211
- file.puts "###"
212
- file.puts "CREATE DATABASE IF NOT EXISTS `#{@opts[:site_db_name]}`;"
213
- file.puts "GRANT ALL PRIVILEGES ON `#{@opts[:site_db_name]}`.* TO '#{@opts[:site_db_user]}'@'localhost' IDENTIFIED BY '#{@opts[:site_db_pass]}';"
214
- file.puts "### End '#{@opts[:site_name]}'"
215
- file.puts "\n"
216
- end
217
-
218
- unless database_is_setup?
219
- @interaction.error "Could not add database info for '#{@opts[:site_name]}' to 'init-custom.sql'. Make sure you have write capabilities to '#{@environment.vvv_path}'."
220
- end
221
- end
222
-
223
- #
224
- # Create vvv-nginx.conf file for local development site
225
- #
226
- # @return {Void}
227
- #
228
- def setup_nginx
229
- @interaction.log "Setting up nginx"
230
-
231
- File.open "#{@opts[:site_location]}/vvv-nginx.conf", "w" do |file|
232
- file.puts "server {"
233
- file.puts "\tlisten 80;"
234
- file.puts "\tserver_name .#{@opts[:site_dev_url]};"
235
- file.puts "\troot {vvv_path_to_folder};"
236
- file.puts "\tinclude /etc/nginx/nginx-wp-common.conf;"
237
- file.puts "}"
238
- end
239
-
240
- unless nginx_is_setup?
241
- @interaction.error "Could not create 'vvv-nginx.conf' file. Make sure you have write capabilities to '#{@opts[:site_location]}'."
242
- end
243
- end
244
-
245
- #
246
- # Create Dotenv environment file
247
- #
248
- # @return {Void}
249
- #
250
- def setup_env
251
- @interaction.log "Setting up environment"
252
-
253
- File.open "#{@opts[:site_location]}/.env.development", "w" do |file|
254
- file.puts "DB_NAME=#{@opts[:site_db_name]}"
255
- file.puts "DB_USER=#{@opts[:site_db_user]}"
256
- file.puts "DB_PASSWORD=#{@opts[:site_db_pass]}"
257
- file.puts "DB_HOST=#{@opts[:site_db_host]}"
258
- file.puts "WP_HOME=http://#{@opts[:site_dev_url]}"
259
- file.puts "WP_SITEURL=http://#{@opts[:site_dev_url]}/wp"
260
- end
261
-
262
- unless env_is_setup?
263
- @interaction.error "Could not create '.env.development' file. Make sure you have write capabilities to '#{@opts[:site_location]}'."
264
- end
265
- end
266
-
267
- #
268
- # Clone starter theme into site location, run install
269
- #
270
- # @return {Void}
271
- #
272
- def setup_starter_theme
273
- unless @opts[:site_bare]
274
- @interaction.log "Setting up starter theme"
275
-
276
- run [
277
- "cd #{@opts[:site_location]}",
278
- "git clone --depth 1 #{@opts[:site_starter_theme]} .",
279
- ]
280
-
281
- if starter_theme_is_setup?
282
- install_starter_theme_dependencies if config_is_setup?
283
- else
284
- @interaction.error "Could not setup starter theme. Make sure you have write capabilities to '#{@opts[:site_location]}'."
285
- end
286
- end
287
- end
288
-
289
- #
290
- # Add synced folder block to Vagrantfile
291
- #
292
- # @return {Void}
293
- #
294
- def setup_synced_folder
295
- @interaction.log "Syncing host theme with VM"
296
-
297
- File.open File.expand_path("#{@environment.vvv_path}/Vagrantfile"), "a+" do |file|
298
- file.puts "### Begin '#{@opts[:site_name]}'"
299
- file.puts "#"
300
- file.puts "# This block is automatically generated by Theme Juice. Do not edit."
301
- file.puts "###"
302
- file.puts "Vagrant.configure('2') do |config|"
303
- file.puts "\tconfig.vm.synced_folder '#{@opts[:site_location]}', '/srv/www/tj-#{@opts[:site_name]}', mount_options: ['dmode=777','fmode=777']"
304
- file.puts "\tconfig.landrush.host '#{@opts[:site_dev_url]}', '192.168.50.4'"
305
- file.puts "end"
306
- file.puts "### End '#{@opts[:site_name]}'"
307
- file.puts "\n"
308
- end
309
-
310
- unless synced_folder_is_setup?
311
- @interaction.error "Could not sync folders for '#{@opts[:site_name]}' in 'Vagrantfile'. Make sure you have write capabilities to '#{@environment.vvv_path}'."
312
- end
313
- end
314
-
315
- #
316
- # Initialize Git repo, add remote, initial commit
317
- #
318
- # @return {Void}
319
- #
320
- def setup_repo
321
- @interaction.log "Setting up Git repository"
322
-
323
- if repo_is_setup?
324
- run [
325
- "cd #{@opts[:site_location]}",
326
- "rm -rf .git",
327
- ]
328
- end
329
-
330
- run [
331
- "cd #{@opts[:site_location]}",
332
- "git init",
333
- "git remote add origin #{@opts[:repository]}",
334
- ]
335
- end
336
-
337
- ##
338
- # Add wp-cli-ssh block to wp-cli.yml
339
- #
340
- # @return {Void}
341
- #
342
- def setup_wpcli
343
- @interaction.log "Setting up WP-CLI"
344
-
345
- File.open "#{@opts[:site_location]}/wp-cli.local.yml", "a+" do |file|
346
- file.puts "require:"
347
- file.puts "\t- vendor/autoload.php"
348
- file.puts "ssh:"
349
- file.puts "\tvagrant:"
350
- file.puts "\t\turl: #{@opts[:site_dev_url]}"
351
- file.puts "\t\tpath: /srv/www/tj-#{@opts[:site_name]}"
352
- file.puts "\t\tcmd: cd #{@environment.vvv_path} && vagrant ssh-config > /tmp/vagrant_ssh_config && ssh -q %pseudotty% -F /tmp/vagrant_ssh_config default %cmd%"
353
- file.puts "\n"
354
- end
355
-
356
- unless wpcli_is_setup?
357
- @interaction.error "Could not create 'wp-cli.local.yml' file. Make sure you have write capabilities to '#{@opts[:site_location]}'."
358
- end
359
- end
360
-
361
- #
362
- # Install dependencies for starter theme
363
- #
364
- # @return {Void}
365
- #
366
- def install_starter_theme_dependencies
367
- load_config
368
-
369
- @interaction.log "Installing theme dependencies"
370
-
371
- @config["commands"]["install"].each do |command|
372
- run ["cd #{@opts[:site_location]}", command], false
373
- end
374
- end
375
- end
376
- end
@@ -1,113 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module ThemeJuice
4
- class Service::Delete < ::ThemeJuice::Service
5
-
6
- #
7
- # @param {Hash} opts
8
- #
9
- def initialize(opts)
10
- opts = ThemeJuice::Interaction::Delete.get_site_options(opts)
11
- super
12
- end
13
-
14
- #
15
- # Remove all traces of site from Vagrant
16
- #
17
- # @return {Void}
18
- #
19
- def delete
20
- @interaction.speak "Are you sure you want to delete '#{@opts[:site_name]}'? (y/N)", {
21
- :color => [:white, :on_red],
22
- :icon => :notice,
23
- :row => true
24
- }
25
-
26
- if @interaction.agree? "", { :color => :red, :simple => true }
27
-
28
- remove_dev_site if dev_site_is_setup?
29
- remove_database if database_is_setup?
30
- remove_synced_folder if synced_folder_is_setup?
31
-
32
- if removal_was_successful?
33
- @interaction.success "Site '#{@opts[:site_name]}' successfully removed!"
34
-
35
- restart_vagrant if @opts[:restart]
36
- else
37
- @interaction.error "Site '#{@opts[:site_name]}' could not be fully be removed."
38
- end
39
- end
40
- end
41
-
42
- private
43
-
44
- #
45
- # Remove all theme files from Vagrant directory
46
- #
47
- # @return {Void}
48
- #
49
- def remove_dev_site
50
-
51
- unless Dir.entries("#{@environment.vvv_path}").include? "www"
52
- @interaction.error "Cannot load VVV path. Aborting mission before something bad happens."
53
- end
54
-
55
- if run ["rm -rf #{@opts[:site_dev_location]}"]
56
- @interaction.log "Development site removed"
57
- else
58
- @interaction.error "Site '#{@opts[:site_name]}' could not be removed. Make sure you have write capabilities to '#{@opts[:site_dev_location]}'."
59
- end
60
- end
61
-
62
- #
63
- # Remove database block from init-custom.sql
64
- #
65
- # @return {Void}
66
- #
67
- def remove_database
68
- if remove_traces_from_file "#{@environment.vvv_path}/database/init-custom.sql"
69
- @interaction.log "Database removed"
70
- end
71
- end
72
-
73
- #
74
- # Remove synced folder block from Vagrantfile
75
- #
76
- # @return {Void}
77
- #
78
- def remove_synced_folder
79
- if remove_traces_from_file "#{@environment.vvv_path}/Vagrantfile"
80
- @interaction.log "Synced folders removed"
81
- end
82
- end
83
-
84
- #
85
- # Remove all traces of auto-generated content from file
86
- #
87
- # @param {String} input_file
88
- #
89
- # @return {Void}
90
- #
91
- def remove_traces_from_file(input_file)
92
- begin
93
- # Create new tempfile
94
- output_file = Tempfile.new File.basename(input_file)
95
- # Copy over contents of actual file to tempfile
96
- open File.expand_path(input_file), "r" do |file|
97
- # Remove traces of theme from contents
98
- output_file.write "#{file.read}".gsub(/(### Begin '#{@opts[:site_name]}')(.*?)(### End '#{@opts[:site_name]}')\n+/m, "")
99
- end
100
- # Move temp file to actual file location
101
- FileUtils.mv output_file, File.expand_path(input_file)
102
- rescue LoadError => err
103
- @interaction.error "There was an error!" do
104
- puts err
105
- end
106
- ensure
107
- # Make sure that the tempfile closes and is cleaned up, regardless of errors
108
- output_file.close
109
- output_file.unlink
110
- end
111
- end
112
- end
113
- end