swiftly 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +2 -0
- data/Dropbox/Development/www/Swiftlyfile +8 -0
- data/Gemfile +3 -0
- data/bin/swiftly +15 -0
- data/lib/swiftly/Rakefile +38 -0
- data/lib/swiftly/app_module.rb +320 -0
- data/lib/swiftly/clean.rb +33 -0
- data/lib/swiftly/cli.rb +36 -0
- data/lib/swiftly/config.rb +131 -0
- data/lib/swiftly/config_global_generator.rb +35 -0
- data/lib/swiftly/config_plugins_generator.rb +33 -0
- data/lib/swiftly/config_project_generator.rb +32 -0
- data/lib/swiftly/config_swiftlyfile_generator.rb +34 -0
- data/lib/swiftly/config_templates_generator.rb +33 -0
- data/lib/swiftly/configure.rb +27 -0
- data/lib/swiftly/configure_all.rb +181 -0
- data/lib/swiftly/configure_local.rb +34 -0
- data/lib/swiftly/configure_production.rb +42 -0
- data/lib/swiftly/configure_staging.rb +41 -0
- data/lib/swiftly/create.rb +94 -0
- data/lib/swiftly/create_git.rb +40 -0
- data/lib/swiftly/create_project.rb +67 -0
- data/lib/swiftly/create_wordpress.rb +185 -0
- data/lib/swiftly/database.rb +213 -0
- data/lib/swiftly/destroy.rb +53 -0
- data/lib/swiftly/enable.rb +13 -0
- data/lib/swiftly/enable_wordpress.rb +22 -0
- data/lib/swiftly/generate.rb +23 -0
- data/lib/swiftly/generate_post_type.rb +50 -0
- data/lib/swiftly/init.rb +130 -0
- data/lib/swiftly/packages.rb +137 -0
- data/lib/swiftly/project.rb +127 -0
- data/lib/swiftly/pull.rb +25 -0
- data/lib/swiftly/push.rb +60 -0
- data/lib/swiftly/rollback.rb +78 -0
- data/lib/swiftly/setup.rb +34 -0
- data/lib/swiftly/ssh.rb +36 -0
- data/lib/swiftly/templates/config_global.erb +3 -0
- data/lib/swiftly/templates/config_project.erb +11 -0
- data/lib/swiftly/templates/gitignore.erb +7 -0
- data/lib/swiftly/templates/post_type.erb +98 -0
- data/lib/swiftly/templates/swiftlyfile.erb +21 -0
- data/lib/swiftly/version.rb +4 -0
- data/swiftly.gemspec +61 -0
- data/test/test_swiftly_spec.rb +18 -0
- metadata +175 -0
@@ -0,0 +1,185 @@
|
|
1
|
+
require "thor/group"
|
2
|
+
require 'rubygems'
|
3
|
+
require 'active_support'
|
4
|
+
require 'swiftly/packages'
|
5
|
+
require 'swiftly/app_module'
|
6
|
+
require 'active_support/core_ext/string'
|
7
|
+
require 'git'
|
8
|
+
|
9
|
+
module Swiftly
|
10
|
+
class CreateWordpress < Thor::Group
|
11
|
+
|
12
|
+
include Thor::Actions
|
13
|
+
include Helpers
|
14
|
+
|
15
|
+
argument :project_name
|
16
|
+
argument :template
|
17
|
+
argument :settings
|
18
|
+
argument :project_path
|
19
|
+
|
20
|
+
desc "Handles the creation of a wordpress project."
|
21
|
+
|
22
|
+
def self.source_root
|
23
|
+
|
24
|
+
File.dirname(__FILE__)
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_wordpress()
|
29
|
+
|
30
|
+
# download wordpress and place it in the project directory
|
31
|
+
inside @project_path do
|
32
|
+
|
33
|
+
get 'https://wordpress.org/latest.zip', 'latest.zip' unless File.exist? 'wordpress'
|
34
|
+
|
35
|
+
unzip 'latest.zip', 'wordpress' unless File.exist? 'wordpress'
|
36
|
+
|
37
|
+
remove_file 'latest.zip' unless !File.exist? 'latest.zip'
|
38
|
+
|
39
|
+
Dir['wordpress/*'].each do |e|
|
40
|
+
|
41
|
+
FileUtils.mv( e, @project_path ) unless File.exist? e.gsub(/^wordpress/, @project_path )
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
remove_file 'wordpress' unless !(Dir.entries('wordpress') - %w{ . .. }).empty?
|
46
|
+
|
47
|
+
inside File.join( 'wp-content', 'themes') do
|
48
|
+
|
49
|
+
if @template[:location] =~ /^#{URI::regexp}\.zip$/
|
50
|
+
|
51
|
+
zipfile = get @template[:location], File.basename( @template[:location] )
|
52
|
+
|
53
|
+
unzip zipfile, @template[:name] unless File.exist? @template[:name]
|
54
|
+
|
55
|
+
remove_file zipfile unless !File.exist? zipfile
|
56
|
+
|
57
|
+
else
|
58
|
+
|
59
|
+
FileUtils.cp_r( File.join( @template[:location], @template[:name] ), '.' )
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
FileUtils.mv( @template[:name], @project_name ) unless !File.exists? @template[:name].capitalize
|
64
|
+
|
65
|
+
inside @project_name do
|
66
|
+
|
67
|
+
[
|
68
|
+
'.git',
|
69
|
+
'_resources',
|
70
|
+
'.gitignore',
|
71
|
+
'.htaccess',
|
72
|
+
".#{APP_NAME}",
|
73
|
+
".#{APP_NAME}ignore"
|
74
|
+
].each do |e|
|
75
|
+
|
76
|
+
remove_file e
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
[
|
81
|
+
'.htaccess',
|
82
|
+
'wp-config.php',
|
83
|
+
'bower.json',
|
84
|
+
'config.rb',
|
85
|
+
'Guardfile',
|
86
|
+
'Gemfile',
|
87
|
+
'Gemfile.lock'
|
88
|
+
].each do |file|
|
89
|
+
|
90
|
+
gsub_file file, /(#{@template[:name]})/, @project_name unless !File.exists? file
|
91
|
+
|
92
|
+
FileUtils.mv( file, @project_path ) unless !File.exists? file
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
FileUtils.mv(
|
97
|
+
"#{@template[:name]}-specific-plugin",
|
98
|
+
File.join( @project_path, "wp-content", "plugins", "#{@project_name}-specific-plugin")
|
99
|
+
) unless !File.exists? "#{@template[:name]}-specific-plugin"
|
100
|
+
|
101
|
+
FileUtils.mv(
|
102
|
+
File.join( "wp-login-logo-#{@template[:name]}.png" ) ,
|
103
|
+
File.join( "wp-login-logo-#{@project_name}.png" )
|
104
|
+
) unless !File.exists? File.join( "wp-login-logo-#{@template[:name]}.png" )
|
105
|
+
|
106
|
+
gsub_file 'functions.php', /(#{@template[:name]})/, @project_name
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
inside File.join( "wp-content", "plugins", "#{@project_name}-specific-plugin") do
|
112
|
+
|
113
|
+
FileUtils.mv(
|
114
|
+
"#{@template[:name]}-plugin.php",
|
115
|
+
"#{@project_name}-plugin.php"
|
116
|
+
) unless !File.exists? "#{@template[:name]}-plugin.php"
|
117
|
+
|
118
|
+
gsub_file "#{@project_name}-plugin.php", /(#{@template[:name]})/, @project_name.capitalize unless !File.exists? "#{@template[:name]}-plugin.php"
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
inside File.join( "wp-content", "plugins" ) do
|
123
|
+
|
124
|
+
plugins = Swiftly::Packages.load_plugins :wordpress
|
125
|
+
|
126
|
+
if plugins
|
127
|
+
|
128
|
+
# grab global plugins if they exist
|
129
|
+
plugins.each do |plugin|
|
130
|
+
|
131
|
+
if plugin[:location] =~ /^#{URI::regexp}\.zip$/
|
132
|
+
|
133
|
+
zipfile = get plugin[:location], File.basename( plugin[:location] )
|
134
|
+
|
135
|
+
unzip zipfile, plugin[:name] unless File.exist? plugin[:name]
|
136
|
+
|
137
|
+
remove_file zipfile unless !File.exist? zipfile
|
138
|
+
|
139
|
+
else
|
140
|
+
|
141
|
+
FileUtils.cp_r( File.join( plugin[:location], plugin[:name] ), '.' ) unless File.exist? plugin[:name]
|
142
|
+
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# add plugins to the functions file
|
149
|
+
# Plugins.add_plugins_to_functions_file @project_path
|
150
|
+
|
151
|
+
remove_file "wp-config-sample.php"
|
152
|
+
|
153
|
+
gsub_file 'wp-config.php', /\/\/\s*Insert_Salts_Below/, Net::HTTP.get('api.wordpress.org', '/secret-key/1.1/salt')
|
154
|
+
gsub_file 'wp-config.php', /(table_prefix\s*=\s*')(wp_')/, '\1' + @project_name[0,3] + "_'"
|
155
|
+
|
156
|
+
if !@settings[:local][:db_host].nil? &&
|
157
|
+
!@settings[:local][:db_user].nil? &&
|
158
|
+
!@settings[:local][:db_pass].nil?
|
159
|
+
|
160
|
+
gsub_file 'wp-config.php', /(\$local\s*?=[\s|\S]*?)({[\s|\S]*?})/ do |match|
|
161
|
+
|
162
|
+
'$local = \'{
|
163
|
+
"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
|
+
"domain": "http://' + @project_name + '.dev",
|
168
|
+
"wp_home": "http://' + @project_name + '.dev"
|
169
|
+
}'
|
170
|
+
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
database = Swiftly::Database.new( @project_name )
|
175
|
+
|
176
|
+
database.create( :local )
|
177
|
+
|
178
|
+
run('bundle') unless !File.exists? 'Gemfile'
|
179
|
+
run('bundle exec guard') unless !File.exists? 'Guardfile'
|
180
|
+
run('bower update') unless !File.exists? 'bower.json'
|
181
|
+
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,213 @@
|
|
1
|
+
require 'Thor'
|
2
|
+
require 'swiftly/app_module'
|
3
|
+
require "thor/group"
|
4
|
+
require 'swiftly/project'
|
5
|
+
require 'open3'
|
6
|
+
|
7
|
+
module Swiftly
|
8
|
+
class Database < Thor
|
9
|
+
|
10
|
+
include Thor::Actions
|
11
|
+
include Helpers
|
12
|
+
|
13
|
+
no_commands do
|
14
|
+
|
15
|
+
def initialize(project_name)
|
16
|
+
|
17
|
+
@settings = Project.settings( project_name )
|
18
|
+
@project_name = project_name
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def verify_db_credentials( environment, verbage )
|
23
|
+
|
24
|
+
if @settings[environment][:db_user].nil?
|
25
|
+
|
26
|
+
say #spacer
|
27
|
+
say_status "#{APP_NAME}:", "Could not #{verbage} #{environment} database, because your credentials are not set.", :red
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
if @settings[environment][:db_host].nil?
|
32
|
+
|
33
|
+
say #spacer
|
34
|
+
say_status "#{APP_NAME}:", "Could not #{verbage} #{environment} database, because your credentials are not set.", :red
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
if @settings[environment][:db_pass].nil?
|
39
|
+
|
40
|
+
say #spacer
|
41
|
+
say_status "#{APP_NAME}:", "Could not #{verbage} #{environment} database, because your credentials are not set.", :red
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
if @settings[environment][:db_name].nil?
|
46
|
+
|
47
|
+
say #spacer
|
48
|
+
say_status "#{APP_NAME}:", "Could not #{verbage} #{environment} database, because your credentials are not set.", :red
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
abort if @settings[environment][:db_user].nil?
|
53
|
+
abort if @settings[environment][:db_host].nil?
|
54
|
+
abort if @settings[environment][:db_pass].nil?
|
55
|
+
abort if @settings[environment][:db_name].nil?
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def dump( environment )
|
60
|
+
|
61
|
+
verify_db_credentials environment, 'dump your'
|
62
|
+
|
63
|
+
# provide the create dump site for the database dump
|
64
|
+
dump_path = File.join( @settings[:project][:dump], environment.to_s )
|
65
|
+
|
66
|
+
dump_file = "#{dump_path}/#{Time.now.strftime("%F-%H-%M-%S-%9N")}-#{environment}.sql"
|
67
|
+
|
68
|
+
# check if the credentials environment provided was local and the ssh_status is set in order to dump using ssh or not
|
69
|
+
if environment != :local && @settings[environment][:ssh_sql] != :disabled
|
70
|
+
|
71
|
+
cmd = <<-EOF.unindent
|
72
|
+
ssh \
|
73
|
+
-C #{@settings[environment][:ssh_user]}@#{@settings[environment][:domain].gsub(/http:\/\//, '')} \
|
74
|
+
mysqldump \
|
75
|
+
--single-transaction \
|
76
|
+
--opt \
|
77
|
+
--net_buffer_length=75000 \
|
78
|
+
--verbose \
|
79
|
+
-u'#{@settings[environment][:db_user]}' \
|
80
|
+
-h'#{@settings[environment][:db_host]}' \
|
81
|
+
-p'#{@settings[environment][:db_pass]}' \
|
82
|
+
'#{@settings[environment][:db_name]}' > \
|
83
|
+
'#{dump_file}'
|
84
|
+
EOF
|
85
|
+
|
86
|
+
swiftly_shell cmd
|
87
|
+
|
88
|
+
else
|
89
|
+
|
90
|
+
cmd = <<-EOF.unindent
|
91
|
+
mysqldump \
|
92
|
+
--single-transaction \
|
93
|
+
--opt --net_buffer_length=75000 \
|
94
|
+
--verbose \
|
95
|
+
-u'#{@settings[environment][:db_user]}' \
|
96
|
+
-h'#{@settings[environment][:db_host]}' \
|
97
|
+
-p'#{@settings[environment][:db_pass]}' \
|
98
|
+
'#{@settings[environment][:db_name]}' > \
|
99
|
+
'#{dump_file}'
|
100
|
+
EOF
|
101
|
+
|
102
|
+
swiftly_shell cmd
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
dump_file
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
def import( destination, import_file )
|
111
|
+
|
112
|
+
verify_db_credentials destination, 'import into your'
|
113
|
+
|
114
|
+
# dump the destination database first!
|
115
|
+
dump( destination )
|
116
|
+
|
117
|
+
# check if the destination destination provided was local and the ssh_status is set in order to dump using ssh or not
|
118
|
+
if destination != :local && @settings[destination][:ssh_sql] != :disabled
|
119
|
+
|
120
|
+
cmd = <<-EOF.unindent
|
121
|
+
ssh \
|
122
|
+
-C #{@settings[destination][:ssh_user]}@#{@settings[destination][:domain].gsub(/http:\/\//, '')} \
|
123
|
+
mysql \
|
124
|
+
-u'#{@settings[destination][:db_user]}' \
|
125
|
+
-h'#{@settings[destination][:db_host]}' \
|
126
|
+
-p'#{@settings[destination][:db_pass]}' \
|
127
|
+
'#{@settings[destination][:db_name]}' \
|
128
|
+
< '#{import_file}'
|
129
|
+
EOF
|
130
|
+
|
131
|
+
swiftly_shell cmd
|
132
|
+
|
133
|
+
|
134
|
+
else
|
135
|
+
|
136
|
+
cmd = <<-EOF.unindent
|
137
|
+
mysql \
|
138
|
+
-u'#{@settings[destination][:db_user]}' \
|
139
|
+
-h'#{@settings[destination][:db_host]}' \
|
140
|
+
-p'#{@settings[destination][:db_pass]}' \
|
141
|
+
'#{@settings[destination][:db_name]}' < \
|
142
|
+
'#{import_file}'
|
143
|
+
EOF
|
144
|
+
|
145
|
+
swiftly_shell cmd
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
def sync( origin, destination, import_file = nil )
|
152
|
+
|
153
|
+
verify_db_credentials origin, 'sync your'
|
154
|
+
verify_db_credentials destination, 'sync your'
|
155
|
+
|
156
|
+
# dump the origin database and return the file
|
157
|
+
import_file = dump( origin ) unless import_file != nil
|
158
|
+
|
159
|
+
import( destination, fix_serialization( update_urls(origin, destination, import_file ) ) )
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
def create( environment )
|
164
|
+
|
165
|
+
verify_db_credentials environment, 'create a'
|
166
|
+
|
167
|
+
cmd = <<-EOF.unindent
|
168
|
+
mysql \
|
169
|
+
-u'#{@settings[environment][:db_user]}' \
|
170
|
+
-h'#{@settings[environment][:db_host]}' \
|
171
|
+
-p'#{@settings[environment][:db_pass]}' \
|
172
|
+
-Bse"CREATE DATABASE IF NOT EXISTS \
|
173
|
+
#{@settings[environment][:db_name]}"
|
174
|
+
EOF
|
175
|
+
|
176
|
+
swiftly_shell cmd
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
def drop( environment )
|
181
|
+
|
182
|
+
verify_db_credentials environment, 'drop your'
|
183
|
+
|
184
|
+
cmd = <<-EOF.unindent
|
185
|
+
mysql \
|
186
|
+
-u'#{@settings[environment][:db_user]}' \
|
187
|
+
-h'#{@settings[environment][:db_host]}' \
|
188
|
+
-p'#{@settings[environment][:db_pass]}' \
|
189
|
+
-Bse"DROP DATABASE IF EXISTS \
|
190
|
+
#{@settings[environment][:db_name]}"
|
191
|
+
EOF
|
192
|
+
|
193
|
+
swiftly_shell cmd
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
def update_urls( origin, destination, import_file )
|
198
|
+
|
199
|
+
# copy the file to the temp folder
|
200
|
+
FileUtils.cp( import_file, File.join( @settings[:project][:dump], "temp") )
|
201
|
+
|
202
|
+
# return the rewritten file
|
203
|
+
return find_and_replace(
|
204
|
+
input: import_file,
|
205
|
+
pattern: @settings[origin][:domain],
|
206
|
+
output: @settings[destination][:domain],
|
207
|
+
file: true
|
208
|
+
)
|
209
|
+
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'swiftly/app_module'
|
2
|
+
require 'swiftly/database'
|
3
|
+
|
4
|
+
module Swiftly
|
5
|
+
class Destroy < Thor
|
6
|
+
|
7
|
+
include Thor::Actions
|
8
|
+
include Helpers
|
9
|
+
|
10
|
+
desc "destroy PROJECT_NAME", "Destroy local project!"
|
11
|
+
|
12
|
+
def destroy( project_name )
|
13
|
+
|
14
|
+
settings = Swiftly::Project.settings project_name
|
15
|
+
directory = File.join( settings[:project][:path], '' )
|
16
|
+
zipfile_name = settings[:project][:path] + '.zip'
|
17
|
+
|
18
|
+
if File.exist? zipfile_name
|
19
|
+
|
20
|
+
|
21
|
+
say_status "#{APP_NAME}:", "There is already a zip file named [#{project_name}.zip]. \n\n", :red
|
22
|
+
|
23
|
+
responses = ['y','Y','']
|
24
|
+
|
25
|
+
unless responses.include? ask set_color "Do you want to overwrite it? [Y/n]", :yellow
|
26
|
+
|
27
|
+
say #spacer
|
28
|
+
say_status "#{APP_NAME}:", "No changes were made. Please remove [#{project_name}.zip] before running destroy again.\n\n", :yellow
|
29
|
+
abort
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
database = Swiftly::Database.new( project_name )
|
35
|
+
|
36
|
+
database.dump( :local )
|
37
|
+
database.drop( :local )
|
38
|
+
|
39
|
+
remove_file zipfile_name
|
40
|
+
|
41
|
+
zip zipfile_name, directory
|
42
|
+
|
43
|
+
FileUtils.remove_dir( settings[:project][:path] )
|
44
|
+
|
45
|
+
say #spacer
|
46
|
+
say_status "#{APP_NAME}:", "A backup was stored at [#{settings[:project][:path]}.zip].\n\n", :green
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
default_task :destroy
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'swiftly/app_module'
|
2
|
+
require 'swiftly/enable_wordpress'
|
3
|
+
|
4
|
+
module Swiftly
|
5
|
+
class Enable < Thor
|
6
|
+
include Thor::Actions
|
7
|
+
include Helpers
|
8
|
+
|
9
|
+
desc "wordpress [COMMAND]", "Enable wordpress intergrations"
|
10
|
+
subcommand "wordpress", Wordpress
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "swiftly/config_templates_generator"
|
2
|
+
require "swiftly/config_plugins_generator"
|
3
|
+
|
4
|
+
module Swiftly
|
5
|
+
class Wordpress < Thor
|
6
|
+
|
7
|
+
desc "plugins", "Enable plugins for intergration"
|
8
|
+
def plugins()
|
9
|
+
|
10
|
+
ConfigPluginsGenerator.new.create
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "templates", "Enable templates for intergrations"
|
15
|
+
|
16
|
+
def templates()
|
17
|
+
|
18
|
+
ConfigTemplateGenerator.new.create
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
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
|
@@ -0,0 +1,50 @@
|
|
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
|
data/lib/swiftly/init.rb
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'json'
|
3
|
+
require 'swiftly/config_global_generator'
|
4
|
+
require 'swiftly/config_swiftlyfile_generator'
|
5
|
+
require 'swiftly/app_module'
|
6
|
+
|
7
|
+
module Swiftly
|
8
|
+
class Init < Thor
|
9
|
+
|
10
|
+
include Thor::Actions
|
11
|
+
include Helpers
|
12
|
+
|
13
|
+
desc "init", "Initiate #{APP_NAME.capitalize} for the first time"
|
14
|
+
|
15
|
+
def init
|
16
|
+
|
17
|
+
say # spacer
|
18
|
+
|
19
|
+
say "\t\t#{APP_NAME} #{VERSION} Development Manager\n\n", :blue
|
20
|
+
|
21
|
+
say_status "#{APP_NAME}:", "Thanks for trying out #{APP_NAME}. Lets get started!", :green
|
22
|
+
|
23
|
+
settings = []
|
24
|
+
|
25
|
+
inside Dir.home do
|
26
|
+
|
27
|
+
responses = ['y','Y','']
|
28
|
+
|
29
|
+
questions = {
|
30
|
+
sites_path: "\n\n--> What is the absolute path to the folder \n\s\s\s\swhere you keep all of your sites? (\e[0;m#{Dir.home}\e[33;m):",
|
31
|
+
db_host: "\n--> What is your local hostname? (\e[0;mlocalhost\e[33;m):",
|
32
|
+
db_user: "\n--> What is your local mysql username? (\e[0;mroot\e[33;m):",
|
33
|
+
db_pass: "\n--> What is your local mysql password?"
|
34
|
+
}
|
35
|
+
|
36
|
+
questions.each do |type, question|
|
37
|
+
|
38
|
+
confirm = false
|
39
|
+
|
40
|
+
until confirm == true do
|
41
|
+
|
42
|
+
if type === :sites_path
|
43
|
+
|
44
|
+
answer = File.expand_path( ask question, :yellow, :path => true )
|
45
|
+
|
46
|
+
elsif type === :db_pass
|
47
|
+
|
48
|
+
answer = ask question, :yellow, :echo => false
|
49
|
+
|
50
|
+
else
|
51
|
+
|
52
|
+
answer = ask question, :yellow
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
if type === :sites_path && answer == ''
|
57
|
+
|
58
|
+
answer = Dir.home
|
59
|
+
|
60
|
+
elsif type === :db_pass
|
61
|
+
|
62
|
+
password = ask "\n\n--> Please re-enter your password?", :yellow, :echo => false
|
63
|
+
|
64
|
+
say #spacer
|
65
|
+
|
66
|
+
until password == answer
|
67
|
+
|
68
|
+
say_status "#{APP_NAME}:", "Passwords did not match please try again.\n", :yellow
|
69
|
+
|
70
|
+
answer = ask question, :yellow, :echo => false
|
71
|
+
|
72
|
+
password = ask "\n--> Please re-enter your password?\n", :yellow, :echo => false
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
if password == answer
|
77
|
+
|
78
|
+
confirm = true
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
elsif answer == ''
|
83
|
+
|
84
|
+
if question[/\e\[[0-9;]*[a-zA-Z](.*)\e\[[0-9;]*[a-zA-Z]/, 1] == ''
|
85
|
+
|
86
|
+
answer = nil
|
87
|
+
|
88
|
+
else
|
89
|
+
|
90
|
+
answer = question[/\e\[[0-9;]*[a-zA-Z](.*)\e\[[0-9;]*[a-zA-Z]/, 1]
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
unless type === :db_pass
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
if responses.include? ask( "\n--> Got it! Is this correct? \e[32;m#{answer}\e[0;m [Y|n]")
|
100
|
+
|
101
|
+
confirm = true
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
settings << answer
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
say_status "\n\s\s\s\sThats it!", "You can now run `#{APP_NAME} help` for more options."
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
Swiftly::ConfigGlobalGenerator.new([
|
116
|
+
settings[0]
|
117
|
+
]).invoke_all
|
118
|
+
|
119
|
+
ConfigSwiftlyfileGenerator.new([
|
120
|
+
settings[1],
|
121
|
+
settings[2],
|
122
|
+
settings[3]
|
123
|
+
]).invoke_all
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
default_task :init
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|