theme-juice 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63c52fd656dcfb57f5f07f15a924c0cd174c48b9
4
- data.tar.gz: 4676d9a168acf7dd7829947cad646b8031d805ba
3
+ metadata.gz: 47cfb1bd6b78a1ad40cef06b741e60a18fbb3d86
4
+ data.tar.gz: 0f55c3a06d5b06531eef6b62c8ed52e182cc9621
5
5
  SHA512:
6
- metadata.gz: fc55911c12aa9e7a71b5d1401efa2ca4b662987fade550d1dd6288a4618e96702e6000be28716021e659992fc40dd356a350929fbe08f256679873bdefb70df1
7
- data.tar.gz: e27f7320c22ac6e0dcc0c8bf17ab506a9a44168d932cc1c12e23cf82016c0ee94d182cc7e749426bb5be035c045a4f961f97395338e9ff3d30c67a2f29a1f247
6
+ metadata.gz: dca54558fe02ceb234995e3e2f160c4f5045425ad18564abc06e0f4d535fb5b769e95834caacf430c147b28237e074527833811eb160545cd6a7d36cca0b8048
7
+ data.tar.gz: 567627416d854968ad33a8fae4c9e810980ef55f5fdb7ba3f42153967377f1ca681fb638df108c66afd484f7a593daf7cb37630d77f9d9170abe15fa4ec20c9b
data/README.md CHANGED
@@ -5,78 +5,111 @@ Command line interface to scaffold out a new WordPress development environment a
5
5
  * First, install [Vagrant](https://www.vagrantup.com/) and [VirtualBox](https://www.virtualbox.org/) for local development.
6
6
  * Then, install [Composer](https://getcomposer.org/) and [WP-CLI](http://wp-cli.org/) (make sure they're executable).
7
7
  * Finally, install with: `gem install theme-juice`
8
-
9
8
  That`s it!
10
9
 
10
+ ## Config
11
+ Because everybody likes to use different tools, you can create a `tj-config.yml` file that will house all of your theme-specific commands. This allows you to use a streamlined set of commands that will act as aliases to your per-project configuration. If you're into [Grunt](https://github.com/gruntjs/grunt), then use it. Prefer [Guard](https://github.com/guard/guard)? Go right ahead. This is obviously relative to the starter theme you use, since you can't exactly use Grunt with a starter theme that doesn't support it. Below is the config that comes baked into [our starter theme](https://github.com/ezekg/theme-juice-starter):
12
+
13
+ ```yml
14
+ watch: bundle exec guard
15
+ server: bundle exec cap
16
+ vendor: composer
17
+ install:
18
+ - composer install
19
+
20
+ ```
21
+
22
+ _Note: If you use a starter theme that doesn't have a `tj-config.yml` file, you'll be prompted through a series of steps in order to create one._
23
+
24
+ #### Config options:
25
+ | Option | Usage |
26
+ |:--------- |:----------------------------------------------------------------------------- |
27
+ | `watch` | Command to be aliased when you run `tj watch` for bulding assets |
28
+ | `server` | Command to be aliased when you run `tj server` for deployments |
29
+ | `vendor` | Command to be aliased when you run `tj vendor` for dependencies |
30
+ | `install` | Each command is executed when you run `tj install` to prepare a starter theme |
31
+
11
32
  ## Usage
12
33
 
13
- #### List available commands:
34
+ ### List available commands:
14
35
  List all commands for `tj`.
15
36
  ```bash
16
37
  tj
17
38
  ```
18
39
 
19
- #### Print version:
40
+ ### Print version:
20
41
  This command will print the current version of `tj`.
21
42
  ```bash
22
- tj version
43
+ tj --version # Aliases: -v, version
23
44
  ```
24
45
 
25
- #### Setup VVV:
46
+ ### Setup VVV:
26
47
  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._
27
48
  ```bash
28
49
  tj init
29
50
  ```
30
51
 
31
- #### Creating a new development site:
52
+ ### Creating a new development site:
32
53
  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.
33
54
  ```bash
34
- tj create [<SITE-NAME>]
55
+ tj create [<SITE-NAME>] # Aliases: new, build, make
35
56
  ```
36
57
 
37
- #### Setting up an existing site:
58
+ #### Option flags:
59
+ | Flag | Type | Description |
60
+ |:--------------------------------------- |:------ |:------------------------------------------------ |
61
+ | `-b, [--bare], [--no-bare]` | Bool | Create a VVV site without a starter theme |
62
+ | `-s, [--site=SITE]` | String | Name of the development site |
63
+ | `-l, [--location=LOCATION]` | Path | Location of the local site |
64
+ | `-t, [--theme=THEME]` | URL | Starter theme to install (can use `none`) |
65
+ | `-u, [--url=URL]` | URL | Development URL of the site (must end in `.dev`) |
66
+ | `-r, [--repository]` | String | Initialize a new Git remote repository |
67
+ | `[--skip-repo], [--no-skip-repo]` | Bool | Skip repository prompts and set to `none` |
68
+ | `[--skip-db], [--no-skip-db]` | Bool | Skip database prompts and use defaults |
69
+
70
+ ### Setting up an existing site:
38
71
  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.
39
72
  ```bash
40
- tj setup [<SITE-NAME>] # Alias for 'tj create [<SITE-NAME>] --bare'
73
+ tj setup [<SITE-NAME>] # Aliases: init, prep
41
74
  ```
42
75
 
43
- #### Deleting a site from the VM: _(Does not remove your local site)_
76
+ ### Deleting a site from the VM: _(Does not remove your local site)_
44
77
  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._
45
78
  ```bash
46
- tj delete <SITE-NAME>
79
+ tj delete <SITE-NAME> # Aliases: remove, teardown
47
80
  ```
48
81
 
49
- #### Listing all `tj` sites in the VM:
82
+ ### Listing all `tj` sites in the VM:
50
83
  Use this to list all sites within your development environment that were generated by `tj`.
51
84
  ```bash
52
- tj list
85
+ tj list # Aliases: sites, show
53
86
  ```
54
87
 
55
- #### Watching and compiling assets: _(Guard)_
56
- Use this to watch and compile assets with [Guard](https://github.com/guard/guard). This is simply a wrapper for Guard commands.
88
+ ### Watching and compiling assets:
89
+ Use this to watch and compile assets with your preferred build tool, whether that be [Grunt](https://github.com/gruntjs/grunt), [Gulp](https://github.com/gulpjs/gulp), [Guard](https://github.com/guard/guard), or whatever. This is simply a wrapper for whatever command is in your `tj-config.yml` file.
57
90
  ```bash
58
- tj watch # Alias for 'bundle exec guard [<COMMANDS>]'
91
+ tj watch # Aliases: dev
59
92
  ```
60
93
 
61
- #### Managing development environment: _(Vagrant)_
62
- 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.
94
+ ### Managing development environment:
95
+ 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 executed within your VVV path.
63
96
  ```bash
64
- tj vm # Alias for 'cd ~/vagrant && vagrant [<COMMANDS>]'
97
+ tj vm # Aliases: vagrant, vvv
65
98
  ```
66
99
 
67
- #### Managing vendor dependencies: _(Composer)_
68
- Use this to easily manage your [Composer](https://github.com/composer/composer) dependencies. This is simply a wrapper for Composer commands.
100
+ ### Managing vendor dependencies:
101
+ Use this to easily manage your dependencies with [Composer](https://github.com/composer/composer), or whatever other command you set in your `tj-config.yml`. This is a wrapper for whatever command is in your config file.
69
102
  ```bash
70
- tj vendor # Alias for 'composer [<COMMANDS>]'
103
+ tj vendor # Aliases: deps
71
104
  ```
72
105
 
73
- #### Managing deployment and migration: _(Capistrano)_
74
- Use this to easily manage your deployment and migration with [Capistrano](https://github.com/capistrano/capistrano). This is simply a wrapper for Capistrano commands.
106
+ ### Managing deployment and migration:
107
+ Use this to easily manage your deployment and migration with [Capistrano](https://github.com/capistrano/capistrano) (or again, anything else set within your `tj-config.yml`). This is just a wrapper for your chosen command.
75
108
  ```bash
76
- tj server # Alias for 'bundle exec cap [<COMMANDS>]'
109
+ tj server # Aliases: deploy
77
110
  ```
78
111
 
79
- #### Executing WP-CLI locally inside your VM with `wp-cli-ssh`
112
+ ### Executing WP-CLI locally inside your VM with `wp-cli-ssh`
80
113
  You can run `wp` commands locally if you specify a `--host`. Upon setup, an `ssh` block for the VM is automatically added to the `wp-cli.local.yml` file with all of your development environment paths.
81
114
  ```bash
82
115
  wp ssh --host=vagrant [<COMMANDS>]
@@ -2,26 +2,15 @@ require "securerandom"
2
2
  require "fileutils"
3
3
  require "pathname"
4
4
  require "tempfile"
5
+ require "rubygems"
5
6
  require "thor"
7
+ require "yaml"
6
8
 
7
9
  require_relative "theme-juice/version"
8
- require_relative "theme-juice/scaffold"
10
+ require_relative "theme-juice/utilities"
11
+ require_relative "theme-juice/executor"
9
12
  require_relative "theme-juice/cli"
10
13
 
11
14
  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
15
+ # Silence is golden?
27
16
  end
@@ -1,11 +1,34 @@
1
1
  module ThemeJuice
2
2
  class CLI < ::Thor
3
3
 
4
+ map %w[--version -v] => :version
5
+ map %w[new, build, make] => :create
6
+ map %w[setup, init, prep] => :create
7
+ map %w[remove, teardown] => :delete
8
+ map %w[sites, show] => :list
9
+ map %w[dev] => :watch
10
+ map %w[dep, deps] => :vendor
11
+ map %w[deploy] => :server
12
+ map %w[vagrant, vvv] => :vm
13
+
14
+ class_option :vvv_path, type: :string, alias: "-fp", default: nil, desc: "Force path to VVV installation"
15
+
4
16
  ###
5
- # Non Thor commands
17
+ # Non-Thor commands
6
18
  ###
7
19
  no_commands do
8
20
 
21
+ ###
22
+ # Set VVV path
23
+ #
24
+ # @return {Void}
25
+ ###
26
+ def force_vvv_path?
27
+ unless options[:vvv_path].nil?
28
+ ::ThemeJuice::Utilities.set_vvv_path options[:vvv_path]
29
+ end
30
+ end
31
+
9
32
  ###
10
33
  # Welcome message
11
34
  #
@@ -30,22 +53,11 @@ module ThemeJuice
30
53
  #
31
54
  # @return {String}
32
55
  ###
33
- desc "version", "Print current version"
56
+ desc "--version, -v", "Print current version"
34
57
  def version
35
- say "Current version: #{::ThemeJuice::VERSION}", :green
36
- end
58
+ # ::ThemeJuice::Utilities.check_if_current_version_is_outdated
37
59
 
38
- ###
39
- # Install and setup VVV environment
40
- #
41
- # @return {Void}
42
- ###
43
- desc "init", "Setup the VVV environment"
44
- def init
45
- self.welcome
46
-
47
- # Setup the VM
48
- ::ThemeJuice::Scaffold::init
60
+ say ::ThemeJuice::VERSION, :green
49
61
  end
50
62
 
51
63
  ###
@@ -58,37 +70,17 @@ module ThemeJuice
58
70
  #
59
71
  # @return {Void}
60
72
  ###
61
- desc "create [SITE]", "Setup SITE and the VVV development environment"
62
- method_option :bare,
63
- type: :boolean,
64
- aliases: "-b",
65
- desc: "Create a VVV site without a starter theme"
66
- method_option :site,
67
- type: :string,
68
- aliases: "-s",
69
- default: false,
70
- desc: "Name of the development site"
71
- method_option :location,
72
- type: :string,
73
- aliases: "-l",
74
- default: false,
75
- desc: "Location of the local site"
76
- method_option :theme,
77
- type: :string,
78
- aliases: "-t",
79
- default: false,
80
- desc: "Starter theme to install"
81
- method_option :url,
82
- type: :string,
83
- aliases: "-u",
84
- default: false,
85
- desc: "Development URL of the site"
86
- method_option :repository,
87
- type: :boolean,
88
- aliases: "-r",
89
- default: false,
90
- desc: "Initialize a new Git remote repository"
91
- def create(site = nil, bare_setup = false)
73
+ desc "create [SITE]", "Create new SITE and setup the VVV development environment"
74
+ method_option :bare, type: :boolean, aliases: "-b", desc: "Create a VVV site without a starter theme"
75
+ method_option :site, type: :string, aliases: "-s", default: false, desc: "Name of the development site"
76
+ method_option :location, type: :string, aliases: "-l", default: false, desc: "Location of the local site"
77
+ method_option :theme, type: :string, aliases: "-t", default: false, desc: "Starter theme to install"
78
+ method_option :url, type: :string, aliases: "-u", default: false, desc: "Development URL of the site"
79
+ method_option :repository, type: :string, aliases: "-r", desc: "Initialize a new Git remote repository"
80
+ method_option :skip_repo, type: :boolean, desc: "Skip repository prompts and use defaults"
81
+ method_option :skip_db, type: :boolean, desc: "Skip database prompts and use defaults"
82
+ def create(site = nil)
83
+ self.force_vvv_path?
92
84
  self.welcome
93
85
 
94
86
  if options[:site]
@@ -96,7 +88,7 @@ module ThemeJuice
96
88
  end
97
89
 
98
90
  # Check if user passed all required options through flags
99
- if options.all? { |opt, val| val != false }
91
+ if options.length >= 6
100
92
  say "Well... looks like you just have everything all figured out, huh?", :yellow
101
93
  elsif site.nil?
102
94
  say "Just a few questions before we begin...", :yellow
@@ -128,31 +120,42 @@ module ThemeJuice
128
120
  end
129
121
 
130
122
  # Starter theme to clone
131
- unless bare_setup
123
+ if bare_setup
124
+ starter_theme = "none"
125
+ else
132
126
 
133
127
  if options[:theme]
134
128
  starter_theme = options[:theme]
135
129
  else
136
130
  require "highline/import"
137
131
 
138
- starter_theme = nil
132
+ # Hash of baked-in starter themes
133
+ themes = {
134
+ "theme-juice/theme-juice-starter" => "https://github.com/ezekg/theme-juice-starter.git"
135
+ }
139
136
 
140
137
  say "Which starter theme would you like to use? :", :blue
141
138
  choose do |menu|
142
139
  menu.index_suffix = ") "
143
140
 
144
- menu.choice "ezekg/theme-juice-starter" do |c|
145
- say "Awesome choice!", :green
146
- starter_theme = c
141
+ themes.each do |theme, repo|
142
+ menu.choice theme do
143
+
144
+ if theme == "theme-juice/theme-juice-starter"
145
+ say "Awesome choice!", :green
146
+ end
147
+
148
+ starter_theme = repo
149
+ end
147
150
  end
148
151
 
149
152
  menu.choice "other" do
150
- starter_theme = ask "What is the user/repository of the starter theme you would like to clone? :", :blue
153
+ starter_theme = ask "What is the repository URL for the starter theme you would like to clone? :", :blue
151
154
  end
152
155
 
153
- menu.choice "none" do |c|
156
+ menu.choice "none" do |opt|
154
157
  say "Next time you want to create a site without a starter theme, you can just run the 'setup' command instead.", :yellow
155
- starter_theme, bare_setup = c, true
158
+ starter_theme, bare_setup = opt, true
156
159
  end
157
160
  end
158
161
  end
@@ -171,40 +174,44 @@ module ThemeJuice
171
174
  end
172
175
 
173
176
  # Initialize a git repository on setup
174
- if options[:repository]
175
- repository = options[:repository]
177
+ if options[:skip_repo]
178
+ repository = false
176
179
  else
177
- if yes? "Would you like to initialize a new Git repository? (y/N) :", :blue
178
- repository = ask "What is the repository's URL? :", :blue
180
+ if options[:repository]
181
+ repository = options[:repository]
179
182
  else
180
- repository = false
183
+ if yes? "Would you like to initialize a new Git repository? (y/N) :", :blue
184
+ repository = ask "What is the repository's URL? :", :blue
185
+ else
186
+ repository = false
187
+ end
181
188
  end
182
189
  end
183
190
 
184
191
  # Database host
185
- if options[:db_host]
186
- db_host = options[:db_host]
192
+ if options[:skip_db]
193
+ db_host = "vvv"
187
194
  else
188
195
  db_host = ask "Database host :", :blue, default: "vvv"
189
196
  end
190
197
 
191
198
  # Database name
192
- if options[:db_name]
193
- db_name = options[:db_name]
199
+ if options[:skip_db]
200
+ db_name = "#{clean_site_name}_db"
194
201
  else
195
202
  db_name = ask "Database name :", :blue, default: "#{clean_site_name}_db"
196
203
  end
197
204
 
198
205
  # Database username
199
- if options[:db_user]
200
- db_user = options[:db_user]
206
+ if options[:skip_db]
207
+ db_user = "#{clean_site_name}_user"
201
208
  else
202
209
  db_user = ask "Database username :", :blue, default: "#{clean_site_name}_user"
203
210
  end
204
211
 
205
212
  # Database password
206
- if options[:db_pass]
207
- db_pass = options[:db_pass]
213
+ if options[:skip_db]
214
+ db_pass = SecureRandom.base64
208
215
  else
209
216
  db_pass = ask "Database password :", :blue, default: SecureRandom.base64
210
217
  end
@@ -215,7 +222,7 @@ module ThemeJuice
215
222
  site_location: File.expand_path(site_location),
216
223
  starter_theme: starter_theme,
217
224
  bare_setup: bare_setup,
218
- dev_location: File.expand_path("~/vagrant/www/tj-#{site}"),
225
+ dev_location: File.expand_path("#{::ThemeJuice::Utilities.get_vvv_path}/www/tj-#{site}"),
219
226
  dev_url: dev_url,
220
227
  repository: repository,
221
228
  db_host: db_host,
@@ -237,9 +244,9 @@ module ThemeJuice
237
244
  say "---> Database password: #{opts[:db_pass]}", :green
238
245
 
239
246
  if yes? "Do the options above look correct? (y/N) :", :blue
240
- ::ThemeJuice::Scaffold::create opts
247
+ ::ThemeJuice::Executor::create opts
241
248
  else
242
- say "Alrighty then! Aborting mission.", :red
249
+ say "Dang typos... aborting mission.", :red
243
250
  exit 1
244
251
  end
245
252
  else
@@ -256,9 +263,9 @@ module ThemeJuice
256
263
  #
257
264
  # @return {Void}
258
265
  ###
259
- desc "setup [SITE]", "Create a VVV site without starter theme (alias for 'create --bare')"
266
+ desc "setup [SITE]", "Setup an existing SITE in development environment"
260
267
  def setup(site = nil)
261
- self.create site, true
268
+ invoke :create, [site], bare: true
262
269
  end
263
270
 
264
271
  ###
@@ -272,8 +279,10 @@ module ThemeJuice
272
279
  desc "delete SITE", "Remove SITE from the VVV development environment (does not remove local site)"
273
280
  method_option :restart, type: :boolean
274
281
  def delete(site)
282
+ self.force_vvv_path?
283
+
275
284
  if yes? "Are you sure you want to delete '#{site}'? (y/N)", :red
276
- ::ThemeJuice::Scaffold::delete site, options[:restart]
285
+ ::ThemeJuice::Executor::delete site, options[:restart]
277
286
  end
278
287
  end
279
288
 
@@ -284,59 +293,76 @@ module ThemeJuice
284
293
  ###
285
294
  desc "list", "List all sites within the VVV development environment"
286
295
  def list
287
- ::ThemeJuice::Scaffold::list
296
+ self.force_vvv_path?
297
+
298
+ ::ThemeJuice::Executor::list
288
299
  end
289
300
 
290
301
  ###
291
- # Guard
302
+ # Install and setup starter theme
303
+ #
304
+ # @return {Void}
305
+ ###
306
+ desc "install", "Run installation for the starter theme"
307
+ method_option :config, type: :string, aliases: "-c", default: nil, desc: "Force path to config file"
308
+ def install
309
+ ::ThemeJuice::Executor::install options[:config]
310
+ end
311
+
312
+ ###
313
+ # Assets
292
314
  #
293
315
  # @param {*} commands
294
316
  # Commands to run
295
317
  #
296
318
  # @return {Void}
297
319
  ###
298
- desc "watch [COMMANDS]", "Watch and compile assets with Guard (alias for 'bundle exec guard [COMMANDS]')"
320
+ desc "watch [COMMANDS]", "Watch and compile assets"
299
321
  def watch(*commands)
300
- system "bundle exec guard #{commands.join(" ")}"
322
+ ::ThemeJuice::Executor::subcommand "#{__method__}", commands.join(" ")
301
323
  end
302
324
 
303
325
  ###
304
- # Vagrant
326
+ # Vendor dependencies
305
327
  #
306
328
  # @param {*} commands
307
329
  # Commands to run
308
330
  #
309
331
  # @return {Void}
310
332
  ###
311
- desc "vm [COMMANDS]", "Manage virtual development environment with Vagrant (alias for 'vagrant [COMMANDS]')"
312
- def vm(*commands)
313
- system "cd ~/vagrant && vagrant #{commands.join(" ")}"
333
+ desc "vendor [COMMANDS]", "Manage vendor dependencies"
334
+ def vendor(*commands)
335
+ ::ThemeJuice::Executor::subcommand "#{__method__}", commands.join(" ")
314
336
  end
315
337
 
316
338
  ###
317
- # Composer
339
+ # Server/Deployment
318
340
  #
319
341
  # @param {*} commands
320
342
  # Commands to run
321
343
  #
322
344
  # @return {Void}
323
345
  ###
324
- desc "vendor [COMMANDS]", "Manage vendor dependencies with Composer (alias for 'composer [COMMANDS]')"
325
- def vendor(*commands)
326
- system "composer #{commands.join(" ")}"
346
+ desc "server [COMMANDS]", "Manage deployment and migration"
347
+ def server(*commands)
348
+ self.force_vvv_path?
349
+
350
+ ::ThemeJuice::Executor::subcommand "#{__method__}", commands.join(" ")
327
351
  end
328
352
 
329
353
  ###
330
- # Capistrano
354
+ # Vagrant
331
355
  #
332
356
  # @param {*} commands
333
357
  # Commands to run
334
358
  #
335
359
  # @return {Void}
336
360
  ###
337
- desc "server [COMMANDS]", "Manage deployment and migration with Capistrano (alias for 'bundle exec cap [COMMANDS]')"
338
- def server(*commands)
339
- system "bundle exec cap #{commands.join(" ")}"
361
+ desc "vm [COMMANDS]", "Manage virtual development environment with Vagrant"
362
+ def vm(*commands)
363
+ self.force_vvv_path?
364
+
365
+ system "cd #{::ThemeJuice::Utilities.get_vvv_path} && vagrant #{commands.join(" ")}"
340
366
  end
341
367
  end
342
368
  end
@@ -1,21 +1,44 @@
1
1
  module ThemeJuice
2
- module Scaffold
2
+ module Executor
3
3
  class << self
4
4
  include ::Thor::Actions
5
5
  include ::Thor::Shell
6
6
 
7
7
  ###
8
- # Set up local development environment
8
+ # Run installation from config
9
+ #
10
+ # @param {String} config_path (nil)
9
11
  #
10
12
  # @return {Void}
11
13
  ###
12
- def init
13
- say "Initializing development environment...", :yellow
14
+ def install(config_path = nil)
15
+ config_path ||= File.expand_path(Dir.pwd)
16
+
17
+ use_config config_path
18
+
19
+ @config["install"].each do |command|
20
+ run ["cd #{config_path}", command], false
21
+ end
22
+ end
14
23
 
15
- if vvv_is_setup?
16
- say "Development environment is already set up. Aborting mission.", :red
24
+ ###
25
+ # Run subcommand from config
26
+ #
27
+ # @param {String} subcommand
28
+ # @param {String} commands
29
+ #
30
+ # @return {Void}
31
+ ###
32
+ def subcommand(subcommand, commands)
33
+ config_path = File.expand_path(Dir.pwd)
34
+
35
+ use_config config_path
36
+
37
+ if @config[subcommand]
38
+ run ["#{@config[subcommand]} #{commands}"], false
17
39
  else
18
- say "Setup successful!", :green if setup_vvv
40
+ say "Unable to find '#{subcommand}' command in '#{config_path}/tj-config.yml'. Aborting mission.", :red
41
+ exit 1
19
42
  end
20
43
  end
21
44
 
@@ -31,10 +54,20 @@ module ThemeJuice
31
54
 
32
55
  say "Running setup for '#{@opts[:site_name]}'...", :yellow
33
56
 
57
+ unless project_dir_is_setup?
58
+ setup_project_dir
59
+ end
60
+
34
61
  unless wordpress_is_setup?
35
62
  setup_wordpress
36
63
  end
37
64
 
65
+ if config_is_setup? @opts[:site_location]
66
+ use_config @opts[:site_location]
67
+
68
+ install_theme_dependencies
69
+ end
70
+
38
71
  unless vvv_is_setup?
39
72
  setup_vvv
40
73
  end
@@ -125,7 +158,7 @@ module ThemeJuice
125
158
  ###
126
159
  @opts = {
127
160
  site_name: site,
128
- dev_location: File.expand_path("~/vagrant/www/tj-#{site}")
161
+ dev_location: File.expand_path("#{::ThemeJuice::Utilities.get_vvv_path}/www/tj-#{site}")
129
162
  }
130
163
 
131
164
  if dev_site_is_setup?
@@ -152,6 +185,7 @@ module ThemeJuice
152
185
  end
153
186
  else
154
187
  say "Site '#{@opts[:site_name]}' could not be fully be removed.", :red
188
+ exit 1
155
189
  end
156
190
  end
157
191
 
@@ -163,16 +197,14 @@ module ThemeJuice
163
197
  def list
164
198
  sites = []
165
199
 
166
- Dir.glob(File.expand_path("~/vagrant/www/*")).each do |f|
200
+ Dir.glob(File.expand_path("#{::ThemeJuice::Utilities.get_vvv_path}/www/*")).each do |f|
167
201
  sites << File.basename(f).gsub(/(tj-)/, "") if File.directory?(f) && f.include?("tj-")
168
202
  end
169
203
 
170
204
  if sites.empty?
171
205
  say "Nothing to list. Create a new site!", :yellow
172
206
  else
173
- i = 0
174
- # Output site to cli
175
- sites.each { |site| i += 1; say "#{i}) #{site}", :green }
207
+ sites.each_with_index { |site, i| say "#{i+1}) #{site}", :green }
176
208
  end
177
209
 
178
210
  sites
@@ -195,18 +227,48 @@ module ThemeJuice
195
227
  system commands.join "&&"
196
228
  end
197
229
 
230
+ ###
231
+ # Verify config is properly setup, set global var
232
+ #
233
+ # @param {String} config_path
234
+ #
235
+ # @return {Void}
236
+ ###
237
+ def use_config(config_path)
238
+
239
+ if config_is_setup? config_path
240
+ @config = YAML.load_file "#{config_path}/tj-config.yml"
241
+ else
242
+ say "Unable to find 'tj-config.yml' file in '#{config_path}'.", :red
243
+
244
+ if yes? "Would you like to create one? (y/N) :", :blue
245
+
246
+ setup_config(config_path)
247
+
248
+ if config_is_setup? config_path
249
+ say "Please re-run the last command to continue.", :yellow
250
+ exit
251
+ else
252
+ exit 1
253
+ end
254
+ else
255
+ say "A config file is needed to continue installation. Aborting mission.", :red
256
+ exit 1
257
+ end
258
+ end
259
+ end
260
+
198
261
  ###
199
262
  # Restart Vagrant
200
263
  #
201
- # @note
202
- # Normally a simple 'vagrant reload' would work, but Landrush requires a
203
- # 'vagrant up' to be fired for it to set up the DNS correctly.
264
+ # @note Normally a simple 'vagrant reload' would work, but Landrush requires
265
+ # a 'vagrant up' to be fired for it to set up the DNS correctly.
204
266
  #
205
267
  # @return {Void}
206
268
  ###
207
269
  def restart_vagrant
208
270
  run [
209
- "cd ~/vagrant",
271
+ "cd #{::ThemeJuice::Utilities.get_vvv_path}",
210
272
  "vagrant halt",
211
273
  "vagrant up --provision",
212
274
  ], false
@@ -226,18 +288,32 @@ module ThemeJuice
226
288
  !setup_was_successful?
227
289
  end
228
290
 
291
+ ###
292
+ # @return {Bool}
293
+ ###
294
+ def project_dir_is_setup?
295
+ Dir.exist? "#{@opts[:site_location]}"
296
+ end
297
+
298
+ ###
299
+ # @return {Bool}
300
+ ###
301
+ def config_is_setup?(config_path)
302
+ File.exist? "#{config_path}/tj-config.yml"
303
+ end
304
+
229
305
  ###
230
306
  # @return {Bool}
231
307
  ###
232
308
  def vvv_is_setup?
233
- File.exist? File.expand_path("~/vagrant")
309
+ File.exist? File.expand_path(::ThemeJuice::Utilities.get_vvv_path)
234
310
  end
235
311
 
236
312
  ###
237
313
  # @return {Bool}
238
314
  ###
239
315
  def wildcard_subdomains_is_setup?
240
- File.readlines(File.expand_path("~/vagrant/Vagrantfile")).grep(/(config.landrush.enabled = true)/m).any?
316
+ File.readlines(File.expand_path("#{::ThemeJuice::Utilities.get_vvv_path}/Vagrantfile")).grep(/(config.landrush.enabled = true)/m).any?
241
317
  end
242
318
 
243
319
  ###
@@ -258,7 +334,7 @@ module ThemeJuice
258
334
  # @return {Bool}
259
335
  ###
260
336
  def database_is_setup?
261
- File.readlines(File.expand_path("~/vagrant/database/init-custom.sql")).grep(/(### Begin '#{@opts[:site_name]}')/m).any?
337
+ File.readlines(File.expand_path("#{::ThemeJuice::Utilities.get_vvv_path}/database/init-custom.sql")).grep(/(### Begin '#{@opts[:site_name]}')/m).any?
262
338
  end
263
339
 
264
340
  ###
@@ -279,7 +355,7 @@ module ThemeJuice
279
355
  # @return {Bool}
280
356
  ###
281
357
  def synced_folder_is_setup?
282
- File.readlines(File.expand_path("~/vagrant/Vagrantfile")).grep(/(### Begin '#{@opts[:site_name]}')/m).any?
358
+ File.readlines(File.expand_path("#{::ThemeJuice::Utilities.get_vvv_path}/Vagrantfile")).grep(/(### Begin '#{@opts[:site_name]}')/m).any?
283
359
  end
284
360
 
285
361
  ###
@@ -309,16 +385,26 @@ module ThemeJuice
309
385
  # @return {Void}
310
386
  ###
311
387
  def setup_vvv
312
- say "Installing VVV into '#{File.expand_path("~/vagrant")}'...", :yellow
388
+ say "Installing VVV into '#{File.expand_path("#{::ThemeJuice::Utilities.get_vvv_path}")}'...", :yellow
313
389
  run [
314
390
  "vagrant plugin install vagrant-hostsupdater",
315
391
  "vagrant plugin install vagrant-triggers",
316
392
  "vagrant plugin install landrush",
317
- "git clone https://github.com/Varying-Vagrant-Vagrants/VVV.git ~/vagrant",
318
- "cd ~/vagrant/database && touch init-custom.sql"
393
+ "git clone https://github.com/Varying-Vagrant-Vagrants/VVV.git #{::ThemeJuice::Utilities.get_vvv_path}",
394
+ "cd #{::ThemeJuice::Utilities.get_vvv_path}/database && touch init-custom.sql"
319
395
  ]
320
396
  end
321
397
 
398
+ ###
399
+ # Ensure project directory structure
400
+ #
401
+ # @return {Void}
402
+ ###
403
+ def setup_project_dir
404
+ say "Creating project directory tree in '#{@opts[:site_location]}'...", :yellow
405
+ run ["mkdir -p #{@opts[:site_location]}"]
406
+ end
407
+
322
408
  ###
323
409
  # Enable Landrush for wildcard subdomains
324
410
  #
@@ -329,7 +415,7 @@ module ThemeJuice
329
415
  ###
330
416
  def setup_wildcard_subdomains
331
417
  say "Setting up wildcard subdomains...", :yellow
332
- open File.expand_path("~/vagrant/Vagrantfile"), "a+" do |file|
418
+ open File.expand_path("#{::ThemeJuice::Utilities.get_vvv_path}/Vagrantfile"), "a+" do |file|
333
419
  file.puts "\n"
334
420
  file.puts "###"
335
421
  file.puts "# Enable wildcard subdomains"
@@ -352,11 +438,39 @@ module ThemeJuice
352
438
  def setup_dev_site
353
439
  say "Setting up new development site at '#{@opts[:dev_location]}'...", :yellow
354
440
  run [
355
- "cd ~/vagrant/www",
441
+ "cd #{::ThemeJuice::Utilities.get_vvv_path}/www",
356
442
  "mkdir tj-#{@opts[:site_name]}",
357
443
  ]
358
444
  end
359
445
 
446
+ ###
447
+ # Create tj-config.yml file for theme settings
448
+ #
449
+ # @param {String} config_path
450
+ #
451
+ # @return {Void}
452
+ ###
453
+ def setup_config(config_path)
454
+ watch = ask "Watch command to use :", :blue, default: "bundle exec guard"
455
+ server = ask "Deployment command to use :", :blue, default: "bundle exec cap"
456
+ vendor = ask "Vendor command to use :", :blue, default: "composer"
457
+ install = ask "Commands to run on theme install :", :blue, default: "composer install"
458
+
459
+ File.open "#{config_path}/tj-config.yml", "w" do |file|
460
+ file.puts "watch: #{watch}"
461
+ file.puts "server: #{server}"
462
+ file.puts "vendor: #{vendor}"
463
+ file.puts "install:"
464
+ file.puts "\s\s\s\s- #{install}"
465
+ end
466
+
467
+ if config_is_setup? config_path
468
+ say "Successfully added 'tj-config.yml' file.", :green
469
+ else
470
+ say "Could not create 'tj-config.yml' file.", :red
471
+ end
472
+ end
473
+
360
474
  ###
361
475
  # Create vvv-hosts file
362
476
  #
@@ -380,7 +494,7 @@ module ThemeJuice
380
494
  # @return {Void}
381
495
  ###
382
496
  def setup_database
383
- File.open File.expand_path("~/vagrant/database/init-custom.sql"), "a+" do |file|
497
+ File.open File.expand_path("#{::ThemeJuice::Utilities.get_vvv_path}/database/init-custom.sql"), "a+" do |file|
384
498
  file.puts "### Begin '#{@opts[:site_name]}'"
385
499
  file.puts "#"
386
500
  file.puts "# This block is automatically generated by ThemeJuice. Do not edit."
@@ -445,35 +559,31 @@ module ThemeJuice
445
559
  ###
446
560
  # Setup WordPress
447
561
  #
448
- # Clones starter theme into @opts[:site_location]
562
+ # Clones starter theme into site location
449
563
  #
450
564
  # @return {Void}
451
565
  ###
452
566
  def setup_wordpress
453
567
  say "Setting up WordPress...", :yellow
454
568
 
455
- if @opts[:bare_setup]
456
-
457
- # Create theme dir
458
- run [
459
- "mkdir -p #{@opts[:site_location]}",
460
- ]
461
-
462
- else
463
-
464
- # Clone starter theme
569
+ unless @opts[:bare_setup]
465
570
  run [
466
- "mkdir -p #{@opts[:site_location]}",
467
571
  "cd #{@opts[:site_location]}",
468
- "git clone --depth 1 https://github.com/#{@opts[:starter_theme]}.git .",
572
+ "git clone --depth 1 #{@opts[:starter_theme]} .",
469
573
  ]
574
+ end
575
+ end
470
576
 
471
- # Install composer dependencies
472
- run [
473
- "cd #{@opts[:site_location]}",
474
- "composer install",
475
- ], false
577
+ ###
578
+ # Install dependencies for starter theme
579
+ #
580
+ # @return {Void}
581
+ ###
582
+ def install_theme_dependencies
583
+ say "Installing theme dependencies...", :yellow
476
584
 
585
+ @config["install"].each do |command|
586
+ run ["cd #{@opts[:site_location]}", command], false
477
587
  end
478
588
  end
479
589
 
@@ -485,7 +595,7 @@ module ThemeJuice
485
595
  def setup_synced_folder
486
596
  say "Syncing host theme directory '#{@opts[:site_location]}' with VM theme directory '/srv/www/tj-#{@opts[:site_name]}'...", :yellow
487
597
 
488
- open File.expand_path("~/vagrant/Vagrantfile"), "a+" do |file|
598
+ open File.expand_path("#{::ThemeJuice::Utilities.get_vvv_path}/Vagrantfile"), "a+" do |file|
489
599
  file.puts "### Begin '#{@opts[:site_name]}'"
490
600
  file.puts "#"
491
601
  file.puts "# This block is automatically generated by ThemeJuice. Do not edit."
@@ -534,7 +644,7 @@ module ThemeJuice
534
644
  file.puts "\tvagrant:"
535
645
  file.puts "\t\turl: #{@opts[:dev_url]}"
536
646
  file.puts "\t\tpath: /srv/www/tj-#{@opts[:site_name]}"
537
- file.puts "\t\tcmd: cd ~/vagrant && vagrant ssh-config > /tmp/vagrant_ssh_config && ssh -q %pseudotty% -F /tmp/vagrant_ssh_config default %cmd%"
647
+ file.puts "\t\tcmd: cd #{::ThemeJuice::Utilities.get_vvv_path} && vagrant ssh-config > /tmp/vagrant_ssh_config && ssh -q %pseudotty% -F /tmp/vagrant_ssh_config default %cmd%"
538
648
  file.puts "\n"
539
649
  end
540
650
 
@@ -564,7 +674,7 @@ module ThemeJuice
564
674
  # @return {Void}
565
675
  ###
566
676
  def remove_database
567
- if remove_traces_from_file "~/vagrant/database/init-custom.sql"
677
+ if remove_traces_from_file "#{::ThemeJuice::Utilities.get_vvv_path}/database/init-custom.sql"
568
678
  say "Database for '#{@opts[:site_name]}' successfully removed.", :yellow
569
679
  end
570
680
  end
@@ -575,7 +685,7 @@ module ThemeJuice
575
685
  # @return {Void}
576
686
  ###
577
687
  def remove_synced_folder
578
- if remove_traces_from_file "~/vagrant/Vagrantfile"
688
+ if remove_traces_from_file "#{::ThemeJuice::Utilities.get_vvv_path}/Vagrantfile"
579
689
  say "Synced folders for '#{@opts[:site_name]}' successfully removed.", :yellow
580
690
  end
581
691
  end
@@ -0,0 +1,70 @@
1
+ module ThemeJuice
2
+ module Utilities
3
+ class << self
4
+ include ::Thor::Actions
5
+ include ::Thor::Shell
6
+
7
+ @@vvv_path ||= File.expand_path("~/vagrant")
8
+
9
+ ###
10
+ # Set path to VVV installation
11
+ #
12
+ # @param {String} path
13
+ #
14
+ # @return {String}
15
+ ###
16
+ def set_vvv_path(path)
17
+ @@vvv_path = File.expand_path(path)
18
+ end
19
+
20
+ ###
21
+ # Get path to VVV installation
22
+ #
23
+ # @return {String}
24
+ ###
25
+ def get_vvv_path
26
+
27
+ unless @@vvv_path
28
+ say "Cannot load VVV path. Aborting mission before something bad happens.", :red
29
+ exit 1
30
+ end
31
+
32
+ @@vvv_path
33
+ end
34
+
35
+ ###
36
+ # Check if program is installed
37
+ #
38
+ # @note Doesn't work on Win
39
+ #
40
+ # @param {String} program
41
+ #
42
+ # @return {Bool}
43
+ ###
44
+ def installed?(program)
45
+ system "which #{program} > /dev/null 2>&1"
46
+ end
47
+
48
+ ###
49
+ # Check if current version is outdated
50
+ #
51
+ # @return {Bool}
52
+ ###
53
+ def check_if_current_version_is_outdated
54
+ local_version = ::ThemeJuice::VERSION
55
+
56
+ fetcher = ::Gem::SpecFetcher.fetcher
57
+ dependency = ::Gem::Dependency.new "theme-juice", ">= #{local_version}"
58
+
59
+ remotes, = fetcher.search_for_dependency dependency
60
+ remote_version = remotes.map { |n, _| n.version }.sort.last
61
+
62
+ if ::Gem::Version.new(local_version) < ::Gem::Version.new(remote_version)
63
+ say "Warning: your version of theme-juice (#{local_version}) is outdated. There is a newer version (#{remote_version}) available. Please update now.", :yellow
64
+ else
65
+ say "Up to date.", :green
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -1,3 +1,3 @@
1
1
  module ThemeJuice
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: theme-juice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezekiel Gabrielse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-29 00:00:00.000000000 Z
11
+ date: 2015-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -50,7 +50,8 @@ files:
50
50
  - lib/theme-juice/ascii/logo.txt
51
51
  - lib/theme-juice/ascii/smiley.txt
52
52
  - lib/theme-juice/cli.rb
53
- - lib/theme-juice/scaffold.rb
53
+ - lib/theme-juice/executor.rb
54
+ - lib/theme-juice/utilities.rb
54
55
  - lib/theme-juice/version.rb
55
56
  - lib/theme-juice.rb
56
57
  - LICENSE
@@ -81,3 +82,4 @@ signing_key:
81
82
  specification_version: 4
82
83
  summary: A WordPress development framework.
83
84
  test_files: []
85
+ has_rdoc: