swiftly 4.0.1 → 5.0.1

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: 3a49b797b143b1083d3ba630b306558b632f8b5d
4
- data.tar.gz: 95443497949365f74775f08bb2135caf0a3cf0d9
3
+ metadata.gz: d783503de636e427ab81750c033953513ab53d95
4
+ data.tar.gz: 1d4b754bc088690b9513dbabf2253cd7a04b4c17
5
5
  SHA512:
6
- metadata.gz: e323166837244ed8817e5eff2d3c420068a4a3c2b034fabc81317ab0eb9d3a8f75444347a51b62f93e9bcd439ffb2e544dd13daff7741552e2c1a1524987a67a
7
- data.tar.gz: a1ebbc8a798cf15d560c43e399efd20735daacb672d4c4624032b8687db0e06808339580f56a6886100f12d3ab9c78b4423877481374b8cf5c0da2d4d4950d16
6
+ metadata.gz: 7c56d006554c3d79b436ce5bdc4a58da4a012b93f8d6ca1896c7c18b1a1092fc0fd6ad30a39660c92dbc0443f55c51192b100b181fbd14f01c7f02bde06bc335
7
+ data.tar.gz: 9dabc4f9bba3c91d6916dd712e4d17cfa82d5908a2ddd6af74c36f8f7b102242f892926ecaa7a6e540db731ed71f91b10a4e5396b861529a16cd95915a57131b
data/README.md ADDED
@@ -0,0 +1,196 @@
1
+ # Swiftly 5.0.1 (formally known as Obi)
2
+
3
+ Swiftly is a web development project management tool.
4
+
5
+ ## Features
6
+
7
+ 1. Create projects swiftly on the fly
8
+ 2. Deploy to multiple environments. Deployment is managed by [mina](https://github.com/mina-deploy/mina)
9
+ 3. Will also push database to server while performing a find and replace on URLs
10
+ 4. Backs up destination database on each push
11
+ 5. Allows for rollback of database and files in the event that it becomes necessary
12
+ 6. And much much more...
13
+
14
+ ## Getting started
15
+
16
+ $ gem install swiftly
17
+
18
+ Run it:
19
+
20
+ $ swiftly <command> <args>
21
+
22
+ ## Requirements
23
+
24
+ Mysql must be in your $PATH. You can check this by running:
25
+
26
+ $ which mysql
27
+
28
+ This should yield something like:
29
+
30
+ $ /opt/boxen/homebrew/bin/mysql
31
+
32
+ If nothing is displayed after running `which mysql` then you need to add it manually by running the following.
33
+
34
+ ***Note that everything between `PATH=` and `:$PATH` in the command below, needs to be the absolute path to your mysql.***
35
+
36
+ $ echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile && source ~/.bash_profile
37
+
38
+ If all goes correctly, you should be able to run `which mysql` again, and it should yield the location of your mysql.
39
+
40
+ ## Usage
41
+
42
+ Running `swiftly init` will walk you through setting up the basic settings necessary to get swiftly up and running.
43
+
44
+ $ swiftly init
45
+
46
+ At this point you will be able to run `swiftly help` to get a list of commands and their arguments in order to interact with swiftly.
47
+
48
+ $ swiftly help
49
+
50
+ Once you complete the interactive setup, a "Swiftlyfile" will be created in your sites directory. This file will contain your local settings and will look something like this:
51
+
52
+ ~~~ruby
53
+
54
+ set :server, :type => :local do
55
+
56
+ db_host 'localhost'
57
+ db_user 'root'
58
+ db_pass 'supersecurepassword'
59
+
60
+ end
61
+
62
+ ~~~
63
+
64
+ The "Swiftlyfile" is used as a global config for your different server settings.
65
+
66
+ Currently the only server types that are recognized by swiftly are `:local`, `:staging`, and `:production`. *Eventually swiftly will allow for user specified server types!*
67
+
68
+ The `:staging` and `:production` server type settings can be overridden locally by adding a `config/config.rb` file in the root directory of an individual project. These server types except more parameters than just `db_host`, `db_user`, and `db_name` which are required in order to manage each project. Below is an example of a `config/config.rb` file using all possible parameters.
69
+
70
+ ~~~ruby
71
+
72
+ set :server, :type => :staging do
73
+
74
+ db_host 'localhost'
75
+ db_user 'root'
76
+ db_pass 'supersecurepassword'
77
+ repo 'git@bitbucket.org:micalexander/micalexander.git'
78
+ branch 'master'
79
+ ssh_path '/var/www/micalexander_micalexander_com'
80
+ ssh_user 'username'
81
+ domain 'http://micalexander.micalexander.com'
82
+
83
+ end
84
+
85
+ set :server, :type => :production do
86
+
87
+ db_host 'localhost'
88
+ db_user 'root'
89
+ db_pass 'supersecurepassword'
90
+ repo 'git@bitbucket.org:micalexander/micalexander.git'
91
+ branch 'master'
92
+ ssh_path '/var/www/micalexander_com'
93
+ ssh_user 'username'
94
+ domain 'micalexander.com'
95
+
96
+ end
97
+
98
+ ~~~
99
+
100
+ ## Projects
101
+
102
+ Swiftly currently supports three types of projects, an `empty`, a `git` enabled, and a `wordpress` (git enabled) project.
103
+
104
+ Example folder structure:
105
+
106
+ ~~~ruby
107
+
108
+ project-name
109
+ |
110
+ |-- _resources // Not required. Opinionated organization
111
+ | |
112
+ | |-- assets
113
+ | |
114
+ | |-- architecture
115
+ | |-- doc
116
+ | |-- emails
117
+ | |-- fonts
118
+ | |-- images
119
+ | |-- raster
120
+ | |-- vector
121
+ |
122
+ |-- _backups // Required for automated backups of environments
123
+ | |
124
+ | |-- local
125
+ | |-- production
126
+ | |-- staging
127
+ | |-- temp
128
+ |
129
+ |-- .git // Not required but a good idea
130
+ | |
131
+ | |-- ...
132
+ |
133
+ |-- .gitignore // Not required but a good
134
+ |
135
+ |-- config // Required for project specific settings
136
+ |
137
+ |-- config.rb // Required for project specific settings
138
+ ~~~
139
+
140
+ The above gives you an idea of what to expect when creating a project.
141
+
142
+ To create a project you can simply run:
143
+
144
+ $ swiftly create [project_type] [project_name]
145
+
146
+ An `empty` project will include the structure in the diagram above with the exception of the .git directory, the .gitignore.
147
+
148
+ A `git` project will include everything in the diagram above.
149
+
150
+ A `wordpress` project will include everything in the diagram above with the addition of a full Wordpress installation.
151
+
152
+ ## Wordpress
153
+
154
+ To install Wordpress as a project run the following command replacing "[project_name]" with your desired project name.
155
+
156
+ $ swiftly create wordpress [project_name]
157
+
158
+ This will download Wordpress into a folder named "[project_name]", setup the Wordpress database for you, and automatically install a theme for you named "[project_name]".
159
+
160
+ By default the theme that will be installed into Wordpress will be [mask](https://github.com/micalexander/mask). This is because swiftly requires a customized "wp-config.php" file in order to setup the databases and manage the push and pulling of environments.
161
+
162
+ When using the customized "wp-config.php" file you will not need to include the `db_host`, `db_user`, `db_name` and `domain` parameters in the `config/config.rb` file. Doing so will override the "wp-config.php" file settings.
163
+
164
+ ### Themes
165
+
166
+ You can tell swiftly what theme to use by following the syntax below. Keep in mind that your theme structure must match that of the [mask](https://github.com/micalexander/mask) theme in order for things to run smoothly.
167
+
168
+ The location parameter accepts a URL to a zip or a file path to a folder.
169
+
170
+ ***Note the status parameter is set to `:disabled`, therefore it will be ignored and not installed. In order to have swiftly install this theme, remove the status altogether or set it to `:enabled`.***
171
+
172
+ ~~~ruby
173
+ set :package, :type => :template do
174
+ name 'mask'
175
+ location 'https://github.com/micalexander/mask/archive/master.zip'
176
+ status :disabled
177
+ end
178
+ ~~~
179
+
180
+ ### Plugins
181
+
182
+ You can tell swiftly what plugin to use by following the syntax below.
183
+
184
+ The location parameter accepts a URL to a zip or a file path to a folder.
185
+
186
+ ***Note the status parameter is set to `:disabled`, therefore it will be ignored and not installed. In order to have swiftly install this plugin, remove the status altogether or set it to `:enabled`.***
187
+
188
+ ~~~ruby
189
+ set :package, :type => :plugin do
190
+ name 'advanced-custom-fields-pro'
191
+ location '/Users/username/plugins'
192
+ status :disabled
193
+ end
194
+ ~~~
195
+
196
+ *More examples coming...*
data/bin/swiftly CHANGED
@@ -12,4 +12,5 @@ Swiftly::Init.start unless File.exist? File.join( Dir.home, ".swiftly" )
12
12
  global_config = YAML.load_file File.join( Dir.home, ".swiftly" ) unless !File.exists? File.join( Dir.home, ".swiftly" )
13
13
 
14
14
  Swiftly::Init.start unless File.exist? File.join( global_config[:sites_path], "Swiftlyfile" )
15
+
15
16
  Swiftly::CLI.start unless !File.exist? File.join( global_config[:sites_path], "Swiftlyfile" )
data/lib/swiftly/cli.rb CHANGED
@@ -3,15 +3,12 @@ require 'json'
3
3
  require 'swiftly/app_module'
4
4
  require 'swiftly/config'
5
5
  require 'swiftly/create'
6
- require 'swiftly/configure'
7
6
  require 'swiftly/push'
8
7
  require 'swiftly/pull'
9
8
  require 'swiftly/ssh'
10
9
  require 'swiftly/clean'
11
10
  require 'swiftly/setup'
12
11
  require 'swiftly/rollback'
13
- require 'swiftly/generate'
14
- require 'swiftly/enable'
15
12
  require 'swiftly/destroy'
16
13
 
17
14
  module Swiftly
@@ -21,15 +18,12 @@ module Swiftly
21
18
  include Helpers
22
19
 
23
20
  register Swiftly::Create, "create", "create COMMAND PROJECT_NAME", "Create projects by passing a project name"
24
- register Swiftly::Configure, "configure", "configure COMMAND", "Configure settings"
25
21
  register Swiftly::Setup, "setup", "setup COMMAND PROJECT_NAME", "Setup [environment] on server"
26
22
  register Swiftly::Push, "push", "push COMMAND PROJECT_NAME", "Push [environment] database and files to server"
27
23
  register Swiftly::Pull, "pull", "pull COMMAND PROJECT_NAME", "Pull [environment] database and files to local"
28
24
  register Swiftly::Rollback, "rollback", "rollback COMMAND PROJECT_NAME", "Rollback the [environment] database and files on server"
29
25
  register Swiftly::SSH, "ssh", "ssh COMMAND PROJECT_NAME", "SSH into the [environment] server and cd into site path"
30
26
  register Swiftly::Clean, "clean", "clean COMMAND PROJECT_NAME", "Clean the [environment] releases on server"
31
- register Swiftly::Generate, "generate", "generate POSTTYPE FILTER PROJECT_NAME", "Generate a custom post type"
32
- register Swiftly::Enable, "enable", "enable COMMAND FRAMEWORK", "Enable global framework intergrations"
33
27
  register Swiftly::Destroy, "destroy", "destroy PROJECT_NAME", "Destroy local project!"
34
28
 
35
29
  end
@@ -1,6 +1,8 @@
1
1
  require 'yaml'
2
2
  require 'swiftly/version'
3
3
  require 'swiftly/app_module'
4
+ require 'swiftly/smokestack'
5
+ require 'swiftly/resolver'
4
6
 
5
7
  module Swiftly
6
8
  class Config < Thor
@@ -41,10 +43,10 @@ module Swiftly
41
43
 
42
44
  File.join(
43
45
  global_config[:sites_path],
44
- project_name, 'config', 'config.yml'
46
+ project_name, 'config', 'config.rb'
45
47
  ) unless !File.exists? File.join(
46
48
  global_config[:sites_path],
47
- project_name, 'config', 'config.yml'
49
+ project_name, 'config', 'config.rb'
48
50
  )
49
51
 
50
52
  end
@@ -65,67 +67,150 @@ module Swiftly
65
67
 
66
68
  end
67
69
 
68
- def self.load file, project_name = nil
70
+ def self.set setting, *args, &block
69
71
 
70
- case file
71
- when :wp_config
72
+ Swiftly::Smokestack.define do
72
73
 
73
- if wp_config_file( project_name )
74
+ factory setting, &block
74
75
 
75
- # load the wp-config file environment settings for wp-enabled environments
76
- wp_local = File.read(
77
- wp_config_file(
78
- project_name
79
- )
80
- )[/\$local\s*?=[\s|\S]*?({[\s|\S]*?})/, 1]
76
+ end
81
77
 
82
- wp_staging = File.read(
83
- wp_config_file(
84
- project_name
85
- )
86
- )[/\$staging\s*?=[\s|\S]*?({[\s|\S]*?})/, 1]
78
+ Swiftly::Resolver.load setting, args[0][:type], Swiftly::Smokestack.build( setting )
87
79
 
88
- wp_production = File.read(
89
- wp_config_file(
90
- project_name
91
- )
92
- )[/\$production\s*?=[\s|\S]*?({[\s|\S]*?})/, 1]
80
+ end
93
81
 
94
- if wp_local.nil? || wp_staging.nil? || wp_production.nil?
82
+ def self.load file, project_name = nil
95
83
 
96
- return {
97
- local: {},
98
- staging: {},
99
- production: {}
100
- }
84
+ case file
85
+ when :wp_config
101
86
 
102
- end
87
+ wp_config_parse project_name
103
88
 
104
- load_hash = {
105
- local: JSON.parse(wp_local).inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo},
106
- staging: JSON.parse(wp_staging).inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo},
107
- production: JSON.parse(wp_production).inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
108
- }
109
89
 
110
- end
90
+ Resolver.get( :server )
111
91
 
112
92
  when :project
113
93
 
114
- load_hash = YAML.load_file( project_file( project_name ) )
94
+ if !eval( IO.read( project_file( project_name ) ) ).nil?
95
+
96
+ load_hash = Resolver.get :server == {} ? false : Resolver.get( :package )
97
+
98
+ end
115
99
 
116
100
  when :swiftly
117
101
 
118
- load_hash = YAML.load_file( swiftlyfile )
102
+ if !eval( IO.read( swiftlyfile ) ).nil?
103
+
104
+ load_hash = Resolver.get :server
105
+
106
+ end
119
107
 
120
108
  when :global
121
109
 
122
110
  load_hash = YAML.load_file( global_file )
123
111
 
112
+ when :all
113
+
114
+ eval( IO.read( swiftlyfile ) ) unless eval( IO.read( swiftlyfile ) ).nil?
115
+
116
+
117
+ wp_config_parse project_name
118
+
119
+
120
+ eval( IO.read( project_file( project_name ) ) ) unless eval( IO.read( project_file( project_name ) ) ).nil?
121
+
122
+
123
+
124
+ load_hash = Resolver.get :server
125
+
124
126
  end
125
127
 
128
+
126
129
  load_hash
127
130
 
128
131
  end
132
+
133
+ def self.wp_config_parse project_name
134
+
135
+ if wp_config_file( project_name )
136
+
137
+ # load the wp-config file environment settings for wp-enabled environments
138
+ wp_local = File.read(
139
+ wp_config_file(
140
+ project_name
141
+ )
142
+ )[/\$local\s*?=[\s|\S]*?({[\s|\S]*?})/, 1]
143
+
144
+ wp_staging = File.read(
145
+ wp_config_file(
146
+ project_name
147
+ )
148
+ )[/\$staging\s*?=[\s|\S]*?({[\s|\S]*?})/, 1]
149
+
150
+ wp_production = File.read(
151
+ wp_config_file(
152
+ project_name
153
+ )
154
+ )[/\$production\s*?=[\s|\S]*?({[\s|\S]*?})/, 1]
155
+
156
+ if wp_local.nil? || wp_staging.nil? || wp_production.nil?
157
+
158
+ return {
159
+ local: {},
160
+ staging: {},
161
+ production: {}
162
+ }
163
+
164
+ end
165
+
166
+ hash = {
167
+ local: JSON.parse(wp_local).inject({}){|memo,(k,v)| memo[k] = v; memo},
168
+ staging: JSON.parse(wp_staging).inject({}){|memo,(k,v)| memo[k] = v; memo},
169
+ production: JSON.parse(wp_production).inject({}){|memo,(k,v)| memo[k] = v; memo}
170
+ }
171
+
172
+ hash.each do |k, v|
173
+
174
+ set :server, :type => k do
175
+
176
+ v.each do |setting, value|
177
+
178
+ if setting != 'wp_home'
179
+
180
+ case setting
181
+ when 'domain'
182
+ domain value
183
+
184
+ when 'repo'
185
+ repo value
186
+
187
+ when 'branch'
188
+ branch value
189
+
190
+ when 'ssh_path'
191
+ ssh_path value
192
+
193
+ when 'ssh_user'
194
+ ssh_user value
195
+
196
+ when 'db_name'
197
+ db_name value
198
+
199
+ when 'db_host'
200
+ db_host value
201
+
202
+ when 'db_user'
203
+ db_user value
204
+
205
+ when 'db_pass'
206
+ db_pass value
207
+ end
208
+ end
209
+ end
210
+ end
211
+ end
212
+ end
213
+ end
129
214
  end
130
215
  end
131
216
  end
@@ -23,7 +23,7 @@ module Swiftly
23
23
  File.join(
24
24
  project_path,
25
25
  'config',
26
- 'config.yml'
26
+ 'config.rb'
27
27
  )
28
28
  )
