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
@@ -0,0 +1,35 @@
1
+ # encoding: UTF-8
2
+
3
+ module ThemeJuice
4
+ module Project
5
+ attr_accessor :name
6
+ attr_accessor :location
7
+ attr_accessor :url
8
+ attr_accessor :theme
9
+ attr_accessor :vm_root
10
+ attr_accessor :vm_location
11
+ attr_accessor :vm_srv
12
+ attr_accessor :vm_restart
13
+ attr_accessor :repository
14
+ attr_accessor :db_host
15
+ attr_accessor :db_name
16
+ attr_accessor :db_user
17
+ attr_accessor :db_pass
18
+ attr_accessor :db_import
19
+ attr_accessor :db_drop
20
+ attr_accessor :bare
21
+ attr_accessor :skip_repo
22
+ attr_accessor :skip_db
23
+ attr_accessor :use_defaults
24
+ attr_accessor :no_wp
25
+ attr_accessor :no_db
26
+
27
+ def inspect
28
+ res = []
29
+ self.instance_variables.each { |k, _| res << "#{k[1..-1]}: #{instance_variable_get(k)}" }
30
+ res.sort
31
+ end
32
+
33
+ extend self
34
+ end
35
+ end
@@ -0,0 +1,42 @@
1
+ # encoding: UTF-8
2
+
3
+ module ThemeJuice
4
+ class Task
5
+
6
+ def initialize(opts = {})
7
+ @env = Env
8
+ @io = IO
9
+ @project = Project
10
+ @config = Config
11
+ @util = Util.new
12
+ @opts = opts.dup
13
+ @tasks = []
14
+ end
15
+
16
+ def runner
17
+ yield @tasks
18
+ end
19
+
20
+ def execute
21
+ @io.error "Method 'execute' not implemented for #{self.class.name}"
22
+ end
23
+
24
+ def unexecute
25
+ @io.error "Method 'unexecute' not implemented for #{self.class.name}"
26
+ end
27
+
28
+ private
29
+
30
+ def vm_root
31
+ File.expand_path "#{@env.vm_path}/www"
32
+ end
33
+
34
+ def vm_location
35
+ "#{vm_root}/#{@env.vm_prefix}#{@project.name}"
36
+ end
37
+
38
+ def vm_srv
39
+ "/srv/www/#{@env.vm_prefix}#{@project.name}"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: UTF-8
2
+
3
+ module ThemeJuice
4
+ module Tasks
5
+ class CreateConfirm < Task
6
+
7
+ def initialize(opts = {})
8
+ super
9
+ end
10
+
11
+ def execute
12
+ confirm
13
+ end
14
+
15
+ private
16
+
17
+ def confirm
18
+ @io.list "Your settings :", :yellow, settings
19
+ unless @io.agree? "Do these settings look correct?"
20
+ @io.error "Dang typos..."
21
+ end
22
+ end
23
+
24
+ def settings
25
+ if @env.verbose
26
+ @env.inspect + @project.inspect
27
+ else
28
+ @project.inspect
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,42 @@
1
+ # encoding: UTF-8
2
+
3
+ module ThemeJuice
4
+ module Tasks
5
+ class CreateSuccess < Task
6
+
7
+ def initialize(opts = {})
8
+ super
9
+
10
+ @vm_provision = Tasks::VMProvision.new(opts)
11
+ end
12
+
13
+ def execute
14
+ provision_vm
15
+ success
16
+ end
17
+
18
+ private
19
+
20
+ def provision_vm
21
+ if @io.agree? "In order to finish creating your project, you need to provision the VM. Do it now?"
22
+ @vm_provision.execute
23
+ else
24
+ @io.notice "Remember, the VM needs to be provisioned before you can use your new site"
25
+ end
26
+ end
27
+
28
+ def success
29
+ @io.success "Successfully created project '#{@project.name}'"
30
+ @io.list "Your settings :", :yellow, settings
31
+ end
32
+
33
+ def settings
34
+ if @env.verbose
35
+ @env.inspect + @project.inspect
36
+ else
37
+ @project.inspect
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: UTF-8
2
+
3
+ module ThemeJuice
4
+ module Tasks
5
+ class Database < Entry
6
+
7
+ def initialize(opts = {})
8
+ super
9
+
10
+ @entry = {
11
+ :project => @project.name,
12
+ :file => "#{@env.vm_path}/database/init-custom.sql",
13
+ :name => "database",
14
+ :id => "DB"
15
+ }
16
+ end
17
+
18
+ def execute
19
+ if @project.db_host && @project.db_name && @project.db_user && @project.db_pass
20
+ create_entry_file
21
+ create_entry do
22
+ %Q{CREATE DATABASE IF NOT EXISTS `#{@project.db_name}`;
23
+ GRANT ALL PRIVILEGES ON `#{@project.db_name}`.* TO '#{@project.db_user}'@'localhost' IDENTIFIED BY '#{@project.db_pass}';}
24
+ end
25
+ end
26
+ end
27
+
28
+ def unexecute
29
+ remove_entry
30
+ drop_database
31
+ end
32
+
33
+ private
34
+
35
+ def drop_database
36
+ if @project.db_drop
37
+
38
+ # Double check that the database should be dropped
39
+ if @io.agree? "Are you sure you want to drop the database for '#{@project.name}'?"
40
+ @io.log "Dropping database"
41
+ @util.run_inside_vm [], :verbose => @env.verbose do |cmds|
42
+ cmds << "cd #{@project.vm_srv}"
43
+ cmds << "wp db drop --yes"
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: UTF-8
2
+
3
+ module ThemeJuice
4
+ module Tasks
5
+ class DeleteConfirm < Task
6
+
7
+ def initialize(opts = {})
8
+ super
9
+ end
10
+
11
+ def unexecute
12
+ confirm
13
+ end
14
+
15
+ private
16
+
17
+ def confirm
18
+ unless @io.agree? "Are you sure you want to remove '#{@project.name}'?"
19
+ @io.error "Aborting mission"
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: UTF-8
2
+
3
+ module ThemeJuice
4
+ module Tasks
5
+ class DeleteSuccess < Task
6
+
7
+ def initialize(opts = {})
8
+ super
9
+
10
+ @vm_restart = Tasks::VMRestart.new(opts)
11
+ end
12
+
13
+ def unexecute
14
+ restart_vm
15
+ success
16
+ end
17
+
18
+ private
19
+
20
+ def restart_vm
21
+ if @project.vm_restart
22
+ @vm_restart.execute
23
+ end
24
+ end
25
+
26
+ def success
27
+ @io.success "Successfully removed project '#{@project.name}'"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: UTF-8
2
+
3
+ module ThemeJuice
4
+ module Tasks
5
+ class DNS < Entry
6
+
7
+ def initialize(opts = {})
8
+ super
9
+
10
+ @entry = {
11
+ :project => @project.name,
12
+ :file => "#{@env.vm_path}/Customfile",
13
+ :name => "DNS",
14
+ :id => "DNS"
15
+ }
16
+ end
17
+
18
+ def execute
19
+ create_entry_file
20
+ create_entry do
21
+ %Q{if defined? Landrush
22
+ config.landrush.host '#{@project.url}', '#{@env.vm_ip}'
23
+ elsif defined? VagrantPlugins::HostsUpdater
24
+ config.hostsupdater.aliases << '#{@project.url}'
25
+ end}
26
+ end
27
+ end
28
+
29
+ def unexecute
30
+ remove_landrush_entry
31
+ remove_entry
32
+ end
33
+
34
+ private
35
+
36
+ def remove_landrush_entry
37
+ unless @env.no_landrush
38
+ @io.log "Removing URL from Landrush"
39
+ @util.run "vagrant landrush rm #{@project.url}",
40
+ :verbose => @env.verbose
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: UTF-8
2
+
3
+ module ThemeJuice
4
+ module Tasks
5
+ class DotEnv < Task
6
+
7
+ def initialize(opts = {})
8
+ super
9
+ end
10
+
11
+ def execute
12
+ unless @project.no_wp
13
+ create_dot_env_file
14
+ end
15
+ end
16
+
17
+ def unexecute
18
+ remove_dot_env_file
19
+ end
20
+
21
+ private
22
+
23
+ def dot_env_file
24
+ "#{@project.location}/.env.development"
25
+ end
26
+
27
+ def dot_env_is_setup?
28
+ File.exist? dot_env_file
29
+ end
30
+
31
+ def create_dot_env_file
32
+ unless dot_env_is_setup?
33
+ @io.log "Creating .env file"
34
+ @util.create_file dot_env_file, :verbose => @env.verbose do
35
+ %Q{DB_NAME=#{@project.db_name}
36
+ DB_USER=#{@project.db_user}
37
+ DB_PASSWORD=#{@project.db_pass}
38
+ DB_HOST=#{@project.db_host}
39
+ WP_HOME=http://#{@project.url}
40
+ WP_SITEURL=http://#{@project.url}/wp
41
+
42
+ }
43
+ end
44
+ end
45
+ end
46
+
47
+ def remove_dot_env_file
48
+ @io.log "Removing .env file"
49
+ @util.remove_file dot_env_file, :verbose => @env.verbose
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: UTF-8
2
+
3
+ module ThemeJuice
4
+ module Tasks
5
+ class Entry < Task
6
+ attr_accessor :entry
7
+
8
+ def initialize(opts = {})
9
+ super
10
+ end
11
+
12
+ private
13
+
14
+ def entry_file_is_setup?
15
+ File.exist? @entry.fetch(:file)
16
+ end
17
+
18
+ def create_entry_file
19
+ unless entry_file_is_setup?
20
+ @io.log "Creating #{@entry.fetch(:name)} file"
21
+ @util.create_file @entry.fetch(:file), nil, :verbose => @env.verbose
22
+ end
23
+ end
24
+
25
+ def entry_is_setup?
26
+ File.readlines(@entry.fetch(:file)).grep(/(#(#*)? Begin '#{@entry.fetch(:project)}' #{@entry.fetch(:id)})/m).any?
27
+ end
28
+
29
+ def create_entry(&block)
30
+ unless entry_is_setup?
31
+ @io.log "Creating #{@entry.fetch(:name)} entry"
32
+ @util.append_to_file @entry.fetch(:file), :verbose => @env.verbose do
33
+ %Q{# Begin '#{@entry.fetch(:project)}' #{@entry.fetch(:id)}
34
+ # The contents below are automatically generated by Theme Juice. Do not modify.
35
+ #{yield}
36
+ # End '#{@entry.fetch(:project)}' #{@entry.fetch(:id)}
37
+
38
+ }
39
+ end
40
+ end
41
+ end
42
+
43
+ def remove_entry
44
+ @io.log "Removing #{@entry.fetch(:name)} entry"
45
+ @util.gsub_file @entry.fetch(:file), /(#(#*)? Begin '#{@entry.fetch(:project)}' #{@entry.fetch(:id)})(.*?)(#(#*)? End '#{@entry.fetch(:project)}' #{@entry.fetch(:id)})\n+/m,
46
+ "", :verbose => @env.verbose
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,43 @@
1
+ # encoding: UTF-8
2
+
3
+ module ThemeJuice
4
+ module Tasks
5
+ class Hosts < Task
6
+
7
+ def initialize(opts = {})
8
+ super
9
+ end
10
+
11
+ def execute
12
+ create_hosts_file
13
+ end
14
+
15
+ def unexecute
16
+ remove_hosts_file
17
+ end
18
+
19
+ private
20
+
21
+ def hosts_file
22
+ "#{@project.location}/vvv-hosts"
23
+ end
24
+
25
+ def hosts_is_setup?
26
+ File.exist? hosts_file
27
+ end
28
+
29
+ def create_hosts_file
30
+ unless hosts_is_setup?
31
+ @io.log "Creating hosts file"
32
+ @util.create_file hosts_file, "#{@project.url}",
33
+ :verbose => @env.verbose
34
+ end
35
+ end
36
+
37
+ def remove_hosts_file
38
+ @io.log "Removing hosts file"
39
+ @util.remove_file hosts_file, :verbose => @env.verbose
40
+ end
41
+ end
42
+ end
43
+ end