theme-juice 0.6.18 → 0.7.0

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.
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,278 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module ThemeJuice
4
- module Interaction::Create
5
-
6
- @environment = ::ThemeJuice::Environment
7
- @interaction = ::ThemeJuice::Interaction
8
-
9
- class << self
10
-
11
- #
12
- # Set up needed site options
13
- #
14
- # @param {Hash} opts
15
- #
16
- # @return {Hash}
17
- #
18
- def setup_site_options(opts = {})
19
- @opts = opts
20
-
21
- if @environment.yolo
22
- @opts[:use_defaults] = true
23
- end
24
-
25
- @opts[:site_name] ||= setup_site_name
26
- @opts[:site_name_clean] ||= setup_site_name_clean
27
- @opts[:site_location] ||= setup_site_location
28
- @opts[:site_starter_theme] ||= setup_site_starter_theme
29
- @opts[:site_dev_location] ||= setup_site_dev_location
30
- @opts[:site_dev_url] ||= setup_site_dev_url
31
- @opts[:site_repository] ||= setup_site_repository
32
- @opts[:site_db_host] ||= setup_site_db_host
33
- @opts[:site_db_name] ||= setup_site_db_name
34
- @opts[:site_db_user] ||= setup_site_db_user
35
- @opts[:site_db_pass] ||= setup_site_db_pass
36
-
37
- # Verify that all the options are correct
38
- @interaction.list "Your settings :", :yellow, [
39
- "Site name: #{@opts[:site_name]}",
40
- "Site location: #{@opts[:site_location]}",
41
- "Starter theme: #{@opts[:site_starter_theme]}",
42
- "Development location: #{@opts[:site_dev_location]}",
43
- "Development url: http://#{@opts[:site_dev_url]}",
44
- "Initialized repository: #{@opts[:site_repository]}",
45
- "Database host: #{@opts[:site_db_host]}",
46
- "Database name: #{@opts[:site_db_name]}",
47
- "Database username: #{@opts[:site_db_user]}",
48
- "Database password: #{@opts[:site_db_pass]}"
49
- ]
50
-
51
- unless @interaction.agree? "Do the options above look correct?"
52
- @interaction.error "Dang typos... aborting mission."
53
- end
54
-
55
- @opts
56
- end
57
-
58
- private
59
-
60
- #
61
- # Site name
62
- #
63
- # @return {String}
64
- #
65
- def setup_site_name
66
- if @environment.yolo
67
- name = Faker::Company.bs.split(" ").sample.downcase
68
- else
69
- name = @interaction.prompt "What's the site name? (letters, numbers and dashes only)"
70
- end
71
-
72
- validate_site_name name
73
-
74
- name
75
- end
76
-
77
- #
78
- # Clean site name for database naming
79
- #
80
- # @return {String}
81
- #
82
- def setup_site_name_clean
83
- "#{@opts[:site_name]}".gsub(/[^\w]/, "_")[0..10]
84
- end
85
-
86
- #
87
- # Site local location
88
- #
89
- # @return {String}
90
- #
91
- def setup_site_location
92
- path = "#{Dir.pwd}/"
93
-
94
- if @opts[:use_defaults]
95
- location = File.expand_path(path)
96
- else
97
- location = File.expand_path(@interaction.prompt "Where do you want to setup the site?", :default => path, :path => true)
98
- end
99
-
100
- location
101
- end
102
-
103
- #
104
- # Site starter theme
105
- #
106
- # @return {String}
107
- #
108
- def setup_site_starter_theme
109
- if @opts[:site_bare]
110
- theme = false
111
- else
112
- themes = {
113
- "theme-juice/theme-juice-starter" => "https://github.com/ezekg/theme-juice-starter.git",
114
- "other" => nil,
115
- "none" => false
116
- }
117
-
118
- if @opts[:use_defaults]
119
- return themes["theme-juice/theme-juice-starter"]
120
- end
121
-
122
- choice = @interaction.choose "Which starter theme would you like to use?", :blue, themes.keys
123
-
124
- case choice
125
- when "theme-juice/theme-juice-starter"
126
- @interaction.success "Awesome choice!"
127
- when "other"
128
- themes[choice] = @interaction.prompt "What is the repository URL for the starter theme that you would like to clone?"
129
- when "none"
130
- @interaction.notice "Next time you need to create a site without a starter theme, you can just run the 'setup' command instead."
131
- @opts[:site_bare] = true
132
- end
133
-
134
- theme = themes[choice]
135
- end
136
-
137
- theme
138
- end
139
-
140
- #
141
- # Site development location
142
- #
143
- # @return {String}
144
- #
145
- def setup_site_dev_location
146
- dev_location = File.expand_path("#{@environment.vvv_path}/www/tj-#{@opts[:site_name]}")
147
- end
148
-
149
- #
150
- # Site development url
151
- #
152
- # @return {String}
153
- #
154
- def setup_site_dev_url
155
- if @opts[:use_defaults]
156
- url = "#{@opts[:site_name]}.dev"
157
- else
158
- url = @interaction.prompt "What do you want the development url to be? (this should end in '.dev')", :default => "#{@opts[:site_name]}.dev"
159
- end
160
-
161
- validate_site_dev_url url
162
-
163
- url
164
- end
165
-
166
- #
167
- # Site repository
168
- #
169
- # @return {String}
170
- #
171
- def setup_site_repository
172
- if @opts[:use_defaults] || @opts[:skip_repo]
173
- repo = false
174
- else
175
- if @interaction.agree? "Would you like to initialize a new Git repository?"
176
- repo = @interaction.prompt "What is the repository's URL?", :indent => 2
177
- else
178
- repo = false
179
- end
180
- end
181
-
182
- repo
183
- end
184
-
185
- #
186
- # Database host
187
- #
188
- # @return {String}
189
- #
190
- def setup_site_db_host
191
- if @opts[:use_defaults] || @opts[:skip_db]
192
- db_host = "vvv"
193
- else
194
- db_host = @interaction.prompt "Database host", :default => "vvv"
195
- end
196
-
197
- db_host
198
- end
199
-
200
- #
201
- # Database name
202
- #
203
- # @return {String}
204
- #
205
- def setup_site_db_name
206
- if @opts[:use_defaults] || @opts[:skip_db]
207
- db_name = "#{@opts[:site_name_clean]}_db"
208
- else
209
- db_name = @interaction.prompt "Database name", :default => "#{@opts[:site_name_clean]}_db"
210
- end
211
-
212
- db_name
213
- end
214
-
215
- #
216
- # Database username
217
- #
218
- # @return {String}
219
- #
220
- def setup_site_db_user
221
- if @opts[:use_defaults] || @opts[:skip_db]
222
- db_user = "#{@opts[:site_name_clean]}_user"
223
- else
224
- db_user = @interaction.prompt "Database username", :default => "#{@opts[:site_name_clean]}_user"
225
- end
226
-
227
- db_user
228
- end
229
-
230
- #
231
- # Database password
232
- #
233
- # @return {String}
234
- #
235
- def setup_site_db_pass
236
- pass = Faker::Internet.password 24
237
-
238
- if @opts[:use_defaults] || @opts[:skip_db]
239
- db_pass = pass
240
- else
241
- db_pass = @interaction.prompt "Database password", :default => pass
242
- end
243
-
244
- db_pass
245
- end
246
-
247
- #
248
- # Validate site name
249
- #
250
- # @param {String} name
251
- #
252
- # @return {Void}
253
- #
254
- def validate_site_name(name)
255
- if name.empty?
256
- @interaction.error "Site name '#{name}' is invalid or empty. Aborting mission."
257
- end
258
-
259
- "#{name}".match /[^0-9A-Za-z.\-]/ do |char|
260
- @interaction.error "Site name contains an invalid character '#{char}'. This name is used for creating directories, so that's not gonna work. Aborting mission."
261
- end
262
- end
263
-
264
- #
265
- # Validate site url
266
- #
267
- # @param {String} url
268
- #
269
- # @return {Void}
270
- #
271
- def validate_site_dev_url(url)
272
- unless "#{url}".match /(.dev)$/
273
- @interaction.error "Your development url '#{url}' doesn't end with '.dev'. This is used internally by Landrush, so that's not gonna work. Aborting mission."
274
- end
275
- end
276
- end
277
- end
278
- end
@@ -1,48 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module ThemeJuice
4
- module Interaction::Delete
5
-
6
- @environment = ::ThemeJuice::Environment
7
- @interaction = ::ThemeJuice::Interaction
8
-
9
- class << self
10
-
11
- #
12
- # Get needed site options
13
- #
14
- # @param {Hash} opts
15
- #
16
- # @return {Hash}
17
- #
18
- def get_site_options(opts = {})
19
- @opts = opts
20
-
21
- @opts[:site_name] ||= get_site_name
22
- @opts[:site_dev_location] ||= get_site_dev_location
23
-
24
- @opts
25
- end
26
-
27
- private
28
-
29
- #
30
- # Site name
31
- #
32
- # @return {String}
33
- #
34
- def get_site_name
35
- name = @interaction.choose "Which site would you like to delete?", :red, ::ThemeJuice::Service::List.new.get_sites
36
- end
37
-
38
- #
39
- # Site development location
40
- #
41
- # @return {String}
42
- #
43
- def get_site_dev_location
44
- dev_location = File.expand_path("#{@environment.vvv_path}/www/tj-#{@opts[:site_name]}")
45
- end
46
- end
47
- end
48
- end
@@ -1,12 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module ThemeJuice
4
- module Interaction::TeeJay
5
-
6
- @environment = ::ThemeJuice::Environment
7
- @interaction = ::ThemeJuice::Interaction
8
-
9
- class << self
10
- end
11
- end
12
- end
@@ -1,224 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module ThemeJuice
4
- class Service
5
- include ::Thor::Actions
6
- include ::Thor::Shell
7
-
8
- #
9
- # @param {Hash} opts
10
- #
11
- def initialize(opts)
12
- @environment = ::ThemeJuice::Environment
13
- @interaction = ::ThemeJuice::Interaction
14
- @opts = opts
15
- @config_path = opts[:site_location] || Dir.pwd
16
- @config_regex = %r{^(\.)?(tj.y(a)?ml)}
17
- rescue => err
18
- @interaction.error "Whoops! Something went wrong!" do
19
- puts err
20
- end
21
- end
22
-
23
- private
24
-
25
- #
26
- # Run system commands
27
- #
28
- # @param {Array} commands
29
- # Array of commands to run
30
- # @param {Bool} silent (true)
31
- # Silence all output from command
32
- #
33
- # @return {Void}
34
- #
35
- def run(commands, silent = true)
36
- commands.map! { |cmd| cmd.to_s + " > /dev/null 2>&1" } if silent
37
- system commands.join "&&"
38
- end
39
-
40
- #
41
- # Verify config is properly setup and load it
42
- #
43
- # @return {Void}
44
- #
45
- def load_config
46
-
47
- if config_is_setup?
48
- @config = YAML.load_file(Dir["#{@config_path}/*"].select { |f| @config_regex =~ File.basename(f) }.last)
49
- else
50
- @interaction.notice "Unable to find a 'tj.yml' file in '#{@config_path}'."
51
-
52
- unless @interaction.agree? "Would you like to create one?"
53
- @interaction.error "A config file is needed to continue. Aborting mission."
54
- end
55
-
56
- setup_config
57
- end
58
- end
59
-
60
- #
61
- # Restart Vagrant
62
- #
63
- # @note Normally a simple 'vagrant reload' would work, but Landrush requires
64
- # a 'vagrant up' to be fired for it to set up the DNS correctly.
65
- #
66
- # @return {Void}
67
- #
68
- def restart_vagrant
69
- @interaction.log "Restarting VVV"
70
-
71
- run [
72
- "cd #{@environment.vvv_path}",
73
- "vagrant halt",
74
- "vagrant up --provision",
75
- ], false
76
- end
77
-
78
- #
79
- # Test if site creation was successful
80
- #
81
- # @return {Bool}
82
- #
83
- def setup_was_successful?
84
- vvv_is_setup? and dev_site_is_setup? and hosts_is_setup? and database_is_setup? and nginx_is_setup?
85
- end
86
-
87
- #
88
- # Test if site removal was successful. This just reverses the check
89
- # for a successful setup.
90
- #
91
- # @return {Bool}
92
- #
93
- def removal_was_successful?
94
- !setup_was_successful?
95
- end
96
-
97
- #
98
- # Test if project directory tree has been created
99
- #
100
- # @return {Bool}
101
- #
102
- def project_dir_is_setup?
103
- Dir.exist? "#{@opts[:site_location]}"
104
- end
105
-
106
- #
107
- # Test if config file is in current working directory
108
- #
109
- # @return {Bool}
110
- #
111
- def config_is_setup?
112
- !Dir["#{@config_path}/*"].select { |f| @config_regex =~ File.basename(f) }.empty?
113
- end
114
-
115
- #
116
- # Test if VVV has been cloned
117
- #
118
- # @return {Bool}
119
- #
120
- def vvv_is_setup?
121
- File.exist? File.expand_path(@environment.vvv_path)
122
- end
123
-
124
- #
125
- # Test if landrush block has been placed
126
- #
127
- # @return {Bool}
128
- #
129
- def wildcard_subdomains_is_setup?
130
- File.readlines(File.expand_path("#{@environment.vvv_path}/Vagrantfile")).grep(/(config.landrush.enabled = true)/m).any?
131
- end
132
-
133
- #
134
- # Test if VVV development location has been created
135
- #
136
- # @return {Bool}
137
- #
138
- def dev_site_is_setup?
139
- File.exist? "#{@opts[:site_dev_location]}"
140
- end
141
-
142
- #
143
- # Test if hosts file has been created
144
- #
145
- # @return {Bool}
146
- #
147
- def hosts_is_setup?
148
- File.exist? "#{@opts[:site_location]}/vvv-hosts"
149
- end
150
-
151
- #
152
- # Test if database block has been placed
153
- #
154
- # @return {Bool}
155
- #
156
- def database_is_setup?
157
- File.readlines(File.expand_path("#{@environment.vvv_path}/database/init-custom.sql")).grep(/(### Begin '#{@opts[:site_name]}')/m).any?
158
- end
159
-
160
- #
161
- # Test if nginx config has been created
162
- #
163
- # @return {Bool}
164
- #
165
- def nginx_is_setup?
166
- File.exist? "#{@opts[:site_location]}/vvv-nginx.conf"
167
- end
168
-
169
- #
170
- # Test if starter theme has been set up by checking for common
171
- # WordPress directories
172
- #
173
- # @return {Bool}
174
- #
175
- def starter_theme_is_setup?
176
- !Dir["#{@opts[:site_location]}/*"].select { |f| %r{wp(-content)?|wordpress|app|public|web|content} =~ File.basename(f) }.empty?
177
- end
178
-
179
- #
180
- # Test if synced folder block has been placed
181
- #
182
- # @return {Bool}
183
- #
184
- def synced_folder_is_setup?
185
- File.readlines(File.expand_path("#{@environment.vvv_path}/Vagrantfile")).grep(/(### Begin '#{@opts[:site_name]}')/m).any?
186
- end
187
-
188
- #
189
- # Test if repository has been set up
190
- #
191
- # @return {Bool}
192
- #
193
- def repo_is_setup?
194
- File.exist? File.expand_path("#{@opts[:site_location]}/.git")
195
- end
196
-
197
- #
198
- # Test if .env file has been created
199
- #
200
- # @return {Bool}
201
- #
202
- def env_is_setup?
203
- File.exist? File.expand_path("#{@opts[:site_location]}/.env.development")
204
- end
205
-
206
- #
207
- # Test if local wp-cli file has been created
208
- #
209
- # @return {Bool}
210
- #
211
- def wpcli_is_setup?
212
- File.exist? File.expand_path("#{@opts[:site_location]}/wp-cli.local.yml")
213
- end
214
-
215
- #
216
- # Test if we're initializing a new repository
217
- #
218
- # @return {Bool}
219
- #
220
- def using_repo?
221
- !!@opts[:site_repository]
222
- end
223
- end
224
- end