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,16 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module ThemeJuice
4
- class Command::Install < ::ThemeJuice::Command
5
-
6
- #
7
- # @param {Hash} opts
8
- #
9
- # @return {Void}
10
- #
11
- def initialize(opts = {})
12
- super
13
- ::ThemeJuice::Service::Config.new.install
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module ThemeJuice
4
- class Command::List < ::ThemeJuice::Command
5
-
6
- #
7
- # @param {Hash} opts
8
- #
9
- # @return {Void}
10
- #
11
- def initialize(opts = {})
12
- super
13
- ::ThemeJuice::Service::List.new.list
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module ThemeJuice
4
- class Command::Subcommand < ::ThemeJuice::Command
5
-
6
- #
7
- # @param {Hash} opts
8
- #
9
- # @return {Void}
10
- #
11
- def initialize(opts = {})
12
- super
13
- ::ThemeJuice::Service::Config.new.subcommand(@opts[:subcommand], @opts[:commands])
14
- end
15
- end
16
- end
@@ -1,15 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module ThemeJuice
4
- module Environment
5
- class << self
6
- attr_accessor :vvv_path
7
- attr_accessor :no_unicode
8
- attr_accessor :no_colors
9
- # attr_accessor :no_animations
10
- # attr_accessor :no_deployer
11
- attr_accessor :boring
12
- attr_accessor :yolo
13
- end
14
- end
15
- end
@@ -1,445 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module ThemeJuice
4
- module Interaction
5
-
6
- # Icons
7
- ICONS = {
8
-
9
- # Unicode
10
- :success => "\u2713",
11
- :error => "\u2191",
12
- :notice => "\u2192",
13
- :question => "\u2022",
14
- :general => "\u2022",
15
- :log => "\u2026",
16
- :restart => "\u21AA",
17
- :selected => "\u2022",
18
- :unselected => "\u25CB",
19
-
20
- # Fallback
21
- :nu_success => "+",
22
- :nu_error => "!",
23
- :nu_notice => "-",
24
- :nu_question => "?",
25
- :nu_general => "-",
26
- :nu_log => "...",
27
- :nu_restart => "!",
28
- :nu_selected => "[x]",
29
- :nu_unselected => "[ ]"
30
- }
31
-
32
- # Escape sequences
33
- KEYS = {
34
- "\e[A" => "up",
35
- "\e[B" => "down",
36
- "\e[C" => "right",
37
- "\e[D" => "left",
38
- "\003" => "ctrl+c",
39
- "\004" => "ctrl+d",
40
- "\e" => "escape",
41
- "\n" => "linefeed",
42
- "\r" => "return",
43
- " " => "space"
44
- }
45
-
46
- # Get the environment
47
- @environment = ::ThemeJuice::Environment
48
-
49
- class << self
50
- include ::Thor::Actions
51
- include ::Thor::Shell
52
-
53
- #
54
- # Output formatted message
55
- #
56
- # @param {String} message
57
- # @param {Hash} opts
58
- #
59
- # @return {Void}
60
- #
61
- def speak(message, opts = {})
62
- format_message message, opts
63
- output_message
64
- end
65
-
66
- #
67
- # Ask a question
68
- #
69
- # @param {String} question
70
- # @param {Hash} opts
71
- #
72
- # @return {Void}
73
- #
74
- def prompt(question, *opts)
75
- format_message question, {
76
- :color => :blue,
77
- :icon => :question
78
- }
79
-
80
- opts.each do |opt|
81
-
82
- # if opt[:default]
83
- # opt[:default] = set_color(opt[:default], :black, :bold) unless @environment.no_colors
84
- # end
85
-
86
- if opt[:indent]
87
- set(question) { |str| (" " * opt[:indent]) << str }
88
- end
89
-
90
- break
91
- end
92
-
93
- ask("#{question} :", *opts).gsub /\e\[\d+m/, ""
94
- end
95
-
96
- #
97
- # Ask a yes or no question
98
- #
99
- # @param {String} question
100
- # @param {Hash} opts
101
- #
102
- # @return {Bool}
103
- #
104
- def agree?(question, opts = {})
105
- format_message question, {
106
- :color => opts[:color] || :blue,
107
- :icon => :question
108
- }
109
-
110
- if opts[:simple]
111
- yes? " :", if opts[:color] then opts[:color] end
112
- else
113
- yes? "#{question} (y/N) :"
114
- end
115
- end
116
-
117
- #
118
- # Output log message
119
- #
120
- # @param {String} message
121
- #
122
- # @return {Void}
123
- #
124
- def log(message)
125
- speak message, {
126
- :color => :yellow,
127
- :icon => :log
128
- }
129
- end
130
-
131
- #
132
- # Output success message
133
- #
134
- # @param {String} message
135
- #
136
- # @return {Void}
137
- #
138
- def success(message)
139
- speak message, {
140
- :color => [:black, :on_green, :bold],
141
- :icon => :success,
142
- :row => true
143
- }
144
- end
145
-
146
- #
147
- # Output notice message
148
- #
149
- # @param {String} message
150
- #
151
- # @return {Void}
152
- #
153
- def notice(message)
154
- speak message, {
155
- :color => [:black, :on_yellow],
156
- :icon => :notice,
157
- :row => true
158
- }
159
- end
160
-
161
- #
162
- # Output error message and exit. Allows a block to be passed
163
- # as well, which will be executed before exiting
164
- #
165
- # @param {String} message
166
- #
167
- # @return {Void}
168
- #
169
- def error(message)
170
- speak message, {
171
- :color => [:white, :on_red],
172
- :icon => :error,
173
- :row => true
174
- }
175
-
176
- yield if block_given?
177
-
178
- exit 1
179
- end
180
-
181
- #
182
- # Output greeting
183
- #
184
- # @param {Hash} opts ({})
185
- #
186
- # @return {Void}
187
- #
188
- def hello(opts = {})
189
- speak "Welcome to Theme Juice!", {
190
- :color => [:black, :on_green, :bold],
191
- :row => true
192
- }.merge(opts)
193
- end
194
-
195
- #
196
- # Output goodbye and exit with interupt code
197
- #
198
- # @param {Hash} opts ({})
199
- #
200
- # @return {Void}
201
- #
202
- def goodbye(opts = {})
203
- speak "Bye bye!", {
204
- :color => :yellow,
205
- :icon => :general,
206
- :newline => true
207
- }.merge(opts)
208
-
209
- exit 130
210
- end
211
-
212
- #
213
- # Output a list of messages
214
- #
215
- # @param {String} header
216
- # @param {Symbol} color
217
- # @param {Array} list
218
- #
219
- # @return {Void}
220
- #
221
- def list(header, color, list)
222
- speak header, {
223
- :color => [:black, :"on_#{color}"],
224
- :icon => :notice,
225
- :row => true
226
- }
227
-
228
- list.each do |item|
229
- speak item, {
230
- :color => :"#{color}",
231
- :icon => :general
232
- }
233
- end
234
- end
235
-
236
- #
237
- # Create a shell select menu
238
- #
239
- # @param {String} header
240
- # @param {Symbol} color
241
- # @param {Array} list
242
- #
243
- # @return {String}
244
- #
245
- def choose(header, color, list)
246
- speak "#{header} (use arrow keys and press enter)", {
247
- :color => :"#{color}",
248
- :icon => :question
249
- }
250
-
251
- print "\n" * list.size
252
-
253
- selected = 0
254
- update_list_selection(list, color, selected)
255
-
256
- loop do
257
- case key = read_key
258
- when "up"
259
- selected -= 1
260
- selected = list.size - 1 if selected < 0
261
- update_list_selection(list, color, selected)
262
- when "down"
263
- selected += 1
264
- selected = 0 if selected > list.size - 1
265
- update_list_selection(list, color, selected)
266
- when "return", "linefeed", "space"
267
- return list[selected]
268
- when "esc", "ctrl+c"
269
- goodbye(:newline => false)
270
- # else
271
- # speak "You pressed: #{key.inspect}", { :color => :yellow }
272
- end
273
- end
274
- end
275
-
276
- private
277
-
278
- #
279
- # Destructively format message
280
- #
281
- # @param {String} message
282
- # @param {Hash} opts
283
- #
284
- # @return {String}
285
- #
286
- def format_message(message, opts = {})
287
- @message, @opts = message, opts
288
-
289
- format_message_icon
290
- format_message_newline
291
- format_message_row
292
- format_message_width
293
- format_message_color
294
- format_message_indent
295
-
296
- @message
297
- end
298
-
299
- #
300
- # Run destructive block against string
301
- #
302
- # @param {String} string
303
- #
304
- # @return {String}
305
- #
306
- def set(string)
307
- str = yield(string); string.clear; string << str
308
- end
309
-
310
- #
311
- # Force message to use icon (if environment allows)
312
- #
313
- # @return {String}
314
- #
315
- def format_message_icon
316
- icon = if @environment.no_unicode then "nu_#{@opts[:icon]}" else "#{@opts[:icon]}" end
317
-
318
- if @opts[:icon]
319
- set(@message) { |msg| " #{ICONS[:"#{icon}"]}" << if @opts[:empty] then nil else " #{msg}" end }
320
- else
321
- set(@message) { |msg| " " << msg }
322
- end
323
- end
324
-
325
- #
326
- # Force message on newline, unless already on newline
327
- #
328
- # @return {String}
329
- #
330
- def format_message_newline
331
- set(@message) { |msg| "\n" << msg } if @opts[:newline]
332
- end
333
-
334
- #
335
- # Force message to use colors (if environment allows)
336
- #
337
- # @return {String}
338
- #
339
- def format_message_color
340
- unless @environment.no_colors
341
- set(@message) { |msg| set_color(msg, *@opts[:color]) } if @opts[:color]
342
- end
343
- end
344
-
345
- #
346
- # Force message to take up width of terminal window
347
- #
348
- # @return {String}
349
- #
350
- def format_message_row
351
- set(@message) { |msg| msg.ljust(terminal_width) } if @opts[:row]
352
- end
353
-
354
- #
355
- # Force message width
356
- #
357
- # @return {String}
358
- #
359
- def format_message_width
360
- set(@message) { |msg| msg.ljust(@opts[:width]) } if @opts[:width]
361
- end
362
-
363
- #
364
- # Force message indentation
365
- #
366
- # @return {String}
367
- #
368
- def format_message_indent
369
- set(@message) { |str| (" " * @opts[:indent]) << str } if @opts[:indent]
370
- end
371
-
372
- #
373
- # Output message to terminal, unless quiet
374
- #
375
- # @return {String|Void}
376
- #
377
- def output_message
378
- if @opts[:quiet] then @message else say @message end
379
- end
380
-
381
- #
382
- # Output list with updated selection
383
- #
384
- # @return {Void}
385
- #
386
- def update_list_selection(list, color, selected = 0)
387
- print "\e[#{list.size}A"
388
-
389
- list.each_with_index do |item, i|
390
- icon = if i == selected then "selected" else "unselected" end
391
- speak "#{item}", {
392
- :color => :"#{color}",
393
- :icon => :"#{icon}",
394
- :indent => 2
395
- }
396
- end
397
- end
398
-
399
- #
400
- # Read input
401
- #
402
- # @see http://www.alecjacobson.com/weblog/?p=75
403
- #
404
- # @return {String}
405
- #
406
- def read_key
407
- save_state
408
- raw_no_echo_mode
409
-
410
- key = STDIN.getc.chr
411
-
412
- if key == "\e"
413
- thread = Thread.new { key += STDIN.getc.chr + STDIN.getc.chr }
414
- thread.join(0.001)
415
- thread.kill
416
- end
417
-
418
- KEYS[key] || key
419
- ensure
420
- restore_state
421
- end
422
-
423
- #
424
- # Get the current state of stty
425
- #
426
- def save_state
427
- @state = %x(stty -g)
428
- end
429
-
430
- #
431
- # Disable echoing and enable raw mode
432
- #
433
- def raw_no_echo_mode
434
- %x(stty raw -echo)
435
- end
436
-
437
- #
438
- # Restore state of stty
439
- #
440
- def restore_state
441
- %x(stty #{@state})
442
- end
443
- end
444
- end
445
- end