29
29
 
@@ -59,7 +59,7 @@ module Swiftly
59
59
  global_settings = Swiftly::Config.load :global
60
60
  project_settings = Swiftly::Config.load :swiftly
61
61
 
62
- template = Swiftly::Packages.load({
62
+ template = Swiftly::Package.load({
63
63
  framework: :wordpress,
64
64
  type: :template,
65
65
  name: options[:template]
@@ -78,7 +78,6 @@ module Swiftly
78
78
  CreateWordpress.new([
79
79
  project_name,
80
80
  template,
81
- project_settings,
82
81
  project_path
83
82
  ]).invoke_all
84
83
 
@@ -14,7 +14,7 @@ module Swiftly
14
14
 
15
15
  argument :project_name
16
16
  argument :template
17
- argument :settings
17
+ # argument :settings
18
18
  argument :project_path
19
19
 
20
20
  desc "Handles the creation of a wordpress project."
@@ -121,7 +121,7 @@ module Swiftly
121
121
 
122
122
  inside File.join( "wp-content", "plugins" ) do
123
123
 
124
- plugins = Swiftly::Packages.load_plugins :wordpress
124
+ plugins = Swiftly::Package.load_plugins :wordpress
125
125
 
126
126
  if plugins
127
127
 
@@ -153,17 +153,20 @@ module Swiftly
153
153
  gsub_file 'wp-config.php', /\/\/\s*Insert_Salts_Below/, Net::HTTP.get('api.wordpress.org', '/secret-key/1.1/salt')
154
154
  gsub_file 'wp-config.php', /(table_prefix\s*=\s*')(wp_')/, '\1' + @project_name[0,3] + "_'"
155
155
 
156
- if !@settings[:local][:db_host].nil? &&
157
- !@settings[:local][:db_user].nil? &&
158
- !@settings[:local][:db_pass].nil?
156
+ settings = Swiftly::Config.load :swiftly
157
+
158
+ if !settings.nil? &&
159
+ !settings[:local][:db_host].nil? &&
160
+ !settings[:local][:db_user].nil? &&
161
+ !settings[:local][:db_pass].nil?
159
162
 
160
163
  gsub_file 'wp-config.php', /(\$local\s*?=[\s|\S]*?)({[\s|\S]*?})/ do |match|
161
164
 
162
165
  '$local = \'{
163
166
  "db_name": "' + @project_name + '_local_wp",
164
- "db_host": "' + @settings[:local][:db_host] + '",
165
- "db_user": "' + @settings[:local][:db_user] + '",
166
- "db_pass": "' + @settings[:local][:db_pass] + '",
167
+ "db_host": "' + settings[:local][:db_host] + '",
168
+ "db_user": "' + settings[:local][:db_user] + '",
169
+ "db_pass": "' + settings[:local][:db_pass] + '",
167
170
  "domain": "http://' + @project_name + '.dev",
168
171
  "wp_home": "http://' + @project_name + '.dev"
169
172
  }'
@@ -170,7 +170,7 @@ module Swiftly
170
170
  -h'#{@settings[environment][:db_host]}' \
171
171
  -p'#{@settings[environment][:db_pass]}' \
172
172
  -Bse"CREATE DATABASE IF NOT EXISTS \
173
- #{@settings[environment][:db_name]}"
173
+ #{@settings[environment][:db_name].gsub(/\-|\./, '_')}"
174
174
  EOF
175
175
 
176
176
  swiftly_shell cmd
@@ -0,0 +1,17 @@
1
+ require "swiftly/smokestack"
2
+ require "swiftly/factory"
3
+
4
+ module Swiftly
5
+ class DefinitionProxy
6
+
7
+ def factory(factory_class, &block)
8
+
9
+ factory = Swiftly::Factory.new
10
+
11
+ factory.instance_eval(&block)
12
+
13
+ Smokestack.registry[Swiftly.const_get(factory_class.capitalize)] = factory
14
+
15
+ end
16
+ end
17
+ end
@@ -12,6 +12,7 @@ module Swiftly
12
12
  def destroy( project_name )
13
13
 
14
14
  settings = Swiftly::Project.settings project_name
15
+
15
16
  directory = File.join( settings[:project][:path], '' )
16
17
  zipfile_name = settings[:project][:path] + '.zip'
17
18
 
@@ -0,0 +1,20 @@
1
+ require "swiftly/server"
2
+
3
+ module Swiftly
4
+ class Factory < BasicObject
5
+
6
+ def initialize
7
+
8
+ @attributes = {}
9
+
10
+ end
11
+
12
+ attr_reader :attributes
13
+
14
+ def method_missing(name, *args, &block)
15
+
16
+ @attributes[name] = args[0]
17
+
18
+ end
19
+ end
20
+ end
data/lib/swiftly/init.rb CHANGED
@@ -16,7 +16,7 @@ module Swiftly
16
16
 
17
17
  say # spacer
18
18
 
19
- say "\t\t#{APP_NAME} #{VERSION} Development Manager\n\n", :blue
19
+ say "\t\t#{APP_NAME} #{VERSION} Web Development Project Manager\n\n", :blue
20
20
 
21
21
  say_status "#{APP_NAME}:", "Thanks for trying out #{APP_NAME}. Lets get started!", :green
22
22
 
@@ -1,15 +1,21 @@
1
1
  require "swiftly/config"
2
2
  require "swiftly/app_module"
3
3
  require "yaml"
4
+ require "swiftly/factory"
4
5
 
5
6
  module Swiftly
6
- class Packages < Thor
7
+ class Package < Thor
7
8
 
8
9
  include Thor::Actions
9
10
  include Helpers
10
11
 
11
12
  no_commands do
12
13
 
14
+ attr_accessor :framework
15
+ attr_accessor :type
16
+ attr_accessor :name
17
+ attr_accessor :location
18
+
13
19
  def self.file
14
20
 
15
21
  @settings = Swiftly::Config.load :global
@@ -41,7 +47,21 @@ module Swiftly
41
47
 
42
48
  def self.available
43
49
 
44
- YAML.load_file self.file
50
+ eval( IO.read( self.file ) )
51
+
52
+ load_hash = Resolver.get( :package ) == {} ? false : Resolver.get( :package )
53
+
54
+ end
55
+
56
+ def self.set setting, *args, &block
57
+
58
+ Swiftly::Smokestack.define do
59
+
60
+ factory setting, &block
61
+
62
+ end
63
+
64
+ Swiftly::Resolver.load setting, args[0][:type], Swiftly::Smokestack.build( setting )
45
65
 
46
66
  end
47
67
 
@@ -10,69 +10,40 @@ module Swiftly
10
10
 
11
11
  no_commands do
12
12
 
13
- def self.settings( project_name )
13
+ def self.set setting, *args, &block
14
14
 
15
- project_name = self.get_project project_name
16
- global_config = Swiftly::Config.load :global
17
- swiftly_config = Swiftly::Config.load :swiftly
18
- project_config = Swiftly::Config.load :project, project_name
19
- wp_config = Swiftly::Config.load :wp_config, project_name
15
+ Swiftly::Smokestack.define do
20
16
 
21
- global_config = {
22
- version: VERSION,
23
- sites_path: global_config[:sites_path],
24
- }
17
+ factory setting, &block
25
18
 
26
- switly_config = {
27
- staging: {
28
- domain: defined?(project_config[:staging][:domain]) ? project_config[:staging][:domain] : global_config[:staging][:domain],
29
- db_host: defined?(project_config[:staging][:db_host]) ? project_config[:staging][:db_host] : global_config[:staging][:db_host],
30
- db_user: defined?(project_config[:staging][:db_user]) ? project_config[:staging][:db_user] : global_config[:staging][:db_user],
31
- db_pass: defined?(project_config[:staging][:db_pass]) ? project_config[:staging][:db_pass] : global_config[:staging][:db_pass],
32
- },
33
- production: {
34
- domain: defined?(project_config[:production][:domain]) ? project_config[:production][:domain] : global_config[:production][:domain],
35
- db_host: defined?(project_config[:production][:db_host]) ? project_config[:production][:db_host] : global_config[:production][:db_host],
36
- db_user: defined?(project_config[:production][:db_user]) ? project_config[:production][:db_user] : global_config[:production][:db_user],
37
- db_pass: defined?(project_config[:production][:db_pass]) ? project_config[:production][:db_pass] : global_config[:production][:db_pass],
38
- }
39
- }.merge! local: global_config[:local]
40
-
41
- settings = {
42
- project: {
43
- name: project_name,
44
- path: File.join( global_config[:sites_path], project_name ),
45
- dump: File.join( global_config[:sites_path], project_name, '_backups', 'dumps' )
46
- },
47
- local: {
48
- domain: defined?(wp_config[:local][:domain]) ? wp_config[:local][:domain] : project_config[:local][:domain],
49
- db_name: defined?(wp_config[:local][:db_name]) ? wp_config[:local][:db_name] : project_config[:local][:db_name],
50
- db_host: defined?(wp_config[:local][:db_host]) ? wp_config[:local][:db_host] : switly_config[:local][:db_host],
51
- db_user: defined?(wp_config[:local][:db_user]) ? wp_config[:local][:db_user] : switly_config[:local][:db_user],
52
- db_pass: defined?(wp_config[:local][:db_pass]) ? wp_config[:local][:db_pass] : switly_config[:local][:db_pass],
53
- },
54
- staging: {
55
- db_name: defined?(wp_config[:staging][:db_name]) ? wp_config[:staging][:db_name] : project_config[:staging][:db_name],
56
- db_host: defined?(wp_config[:staging][:db_host]) ? wp_config[:staging][:db_host] : switly_config[:staging][:db_host],
57
- db_user: defined?(wp_config[:staging][:db_user]) ? wp_config[:staging][:db_user] : switly_config[:staging][:db_user],
58
- db_pass: defined?(wp_config[:staging][:db_pass]) ? wp_config[:staging][:db_pass] : switly_config[:staging][:db_pass],
59
- domain: defined?(switly_config[:staging][:domain]) ? switly_config[:staging][:domain] : wp_config[:staging][:domain],
60
- repo: project_config[:staging][:repo],
61
- branch: project_config[:staging][:branch],
62
- ssh_path: project_config[:staging][:ssh_path],
63
- ssh_user: project_config[:staging][:ssh_user],
64
- },
65
- production: {
66
- db_name: defined?(wp_config[:production][:db_name]) ? wp_config[:production][:db_name] : project_config[:production][:db_name],
67
- db_host: defined?(wp_config[:production][:db_host]) ? wp_config[:production][:db_host] : switly_config[:production][:db_host],
68
- db_user: defined?(wp_config[:production][:db_user]) ? wp_config[:production][:db_user] : switly_config[:production][:db_user],
69
- db_pass: defined?(wp_config[:production][:db_pass]) ? wp_config[:production][:db_pass] : switly_config[:production][:db_pass],
70
- domain: defined?(switly_config[:production][:domain]) ? switly_config[:production][:domain] : wp_config[:production][:domain],
71
- repo: project_config[:production][:repo],
72
- branch: project_config[:production][:branch],
73
- ssh_path: project_config[:production][:ssh_path],
74
- ssh_user: project_config[:production][:ssh_user],
75
- }
19
+ end
20
+
21
+ Swiftly::Resolver.load setting, args[0][:type], Swiftly::Smokestack.build( setting )
22
+
23
+ end
24
+
25
+ def self.settings project_name = nil
26
+
27
+ project_name = self.get_project project_name
28
+ global_config = Swiftly::Config.load :global
29
+ swiftlyfile = Swiftly::Config.swiftlyfile
30
+ project_file = Swiftly::Config.project_file project_name
31
+ wp_config = Swiftly::Config.wp_config_file project_name
32
+
33
+ eval( IO.read( swiftlyfile ) ) unless eval( IO.read( swiftlyfile ) ).nil?
34
+
35
+ wp_config_parse wp_config
36
+
37
+ eval( IO.read( project_file ) ) unless eval( IO.read( project_file ) ).nil?
38
+
39
+ settings = Resolver.get :server
40
+
41
+ settings[:global] = global_config
42
+
43
+ settings[:project] = {
44
+ name: project_name,
45
+ path: File.join( global_config[:sites_path], project_name ),
46
+ dump: File.join( global_config[:sites_path], project_name, '_backups', 'dumps' )
76
47
  }
77
48
 
78
49
  if defined?( settings[:staging][:ssh_user] ) &&
@@ -97,6 +68,76 @@ module Swiftly
97
68
 
98
69
  end
99
70
 
71
+ def self.wp_config_parse file
72
+
73
+ if file
74
+
75
+ # load the wp-config file environment settings for wp-enabled environments
76
+ wp_local = File.read( file )[/\$local\s*?=[\s|\S]*?({[\s|\S]*?})/, 1]
77
+
78
+ wp_staging = File.read( file )[/\$staging\s*?=[\s|\S]*?({[\s|\S]*?})/, 1]
79
+
80
+ wp_production = File.read( file )[/\$production\s*?=[\s|\S]*?({[\s|\S]*?})/, 1]
81
+
82
+ if wp_local.nil? || wp_staging.nil? || wp_production.nil?
83
+
84
+ return {
85
+ local: {},
86
+ staging: {},
87
+ production: {}
88
+ }
89
+
90
+ end
91
+
92
+ hash = {
93
+ local: JSON.parse(wp_local).inject({}){|memo,(k,v)| memo[k] = v; memo},
94
+ staging: JSON.parse(wp_staging).inject({}){|memo,(k,v)| memo[k] = v; memo},
95
+ production: JSON.parse(wp_production).inject({}){|memo,(k,v)| memo[k] = v; memo}
96
+ }
97
+
98
+ hash.each do |k, v|
99
+
100
+ set :server, :type => k do
101
+
102
+ v.each do |setting, value|
103
+
104
+ if setting != 'wp_home'
105
+
106
+ case setting
107
+ when 'domain'
108
+ domain value
109
+
110
+ when 'repo'
111
+ repo value
112
+
113
+ when 'branch'
114
+ branch value
115
+
116
+ when 'ssh_path'
117
+ ssh_path value
118
+
119
+ when 'ssh_user'
120
+ ssh_user value
121
+
122
+ when 'db_name'
123
+ db_name value
124
+
125
+ when 'db_host'
126
+ db_host value
127
+
128
+ when 'db_user'
129
+ db_user value
130
+
131
+ when 'db_pass'
132
+ db_pass value
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
140
+
100
141
  def self.get_project( project_name )
101
142
 
102
143
  pathname = Pathname.new project_name
@@ -110,7 +151,7 @@ module Swiftly
110
151
  thor.say_status( "#{APP_NAME}:", "#{project_path} is not a project.\n", :yellow ) &&
111
152
  abort unless File.directory?( project_path )
112
153
 
113
- pathname.expand_path.basename
154
+ pathname.expand_path.basename.to_s
114
155
 
115
156
  end
116
157
 
@@ -0,0 +1,72 @@
1
+ module Swiftly
2
+ class Resolver
3
+
4
+ @@settings = {
5
+ server: [],
6
+ package: []
7
+ }
8
+
9
+ def self.load setting, type, attributes
10
+
11
+ @@settings[setting] << { type => attributes }
12
+
13
+ end
14
+
15
+ def self.get setting
16
+
17
+ override = {}
18
+ final = {}
19
+
20
+ if !@@settings[setting].nil?
21
+
22
+ @@settings[setting].each do |s|
23
+
24
+ s.each do |k, v|
25
+
26
+ override[k] = []
27
+
28
+ end
29
+ end
30
+
31
+ @@settings[setting].each do |s|
32
+
33
+ s.each do |k, v|
34
+
35
+ override[k] << v
36
+
37
+ end
38
+ end
39
+
40
+ override.each do |k, v|
41
+
42
+ construct = {}
43
+ capture = {}
44
+
45
+ override[k].each do |o|
46
+
47
+ final.merge!( {k => {} } )
48
+
49
+ available_methods = o.methods - Object.methods
50
+
51
+ available_methods.each_with_index do |n, e|
52
+
53
+ unless (n.to_s.end_with?("="))
54
+
55
+ construct[n] = o.send(n) unless o.send(n).nil?
56
+
57
+ end
58
+
59
+ end
60
+
61
+ final[k] = capture.merge!( construct )
62
+
63
+ end
64
+ end
65
+ end
66
+
67
+ final
68
+
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,17 @@
1
+ require "swiftly/factory"
2
+
3
+ module Swiftly
4
+ class Server
5
+
6
+ attr_accessor :domain
7
+ attr_accessor :repo
8
+ attr_accessor :branch
9
+ attr_accessor :ssh_path
10
+ attr_accessor :ssh_user
11
+ attr_accessor :db_name
12
+ attr_accessor :db_host
13
+ attr_accessor :db_user
14
+ attr_accessor :db_pass
15
+
16
+ end
17
+ end
@@ -0,0 +1,37 @@
1
+ require 'swiftly/definition_proxy'
2
+
3
+ module Swiftly
4
+ module Smokestack
5
+
6
+ @registry = {}
7
+
8
+ def self.registry
9
+
10
+ @registry
11
+
12
+ end
13
+
14
+ def self.define(&block)
15
+
16
+ definition_proxy = Swiftly::DefinitionProxy.new
17
+ definition_proxy.instance_eval(&block)
18
+
19
+ end
20
+
21
+ def self.build(factory_class, overrides = {})
22
+
23
+ instance = Swiftly.const_get(factory_class.capitalize).new
24
+ factory = registry[Swiftly.const_get(factory_class.capitalize)]
25
+ attributes = factory.attributes.merge(overrides)
26
+
27
+ attributes.each do |attribute_name, value|
28
+
29
+ instance.send("#{attribute_name}=", value)
30
+
31
+ end
32
+
33
+ instance
34
+
35
+ end
36
+ end
37
+ end
@@ -1,11 +1,17 @@
1
- ---
2
- :staging:
3
- :repo:
4
- :branch:
5
- :ssh_path:
6
- :ssh_user:
7
- :production:
8
- :repo:
9
- :branch:
10
- :ssh_path:
11
- :ssh_user:
1
+ # set :server, :type => :staging do
2
+
3
+ # repo
4
+ # branch
5
+ # ssh_path
6
+ # ssh_user
7
+
8
+ # end
9
+
10
+ # set :server, :type => :production do
11
+
12
+ # repo
13
+ # branch
14
+ # ssh_path
15
+ # ssh_user
16
+
17
+ # end
@@ -1,21 +1,23 @@
1
- ---
2
- :local:
3
- :db_host: "<%= @db_host %>"
4
- :db_user: "<%= @db_user %>"
5
- :db_pass: "<%= @db_pass %>"
6
- :staging:
7
- :domain:
8
- :db_host:
9
- :production:
10
- :domain:
11
- :db_host:
12
- :packages:
13
- :wordpress:
14
- :template:
15
- - :name: mask
16
- :location: https://github.com/micalexander/mask/archive/master.zip
17
- :status: :disabled
18
- :plugins:
19
- - :name: advanced-custom-fields-pro
20
- :location: "/Users/username/plugins"
21
- :status: :disabled
1
+ set :server, :type => :local do
2
+
3
+ db_host '<%= @db_host %>'
4
+ db_user '<%= @db_user %>'
5
+ db_pass '<%= @db_pass %>'
6
+
7
+ end
8
+
9
+ # set :package, :type => :template do
10
+
11
+ # name 'mask'
12
+ # location 'https://github.com/micalexander/mask/archive/master.zip'
13
+ # status :disabled
14
+
15
+ # end
16
+
17
+ # set :package, :type => :plugin do
18
+
19
+ # name 'advanced-custom-fields-pro'
20
+ # location '/Users/username/plugins'
21
+ # status :disabled
22
+
23
+ # end
@@ -1,4 +1,4 @@
1
1
  module Swiftly
2
2
  APP_NAME = 'swiftly'
3
- VERSION = '4.0.1'
3
+ VERSION = '5.0.1'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swiftly
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mic Alexander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-23 00:00:00.000000000 Z
11
+ date: 2015-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -105,8 +105,8 @@ extra_rdoc_files: []
105
105
  files:
106
106
  - ".DS_Store"
107
107
  - ".gitignore"
108
- - Dropbox/Development/www/Swiftlyfile
109
108
  - Gemfile
109
+ - README.md
110
110
  - bin/swiftly
111
111
  - lib/swiftly/Rakefile
112
112
  - lib/swiftly/app_module.rb
@@ -121,16 +121,19 @@ files:
121
121
  - lib/swiftly/create_project.rb
122
122
  - lib/swiftly/create_wordpress.rb
123
123
  - lib/swiftly/database.rb
124
+ - lib/swiftly/definition_proxy.rb
124
125
  - lib/swiftly/destroy.rb
125
- - lib/swiftly/generate.rb
126
- - lib/swiftly/generate_post_type.rb
126
+ - lib/swiftly/factory.rb
127
127
  - lib/swiftly/init.rb
128
128
  - lib/swiftly/packages.rb
129
129
  - lib/swiftly/project.rb
130
130
  - lib/swiftly/pull.rb
131
131
  - lib/swiftly/push.rb
132
+ - lib/swiftly/resolver.rb
132
133
  - lib/swiftly/rollback.rb
134
+ - lib/swiftly/server.rb
133
135
  - lib/swiftly/setup.rb
136
+ - lib/swiftly/smokestack.rb
134
137
  - lib/swiftly/ssh.rb
135
138
  - lib/swiftly/templates/config_global.erb
136
139
  - lib/swiftly/templates/config_project.erb
@@ -1,8 +0,0 @@
1
- # :wordpress:
2
- # :template:
3
- # - :name:
4
- # :remote: https://github.com/micalexander/mask/archive/master.zip
5
- # :status: :disabled
6
- # :plugins:
7
- # - advanced-custom-fields-pro/acf.php
8
- # - ambrosite-body-class-enhanced/ambrosite-body-class.php
@@ -1,23 +0,0 @@
1
- require 'swiftly/generate_post_type'
2
- require 'swiftly/app_module'
3
-
4
- module Swiftly
5
- class Generate < Thor
6
-
7
- include Helpers
8
-
9
- desc "cpt [option] PROJECT_NAME", "Creates Custom Post Type file"
10
-
11
- def cpt(post_type_name, post_type_filter, project_name)
12
-
13
- settings = Swiftly::Project.settings( project_name )
14
-
15
- GeneratePostType.new([
16
- post_type_name,
17
- post_type_filter,
18
- settings[:project]
19
- ]).invoke_all
20
-
21
- end
22
- end
23
- end
@@ -1,50 +0,0 @@
1
- require "thor/group"
2
- require 'rubygems'
3
- require 'active_support'
4
- require 'active_support/core_ext/string'
5
-
6
- module Swiftly
7
- class GeneratePostType < Thor::Group
8
-
9
- include Thor::Actions
10
-
11
- argument :post_type_name
12
- argument :post_type_filter
13
- argument :project
14
-
15
- desc "Handles the creation of the post type file."
16
-
17
- def self.source_root
18
- File.dirname(__FILE__)
19
- end
20
-
21
- def create()
22
-
23
- if @post_type_filter == 'published-date' or @post_type_filter == ''
24
-
25
- @filter = '&int-year=$matches[1]&int-month=$matches[2]'
26
- @taxonomy_filter = '=$matches[1]&int-year=$matches[2]$&int-month=$matches[3]'
27
- @filter_regexp = '(\d{4})/(\d{2})/??'
28
-
29
- elsif @post_type_filter == 'last-name'
30
-
31
- @post_type_filter = '&letter=$matches[1]'
32
- @filter_regexp = '([A-Z])/??$'
33
-
34
- elsif @post_type_filter == 'start-date'
35
-
36
- @post_type_filter = '&month=$matches[1]'
37
- @filter_regexp = '(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/?$'
38
-
39
- else
40
-
41
- say "\nswiftly: filter type \"#{@post_type_filter}\" unaccepted\n\n", :red
42
- exit
43
-
44
- end
45
-
46
- template File.join( 'templates', 'post_type.erb' ), File.join( "#{@project[:path]}", 'wp-content', 'plugins', "#{@project[:name]}-specific-plugin", 'custom-post-types',"#{@post_type_name.pluralize}.php")
47
-
48
- end
49
- end
50
- end