theme-juice 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dc35777e4bd07bd8eae2a314ec39c251f5fa5562
4
+ data.tar.gz: 989ba458f6709aaa228889afa7198a6d51988e48
5
+ SHA512:
6
+ metadata.gz: 6f88be099cb1768bd1d94a1af73a012353d65ce0946c5e7af354abe0178540d099ac69bef543ecef87d75c7569080c2db3f705823f23de792a99ac4de099d8b8
7
+ data.tar.gz: 8997b53e9b08991187e6a19b123a0f40fccf0cd81f7a846bab977b3ec672b7ddf4b974ee6a92386da5e0418783370b1178084a2a569fe729989c5ff2fb87cfd5
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ezekiel Gabrielse
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # Theme Juice
2
+ Command line interface to scaffold out a new WordPress development environment and countless sites. Everybody loves one command setups, and 'tj' even does one command deployments too.
3
+
4
+ ## Installation
5
+ * First, install [Vagrant](https://www.vagrantup.com/) and [VirtualBox](https://www.virtualbox.org/) for local development.
6
+ * Then, install [Composer](https://getcomposer.org/) and [WP-CLI](http://wp-cli.org/). _Make sure that these are executable from the command line._
7
+ * Finally, you can run: '$ gem install theme-juice-cli'
8
+
9
+ That's it!
10
+
11
+ ## Usage
12
+
13
+ #### List available commands:
14
+ List all commands for 'tj'.
15
+ '''bash
16
+ tj
17
+ '''
18
+
19
+ #### Setup VVV:
20
+ This command will _only_ setup [Varying Vagrant Vagrants](https://github.com/Varying-Vagrant-Vagrants/VVV). It will not prompt you to create a new site. _Note: This is automatically run when you create your first site._
21
+ '''bash
22
+ tj init
23
+ '''
24
+
25
+ #### Create a new development site:
26
+ Use this to create a new development site. It will automagically set up your entire development environment, including a local development site at 'http://<sites-dev-url>.dev' with WordPress installed and a fresh WP database. It will sync up your local site installation with the Vagrant VM. This task will also install and configure Vagrant/VVV into your '~/' directory if it has not already been installed. Site name is optional, as it will be asked for if not given.
27
+ '''bash
28
+ tj create [<site-name>]
29
+ '''
30
+
31
+ #### Setup an existing site:
32
+ Use this to setup an existing local site installation within the development environment. You will go through the setup process to create the necessary files for the VM, including 'vvv-hosts', 'vvv-nginx.conf', and a fresh database (unless one already exists by the name chosen). Site name is optional, as it will be asked for if not given.
33
+ '''bash
34
+ tj setup [<site-name>] # Alias for 'tj create [<site-name>] --bare'
35
+ '''
36
+
37
+ #### Delete a site from the VM: _(Does not remove your local site)_
38
+ Use this to remove a site from your development environment. This is only remove files that were generated by 'tj'. including the database setup, development url, and shared directories. _It will not touch your local files._
39
+ '''bash
40
+ tj delete <site-name>
41
+ '''
42
+
43
+ #### List all sites in the VM:
44
+ Use this to list all sites within your development environment that were generated by 'tj'.
45
+ '''bash
46
+ tj list
47
+ '''
48
+
49
+ #### Watch and compile assets: _(Guard)_
50
+ Use this to watch and compile assets with [Guard](https://github.com/guard/guard). This is simply a wrapper for Guard commands.
51
+ '''bash
52
+ tj watch # Alias for 'bundle exec guard #{cmd}'
53
+ '''
54
+
55
+ #### Use for managing development environment: _(Vagrant)_
56
+ Use this to easily manage your [Varying Vagrant Vagrants](https://github.com/Varying-Vagrant-Vagrants/VVV) development environment. This is simply a wrapper for Vagrant commands.
57
+ '''bash
58
+ tj vm # Alias for 'cd ~/vagrant && vagrant #{cmd}'
59
+ '''
60
+
61
+ #### Use for managing vendor dependencies: _(Composer)_
62
+ Use this to easily manage your [Composer](https://github.com/composer/composer) dependencies. This is simply a wrapper for Composer commands.
63
+ '''bash
64
+ tj vendor # Alias for 'composer #{cmd}'
65
+ '''
66
+
67
+ #### Use for managing deployment and migration: _(Capistrano)_
68
+ Use this to easily manage your deployment and migration with [Capistrano](https://github.com/capistrano/capistrano). This is simply a wrapper for Capistrano commands.
69
+ '''bash
70
+ tj server # Alias for 'bundle exec cap #{cmd}'
71
+ '''
72
+
73
+ ## Contributing
74
+
75
+ 1. First, create an [issue](https://github.com/ezekg/theme-juice-cli/issues) for your proposed feature. If it's a bug fix, go right to step 2.
76
+ 2. [Fork the repository](https://github.com/ezekg/theme-juice-cli/fork).
77
+ 3. Create a new feature branch. ('git checkout -b my-new-feature')
78
+ 4. Commit your changes. ('git commit -am 'Add some feature'')
79
+ 5. Push to the new branch. ('git push origin my-new-feature')
80
+ 6. Create a new Pull Request.
data/bin/tj ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+ require "pathname"
4
+ require "thor"
5
+
6
+ begin
7
+ require_relative "../lib/theme-juice"
8
+ rescue LoadError => err
9
+ warn err
10
+ exit 1
11
+ end
12
+
13
+ ThemeJuice::CLI.start
@@ -0,0 +1,30 @@
1
+ '-/+osssssssssssso+/-'
2
+ ./oys syo/.
3
+ .+ys: ..:/osyyhhhhyyso/:.. +sy+.
4
+ /ys: .+ydmmmmmmmmmmmmmmmmmmmdy+. :sy/
5
+ /h+' -odmmmmmmmmmmmmmmmmmmmmmmmmmmdo- '+h/
6
+ :ho' /hmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmds/ 'oh:
7
+ 'sy. /hmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm+ .ys'
8
+ .ho /mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmy oh.
9
+ .h+ 'mmmmmmmm' 'mmmmmmmh +h.
10
+ 'ho ' /mmmmmmmmmmo .dmmmmmmmms ~~ oh'
11
+ oy .h' ymmmmmmmmmm: /mmmmmmmmmy' -d. yo
12
+ .d- ymy 'dmmmmmmmmmd. ymmmmmmmmmh' /my -d.
13
+ oy -mmm+ /mmmmmmmmmmy .dmmmmmmmmmy ymm- yo
14
+ h+ +mmmd- smmmmmmmmmm+ /mmmmmmmmmm- :mmm+ +h
15
+ d/ smmmmh' 'dmmmmmmmmmd' smmmmmmmmm: 'dmmms /d
16
+ d/ smmmmms :mmmmmmmmm+ 'dmmmmmmmd. smmmms /d
17
+ h+ +mmmmmm/ smmmmmmmh + /mmmmmmmy /mmmmm+ +h
18
+ oy -mmmmmmd. 'dmmmmmd- +m/ smmmmmd. .dmmmmm- yo
19
+ .d- ymmmmmmh :mmmmm+ .dmd- 'dmmmm/ ymmmmmy -d.
20
+ oy .dmmmmmmo smmmh hmmmh' :mmmy +mmmmmd. yo
21
+ 'ho -dmmmmmd: 'dmd+ .mmmmms smd- .dmmmmd- oh'
22
+ .h+ -dmmmmmd' :m+ dmmmmmm: 'do hmmmmd- +h.
23
+ .ho .ymmmmmy + hmmmmmmmd. :' ommmmy. oh.
24
+ 'sy. /hmmmm+ ommmmmmmmmy -dmmh/ .ys'
25
+ :ho /hmmd- :mmmmmmmmmmmo 'hmh/ oh:
26
+ /h+ -odh' 'dmmmmmmmmmmmd: oo- +h/
27
+ /ys: ~~ smmmmmmmmmmmmmd' :sy/
28
+ .+ys '/osyyhhhhyyso/:' ./sy+.
29
+ ./oys+ +syo/.
30
+ '-/+osssssssssssso+/-'
@@ -0,0 +1,24 @@
1
+ ...gNMMM@@MMMNa+..
2
+ ..M@M#"=!........?7TWMMN&,
3
+ ..MMY=...'.....'...'''....?YMMa.
4
+ .JM#^..''.'''''''''''''''....'.JW@N.
5
+ .M#^.''.'.'''''''''''''''.'..''''.,WMh.
6
+ .MM5.J.J..'''.''''''''..'.JJ.,,'...''.JMN.
7
+ .MM.JY^' .MMa .'''''''.'.M"= .dMN,'.'.'.MM,
8
+ .@M.M$ @@MMN.''''''.'dF J@@MMp''''..MM,
9
+ M@^JF ?WH"Jb .'''''JF "H"^M,..'''.@N
10
+ JMF dF JN '''''.@F gF '.'.'J@F
11
+ J@''Jh.........JF .''''.4b...........MF''''.'.@b
12
+ M@ '.!!!!!!!!!!?''''''''.!!!??????????.'''''' @N
13
+ M@ '.......'.'.''.'.....'''''.'....'...''''.. @M
14
+ d@,''.NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNr''''.''.@F
15
+ J@b '''JNWHHHHHHHHHHHHHHHHHHHHHHHHHHd@ ''''''J@F
16
+ MM.''' @KHHHHHHHHHHHHHHHHHHHHHHHHHHW@.''''..@M
17
+ .@N ''.JMKHHHHHHHHHHHHHHHHHHHHHHHHHM@ '''.'dM3
18
+ J@N.'''?MKHHHHHHHHHHHNHYY9HHHHHHHHMF.''..d@$
19
+ .MN,''.JMNHHHHHHHNY!.'''''..4NHNM5..''.MM^
20
+ 4Mh,'..TMNHHHH@ ...'''...'..MD..''.JMY'
21
+ .W@N,''.?HNN# ...'..''J.M#^.'.'.J@#^
22
+ .TMMa,'..'T"MMQQHMH"T!..''..@MY!
23
+ '"MMNg...''''''''...+MMM"^
24
+ '""WMMM@@@MM@M#""!
@@ -0,0 +1,275 @@
1
+ module ThemeJuice
2
+ class CLI < ::Thor
3
+
4
+ ###
5
+ # Non Thor commands
6
+ ###
7
+ no_commands do
8
+
9
+ ###
10
+ # Welcome message
11
+ #
12
+ # @return {Void}
13
+ ###
14
+ def welcome
15
+
16
+ # Get WP logo ASCII art
17
+ logo = File.read(File.expand_path("../ascii/logo.txt", __FILE__))
18
+
19
+ # Output welcome message
20
+ say "\n"
21
+ say logo.gsub(/[m]/) { |char| set_color(char, :green) }.gsub(/[\+\/\-\'\:\.\~dyhos]/) { |char| set_color(char, :yellow) }
22
+ say "\n"
23
+ say "Welcome to Theme Juice!".center(60), :green
24
+ say "\n\n"
25
+ end
26
+ end
27
+
28
+ ###
29
+ # Install and setup VVV environment
30
+ #
31
+ # @return {Void}
32
+ ###
33
+ desc "init", "Setup the VVV environment"
34
+ def init
35
+ self.welcome
36
+
37
+ # Setup the VM
38
+ ::ThemeJuice::Scaffold::init
39
+ end
40
+
41
+ ###
42
+ # Install and setup VVV environment with new site
43
+ #
44
+ # @param {String} site (nil)
45
+ # Name of the site to create
46
+ # @param {Bool} bare (false)
47
+ # Create a bare VVV site without starter
48
+ #
49
+ # @return {Void}
50
+ ###
51
+ desc "create [SITE]", "Setup SITE and the VVV development environment"
52
+ method_option :bare, type: :boolean, desc: "Create a VVV site without the starter theme"
53
+ def create(site = nil, bare_setup = false)
54
+ self.welcome
55
+
56
+ ###
57
+ # Theme setup
58
+ ###
59
+ if site.nil?
60
+ say "Just a few questions before we begin...", :yellow
61
+ else
62
+ say "Your site name shall be #{site}! Just a few more questions before we begin...", :yellow
63
+ end
64
+
65
+ # ask for the Site name if not passed directly
66
+ site ||= ask "What's the site name? (only ascii characters are allowed) :", :green
67
+
68
+ if site.match /[^0-9A-Za-z.\-]/
69
+ say "Site name contains invalid non-ascii characters. This name is used for creating directories, so that's not gonna work. Aborting mission.", :red
70
+ exit 1
71
+ end
72
+
73
+ # Bare install
74
+ bare_setup ||= options[:bare]
75
+
76
+ # Make sure Site name was given, else throw err
77
+ unless site.empty?
78
+ clean_site_name = site.gsub(/[^\w]/, "_")[0..10]
79
+
80
+ ###
81
+ # Location of site installation
82
+ ###
83
+ site_location = ask "Where do you want to setup the site? :", :green,
84
+ default: "#{Dir.pwd}/",
85
+ path: true
86
+
87
+ ###
88
+ # Starter theme to clone
89
+ ###
90
+ unless bare_setup
91
+ require "highline/import"
92
+
93
+ starter_theme = nil
94
+
95
+ say "Which starter theme would you like to use? :", :green
96
+ choose do |menu|
97
+ menu.index_suffix = ") "
98
+
99
+ menu.choice "ezekg/theme-juice-starter" do |c|
100
+ say "Awesome choice!", :green
101
+ starter_theme = c
102
+ end
103
+
104
+ menu.choice "other" do
105
+ starter_theme = ask "What is the user/repository of the starter theme you would like to clone? :", :green
106
+ end
107
+
108
+ menu.choice "none" do |c|
109
+ say "Next time you want to create a site without a starter theme, you can just run the 'setup' command instead.", :yellow
110
+ starter_theme, bare_setup = c, true
111
+ end
112
+ end
113
+ end
114
+
115
+ ###
116
+ # Development url
117
+ ###
118
+ dev_url = ask "What do you want the development url to be? (this should end in '.dev') :", :green,
119
+ default: "#{site}.dev"
120
+
121
+ unless dev_url.match /(.dev)$/
122
+ say "Your development url doesn't end with '.dev'. This is used within Vagrant, so that's not gonna work. Aborting mission.", :red
123
+ exit 1
124
+ end
125
+
126
+ ###
127
+ # Initialize a git repository on setup
128
+ ###
129
+ if yes? "Would you like to initialize a new Git repository? (y/N) :", :green
130
+ repository = ask "Remote URL :", :green
131
+ else
132
+ repository = false
133
+ end
134
+
135
+ ###
136
+ # Database host
137
+ ###
138
+ db_host = ask "Database host :", :green,
139
+ default: "vvv"
140
+
141
+ ###
142
+ # Database name
143
+ ###
144
+ db_name = ask "Database name :", :green,
145
+ default: "#{clean_site_name}_db"
146
+
147
+ ###
148
+ # Database username
149
+ ###
150
+ db_user = ask "Database username :", :green,
151
+ default: "#{clean_site_name}_user"
152
+
153
+ ###
154
+ # Database password
155
+ ###
156
+ db_pass = ask "Database password :", :green,
157
+ default: SecureRandom.base64
158
+
159
+ ###
160
+ # Save options
161
+ ###
162
+ opts = {
163
+ site_name: site,
164
+ site_location: File.expand_path(site_location),
165
+ starter_theme: starter_theme,
166
+ bare_setup: bare_setup,
167
+ dev_location: File.expand_path("~/vagrant/www/tj-#{site}"),
168
+ dev_url: dev_url,
169
+ repository: repository,
170
+ db_host: db_host,
171
+ db_name: db_name,
172
+ db_user: db_user,
173
+ db_pass: db_pass,
174
+ }
175
+
176
+ # Create the theme!
177
+ ::ThemeJuice::Scaffold::create opts
178
+ else
179
+ say "Site name is required. Aborting mission.", :red
180
+ exit 1
181
+ end
182
+ end
183
+
184
+ ###
185
+ # Setup an existing WordPress install in VVV
186
+ #
187
+ # @param {String} site (nil)
188
+ # Name of the theme to create
189
+ #
190
+ # @return {Void}
191
+ ###
192
+ desc "setup [SITE]", "Create a VVV site without starter theme (alias for 'create --bare')"
193
+ def setup(site = nil)
194
+ self.create site, true
195
+ end
196
+
197
+ ###
198
+ # Remove all traces of site from Vagrant
199
+ #
200
+ # @param {String} site
201
+ # Theme to delete. This will not delete your local files, only the VVV env.
202
+ #
203
+ # @return {Void}
204
+ ###
205
+ desc "delete SITE", "Remove SITE from the VVV development environment (does not remove local site)"
206
+ method_option :restart, type: :boolean
207
+ def delete(site)
208
+ if yes? "Are you sure you want to delete '#{site}'? (y/N)", :red
209
+ ::ThemeJuice::Scaffold::delete site, options[:restart]
210
+ end
211
+ end
212
+
213
+ ###
214
+ # List all development sites
215
+ #
216
+ # @return {Void}
217
+ ###
218
+ desc "list", "List all sites within the VVV development environment"
219
+ def list
220
+ ::ThemeJuice::Scaffold::list
221
+ end
222
+
223
+ ###
224
+ # Guard
225
+ #
226
+ # @param {*} commands
227
+ # Commands to run
228
+ #
229
+ # @return {Void}
230
+ ###
231
+ desc "watch [COMMANDS]", "Watch and compile assets with Guard (alias for 'bundle exec guard [COMMANDS]')"
232
+ def watch(*commands)
233
+ system "bundle exec guard #{commands.join(" ")}"
234
+ end
235
+
236
+ ###
237
+ # Vagrant
238
+ #
239
+ # @param {*} commands
240
+ # Commands to run
241
+ #
242
+ # @return {Void}
243
+ ###
244
+ desc "vm [COMMANDS]", "Manage virtual development environment with Vagrant (alias for 'vagrant [COMMANDS]')"
245
+ def vm(*commands)
246
+ system "cd ~/vagrant && vagrant #{commands.join(" ")}"
247
+ end
248
+
249
+ ###
250
+ # Composer
251
+ #
252
+ # @param {*} commands
253
+ # Commands to run
254
+ #
255
+ # @return {Void}
256
+ ###
257
+ desc "vendor [COMMANDS]", "Manage vendor dependencies with Composer (alias for 'composer [COMMANDS]')"
258
+ def vendor(*commands)
259
+ system "composer #{commands.join(" ")}"
260
+ end
261
+
262
+ ###
263
+ # Capistrano
264
+ #
265
+ # @param {*} commands
266
+ # Commands to run
267
+ #
268
+ # @return {Void}
269
+ ###
270
+ desc "server [COMMANDS]", "Manage deployment and migration with Capistrano (alias for 'bundle exec cap [COMMANDS]')"
271
+ def server(*commands)
272
+ system "bundle exec cap #{commands.join(" ")}"
273
+ end
274
+ end
275
+ end
@@ -0,0 +1,540 @@
1
+ module ThemeJuice
2
+ module Scaffold
3
+ class << self
4
+ include ::Thor::Actions
5
+ include ::Thor::Shell
6
+
7
+ ###
8
+ # Set up local development environment
9
+ #
10
+ # @return {Void}
11
+ ###
12
+ def init
13
+ say "Initializing development environment...", :yellow
14
+
15
+ if vvv_is_setup?
16
+ say "Development environment is already set up. Aborting mission.", :red
17
+ else
18
+ say "Setup successful!", :green if setup_vvv
19
+ end
20
+ end
21
+
22
+ ###
23
+ # Set up local development environment and site
24
+ #
25
+ # @param {Hash} opts
26
+ #
27
+ # @return {Void}
28
+ ###
29
+ def create(opts)
30
+ @opts = opts
31
+
32
+ say "Running setup for '#{@opts[:site_name]}'...", :yellow
33
+
34
+ unless wordpress_is_setup?
35
+ setup_wordpress
36
+ end
37
+
38
+ unless vvv_is_setup?
39
+ setup_vvv
40
+ end
41
+
42
+ unless hosts_is_setup?
43
+ setup_hosts
44
+ end
45
+
46
+ unless database_is_setup?
47
+ setup_database
48
+ end
49
+
50
+ unless nginx_is_setup?
51
+ setup_nginx
52
+ end
53
+
54
+ unless dev_site_is_setup?
55
+ setup_dev_site
56
+ end
57
+
58
+ unless env_is_setup?
59
+ setup_env
60
+ end
61
+
62
+ unless synced_folder_is_setup?
63
+ setup_synced_folder
64
+ end
65
+
66
+ if @opts[:repository]
67
+ setup_repo
68
+ end
69
+
70
+ if setup_was_successful?
71
+ say "Restarting VVV...", :yellow
72
+
73
+ if restart_vagrant
74
+
75
+ # Get smiley ASCII art
76
+ success = File.read(File.expand_path("../ascii/smiley.txt", __FILE__))
77
+
78
+ # Output welcome message
79
+ say "\n"
80
+ say set_color(success, :yellow)
81
+ say "\n"
82
+ say "Success!".center(48), :green
83
+ say "\n"
84
+
85
+ # Output setup info
86
+ say "Here's your installation info:", :yellow
87
+ say "Site name: #{@opts[:site_name]}", :green
88
+ say "Site location: #{@opts[:site_location]}", :green
89
+ say "Starter theme: #{@opts[:starter_theme]}", :green
90
+ say "Development location: #{@opts[:dev_location]}", :green
91
+ say "Development url: http://#{@opts[:dev_url]}", :green
92
+ say "Initialized repository: #{@opts[:repository]}", :green
93
+ say "Database host: #{@opts[:db_host]}", :green
94
+ say "Database name: #{@opts[:db_name]}", :green
95
+ say "Database username: #{@opts[:db_user]}", :green
96
+ say "Database password: #{@opts[:db_pass]}", :green
97
+ end
98
+ else
99
+ say "Setup failed. Running cleanup...", :red
100
+ delete @opts[:site_name], false
101
+ end
102
+ end
103
+
104
+ ###
105
+ # Remove all traces of site from Vagrant
106
+ #
107
+ # @param {String} site
108
+ # @param {Bool} restart
109
+ #
110
+ # @return {Void}
111
+ ###
112
+ def delete(site, restart)
113
+
114
+ ###
115
+ # @TODO - This is a really hacky way to remove the theme.
116
+ # Eventually I'd like to handle state.
117
+ ###
118
+ @opts = {
119
+ site_name: site,
120
+ dev_location: File.expand_path("~/vagrant/www/tj-#{site}")
121
+ }
122
+
123
+ if dev_site_is_setup?
124
+ remove_dev_site
125
+ else
126
+ say "Site '#{@opts[:site_name]}' does not exist.", :red
127
+ exit 1
128
+ end
129
+
130
+ if database_is_setup?
131
+ remove_database
132
+ end
133
+
134
+ if synced_folder_is_setup?
135
+ remove_synced_folder
136
+ end
137
+
138
+ if removal_was_successful?
139
+ say "Site '#{@opts[:site_name]}' successfully removed!", :green
140
+
141
+ unless restart
142
+ say "Restarting VVV...", :yellow
143
+ restart_vagrant
144
+ end
145
+ else
146
+ say "Site '#{@opts[:site_name]}' could not be fully be removed.", :red
147
+ end
148
+ end
149
+
150
+ ###
151
+ # List all development sites
152
+ #
153
+ # @return {Array}
154
+ ###
155
+ def list
156
+ sites = []
157
+
158
+ Dir.glob(File.expand_path("~/vagrant/www/*")).each do |f|
159
+ sites << File.basename(f).gsub(/(tj-)/, "") if File.directory?(f) && f.include?("tj-")
160
+ end
161
+
162
+ if sites.empty?
163
+ say "Nothing to list. Create a new site!", :yellow
164
+ else
165
+ i = 0
166
+ # Output site to cli
167
+ sites.each { |site| i += 1; say "#{i}) #{site}", :green }
168
+ end
169
+
170
+ sites
171
+ end
172
+
173
+ private
174
+
175
+ ###
176
+ # Restart Vagrant
177
+ #
178
+ # @note
179
+ # Normally a simple 'vagrant reload' would work, but Landrush requires a
180
+ # 'vagrant up' to be fired for it to set up the DNS correctly.
181
+ #
182
+ # @return {Void}
183
+ ###
184
+ def restart_vagrant
185
+ system [
186
+ "cd ~/vagrant",
187
+ "vagrant halt",
188
+ "vagrant up --provision"
189
+ ].join " && "
190
+ end
191
+
192
+ ###
193
+ # @return {Bool}
194
+ ###
195
+ def setup_was_successful?
196
+ vvv_is_setup? and dev_site_is_setup? and hosts_is_setup? and database_is_setup? and nginx_is_setup?
197
+ end
198
+
199
+ ###
200
+ # @return {Bool}
201
+ ###
202
+ def removal_was_successful?
203
+ !setup_was_successful?
204
+ end
205
+
206
+ ###
207
+ # @return {Bool}
208
+ ###
209
+ def vvv_is_setup?
210
+ File.exists? File.expand_path("~/vagrant")
211
+ end
212
+
213
+ ###
214
+ # @return {Bool}
215
+ ###
216
+ def dev_site_is_setup?
217
+ File.exists? "#{@opts[:dev_location]}"
218
+ end
219
+
220
+ ###
221
+ # @return {Bool}
222
+ ###
223
+ def hosts_is_setup?
224
+ File.exists? "#{@opts[:site_location]}/vvv-hosts"
225
+ end
226
+
227
+ ###
228
+ # @return {Bool}
229
+ ###
230
+ def database_is_setup?
231
+ File.readlines(File.expand_path("~/vagrant/database/init-custom.sql")).grep(/(### Begin '#{@opts[:site_name]}')/m).any?
232
+ end
233
+
234
+ ###
235
+ # @return {Bool}
236
+ ###
237
+ def nginx_is_setup?
238
+ File.exists? "#{@opts[:site_location]}/vvv-nginx.conf"
239
+ end
240
+
241
+ ###
242
+ # @return {Bool}
243
+ ###
244
+ def wordpress_is_setup?
245
+ File.exists? File.expand_path("#{@opts[:site_location]}/app")
246
+ end
247
+
248
+ ###
249
+ # @return {Bool}
250
+ ###
251
+ def synced_folder_is_setup?
252
+ File.readlines(File.expand_path("~/vagrant/Vagrantfile")).grep(/(### Begin '#{@opts[:site_name]}')/m).any?
253
+ end
254
+
255
+ ###
256
+ # @return {Bool}
257
+ ###
258
+ def repo_is_setup?
259
+ File.exists? File.expand_path("#{@opts[:site_location]}/.git")
260
+ end
261
+
262
+ ###
263
+ # @return {Bool}
264
+ ###
265
+ def env_is_setup?
266
+ File.exists? File.expand_path("#{@opts[:site_location]}/.env.development")
267
+ end
268
+
269
+ ###
270
+ # Install plugins and clone VVV
271
+ #
272
+ # @return {Void}
273
+ ###
274
+ def setup_vvv
275
+ say "Installing VVV into '#{File.expand_path("~/vagrant")}'.", :yellow
276
+ system [
277
+ "vagrant plugin install vagrant-hostsupdater",
278
+ "vagrant plugin install vagrant-triggers",
279
+ "vagrant plugin install landrush",
280
+ "git clone https://github.com/Varying-Vagrant-Vagrants/VVV.git ~/vagrant",
281
+ "cd ~/vagrant/database && touch init-custom.sql"
282
+ ].join " && "
283
+
284
+ setup_wildcard_subdomains
285
+ end
286
+
287
+ ###
288
+ # Enable Landrush for wildcard subdomains
289
+ #
290
+ # This will write a Landrush activation block to the global Vagrantfile
291
+ # if one does not already exist.
292
+ #
293
+ # @return {Void}
294
+ ###
295
+ def setup_wildcard_subdomains
296
+ say "Setting up wildcard subdomains...", :yellow
297
+ open File.expand_path("~/vagrant/Vagrantfile"), "a+" do |file|
298
+ file.puts "###"
299
+ file.puts "# Enable wildcard subdomains"
300
+ file.puts "#"
301
+ file.puts "# This block is automatically generated by ThemeJuice. Do not edit."
302
+ file.puts "###"
303
+ file.puts "Vagrant.configure('2') do |config|"
304
+ file.puts "\tconfig.landrush.enabled = true"
305
+ file.puts "\tconfig.landrush.tld = 'dev'"
306
+ file.puts "end"
307
+ file.puts "\n"
308
+ end
309
+ end
310
+
311
+ ###
312
+ # Create a new directory for site that will be symlinked with the local install
313
+ #
314
+ # @return {Void}
315
+ ###
316
+ def setup_dev_site
317
+ say "Setting up new development site at '#{@opts[:dev_location]}'.", :yellow
318
+ system [
319
+ "cd ~/vagrant/www",
320
+ "mkdir tj-#{@opts[:site_name]}"
321
+ ].join " && "
322
+ end
323
+
324
+ ###
325
+ # Create vvv-hosts file
326
+ #
327
+ # @return {Void}
328
+ ###
329
+ def setup_hosts
330
+ File.open "#{@opts[:site_location]}/vvv-hosts", "w" do |file|
331
+ file.puts @opts[:dev_url]
332
+ end
333
+
334
+ if hosts_is_setup?
335
+ say "Successfully added 'vvv-hosts' file.", :green
336
+ else
337
+ say "Could not create 'vvv-hosts' file.", :red
338
+ end
339
+ end
340
+
341
+ ###
342
+ # Add database block to init-custom.sql, create if not exists
343
+ #
344
+ # @return {Void}
345
+ ###
346
+ def setup_database
347
+ File.open File.expand_path("~/vagrant/database/init-custom.sql"), "a+" do |file|
348
+ file.puts "### Begin '#{@opts[:site_name]}'"
349
+ file.puts "#"
350
+ file.puts "# This block is automatically generated by ThemeJuice. Do not edit."
351
+ file.puts "###"
352
+ file.puts "CREATE DATABASE IF NOT EXISTS `#{@opts[:db_name]}`;"
353
+ file.puts "GRANT ALL PRIVILEGES ON `#{@opts[:db_name]}`.* TO '#{@opts[:db_user]}'@'localhost' IDENTIFIED BY '#{@opts[:db_pass]}';"
354
+ file.puts "### End '#{@opts[:site_name]}'"
355
+ file.puts "\n"
356
+ end
357
+
358
+ if database_is_setup?
359
+ say "Successfully added database to 'init-custom.sql'.", :green
360
+ else
361
+ say "Could not add database info for '#{@opts[:site_name]}' to 'init-custom.sql'.", :red
362
+ end
363
+ end
364
+
365
+ ###
366
+ # Create vvv-nginx.conf file for local development site
367
+ #
368
+ # @return {Void}
369
+ ###
370
+ def setup_nginx
371
+ File.open "#{@opts[:site_location]}/vvv-nginx.conf", "w" do |file|
372
+ file.puts "server {"
373
+ file.puts "\tlisten 80;"
374
+ file.puts "\tserver_name .#{@opts[:dev_url]};"
375
+ file.puts "\troot {vvv_path_to_folder};"
376
+ file.puts "\tinclude /etc/nginx/nginx-wp-common.conf;"
377
+ file.puts "}"
378
+ end
379
+
380
+ if nginx_is_setup?
381
+ say "Successfully added 'vvv-nginx.conf' file.", :green
382
+ else
383
+ say "Could not create 'vvv-nginx.conf' file.", :red
384
+ end
385
+ end
386
+
387
+ ###
388
+ # Create Dotenv environment file
389
+ #
390
+ # @return {Void}
391
+ ###
392
+ def setup_env
393
+ File.open "#{@opts[:site_location]}/.env.development", "w" do |file|
394
+ file.puts "DB_NAME=#{@opts[:db_name]}"
395
+ file.puts "DB_USER=#{@opts[:db_user]}"
396
+ file.puts "DB_PASSWORD=#{@opts[:db_pass]}"
397
+ file.puts "DB_HOST=#{@opts[:db_host]}"
398
+ file.puts "WP_HOME=http://#{@opts[:dev_url]}"
399
+ file.puts "WP_SITEURL=http://#{@opts[:dev_url]}/wp"
400
+ end
401
+
402
+ if env_is_setup?
403
+ say "Successfully added '.env.development' file.", :green
404
+ else
405
+ say "Could not create '.env.development' file.", :red
406
+ end
407
+ end
408
+
409
+ ###
410
+ # Setup WordPress
411
+ #
412
+ # Clones starter theme into @opts[:site_location]
413
+ #
414
+ # @return {Void}
415
+ ###
416
+ def setup_wordpress
417
+ say "Setting up WordPress...", :yellow
418
+
419
+ if @opts[:bare_setup]
420
+ # Create theme dir
421
+ system "mkdir -p #{@opts[:site_location]}"
422
+ else
423
+ # Clone starter, install WP
424
+ system [
425
+ "mkdir -p #{@opts[:site_location]} && cd $_",
426
+ "git clone --depth 1 https://github.com/#{@opts[:starter_theme]}.git .",
427
+ "composer install",
428
+ ].join " && "
429
+ end
430
+ end
431
+
432
+ ###
433
+ # Add synced folder block to Vagrantfile
434
+ #
435
+ # @return {Void}
436
+ ###
437
+ def setup_synced_folder
438
+ say "Syncing host theme directory '#{@opts[:site_location]}' with VM theme directory '/srv/www/tj-#{@opts[:site_name]}'...", :yellow
439
+
440
+ open File.expand_path("~/vagrant/Vagrantfile"), "a+" do |file|
441
+ file.puts "### Begin '#{@opts[:site_name]}'"
442
+ file.puts "#"
443
+ file.puts "# This block is automatically generated by ThemeJuice. Do not edit."
444
+ file.puts "###"
445
+ file.puts "Vagrant.configure('2') do |config|"
446
+ file.puts "\tconfig.vm.synced_folder '#{@opts[:site_location]}', '/srv/www/tj-#{@opts[:site_name]}', mount_options: ['dmode=777,fmode=777']"
447
+ file.puts "\tconfig.landrush.host '#{@opts[:dev_url]}', '192.168.50.4'"
448
+ file.puts "end"
449
+ file.puts "### End '#{@opts[:site_name]}'"
450
+ file.puts "\n"
451
+ end
452
+ end
453
+
454
+ ###
455
+ # Initialize Git repo, add remote, initial commit
456
+ #
457
+ # @return {Void}
458
+ ###
459
+ def setup_repo
460
+ say "Setting up Git repository at '#{@opts[:repository]}'...", :yellow
461
+
462
+ if repo_is_setup?
463
+ system [
464
+ "cd #{@opts[:site_location]}",
465
+ "rm -rf .git",
466
+ ].join " && "
467
+ end
468
+
469
+ system [
470
+ "cd #{@opts[:site_location]}",
471
+ "git init",
472
+ "git remote add origin #{@opts[:repository]}"
473
+ ].join " && "
474
+ end
475
+
476
+ ###
477
+ # Remove all theme files from Vagrant directory
478
+ #
479
+ # @return {Void}
480
+ ###
481
+ def remove_dev_site
482
+ if system "rm -rf #{@opts[:dev_location]}"
483
+ say "VVV installation for '#{@opts[:site_name]}' successfully removed.", :green
484
+ else
485
+ say "Theme '#{@opts[:site_name]}' could not be removed. Make sure you have write capabilities.", :red
486
+ end
487
+ end
488
+
489
+ ###
490
+ # Remove database block from init-custom.sql
491
+ #
492
+ # @return {Void}
493
+ ###
494
+ def remove_database
495
+ if remove_traces_from_file "~/vagrant/database/init-custom.sql"
496
+ say "Database for '#{@opts[:site_name]}' successfully removed.", :green
497
+ end
498
+ end
499
+
500
+ ###
501
+ # Remove synced folder block from Vagrantfile
502
+ #
503
+ # @return {Void}
504
+ ###
505
+ def remove_synced_folder
506
+ if remove_traces_from_file "~/vagrant/Vagrantfile"
507
+ say "Synced folders for '#{@opts[:site_name]}' successfully removed.", :green
508
+ end
509
+ end
510
+
511
+ ###
512
+ # Remove all traces of auto-generated content from file
513
+ #
514
+ # @param {String} input_file
515
+ #
516
+ # @return {Void}
517
+ ###
518
+ def remove_traces_from_file(input_file)
519
+ begin
520
+ # Create new tempfile
521
+ output_file = Tempfile.new File.basename(input_file)
522
+ # Copy over contents of actual file to tempfile
523
+ open File.expand_path(input_file), "rb" do |file|
524
+ # Remove traces of theme from contents
525
+ output_file.write "#{file.read}".gsub(/(### Begin '#{@opts[:site_name]}')(.*?)(### End '#{@opts[:site_name]}')\n+/m, "")
526
+ end
527
+ # Move temp file to actual file location
528
+ FileUtils.mv output_file, File.expand_path(input_file)
529
+ rescue LoadError => err
530
+ say err, :red
531
+ exit 1
532
+ ensure
533
+ # Make sure that the tempfile closes and is cleaned up, regardless of errors
534
+ output_file.close
535
+ output_file.unlink
536
+ end
537
+ end
538
+ end
539
+ end
540
+ end
@@ -0,0 +1,3 @@
1
+ module ThemeJuice
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ require "securerandom"
2
+ require "fileutils"
3
+ require "pathname"
4
+ require "tempfile"
5
+ require "thor"
6
+
7
+ require_relative "theme-juice/version"
8
+ require_relative "theme-juice/scaffold"
9
+ require_relative "theme-juice/cli"
10
+
11
+ module ThemeJuice
12
+ class << self
13
+
14
+ ###
15
+ # Check if program is installed
16
+ #
17
+ # @note Doesn't work on Win
18
+ #
19
+ # @param {String} program
20
+ #
21
+ # @return {Bool}
22
+ ###
23
+ def installed?(program)
24
+ system "which #{program} > /dev/null 2>&1"
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: theme-juice
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ezekiel Gabrielse
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: highline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A WordPress development framework that scaffolds out an entire Vagrant
42
+ development environment in seconds. Uses trendy tech like Haml, Sass and CoffeeScript.
43
+ email:
44
+ - ezekg@yahoo.com
45
+ executables:
46
+ - tj
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - lib/theme-juice/ascii/logo.txt
51
+ - lib/theme-juice/ascii/smiley.txt
52
+ - lib/theme-juice/cli.rb
53
+ - lib/theme-juice/scaffold.rb
54
+ - lib/theme-juice/version.rb
55
+ - lib/theme-juice.rb
56
+ - LICENSE
57
+ - README.md
58
+ - bin/tj
59
+ homepage: https://github.com/ezekg/theme-juice-cli.git
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: 2.0.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project: theme-juice
79
+ rubygems_version: 2.0.14
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: A WordPress development framework.
83
+ test_files: []