wslave 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,82 @@
1
+ require 'fileutils'
2
+ require 'rubygems'
3
+ require 'pathname'
4
+ require 'git'
5
+
6
+ require_relative 'wslave_tools'
7
+
8
+ class WSlaveNew
9
+ def initialize(path, version = '', wspath = '')
10
+ puts '⚙ Initializing Toolchain・・・'
11
+
12
+ if (wspath != '')
13
+ manual_path = true
14
+ if ((Pathname.new(wspath)).absolute?)
15
+ base_path = File.expand_path "#{wspath}/base/"
16
+ template_path = File.expand_path "#{wspath}/templates/"
17
+ else
18
+ base_path = File.expand_path "#{path}/#{wspath}/base/"
19
+ template_path = File.expand_path "#{path}/#{wspath}/templates/"
20
+ end
21
+ else
22
+ manual_path = false
23
+ wspath = "#{__dir__}/.."
24
+ base_path = File.expand_path "#{wspath}/base/"
25
+ template_path = File.expand_path "#{wspath}/templates/"
26
+ end
27
+
28
+ FileUtils.mkdir_p path
29
+
30
+ Dir.chdir path
31
+
32
+ puts " > Setting up WordPress WSlave setup in: #{path}"
33
+ FileUtils.cp_r Dir.glob("#{base_path}/*"), path
34
+ FileUtils.cp_r Dir.glob("#{template_path}/*"), path
35
+ add_path_to_Gemspec(wspath, path) if manual_path
36
+
37
+ spec = Gem::Specification::load("#{wspath}/wslave.gemspec")
38
+ File.open("#{path}/config/.wslave", 'w') {|f| f.write(spec.version)}
39
+
40
+ `cd #{path} && git init && git add --all && git commit -am "initial commit by wslave"`
41
+
42
+ `cd #{path} && git submodule add git://github.com/WordPress/WordPress.git public/wordpress`
43
+ `cd #{path} && git submodule update --init --recursive public/wordpress`
44
+ if (version == 'edge' || version == 'master')
45
+ `cd #{path}/public/wordpress && git checkout master`
46
+ elsif version != ''
47
+ `cd #{path}/public/wordpress && git checkout #{version}`
48
+ else
49
+ `cd #{path}/public/wordpress && git checkout #{get_stable_branch_version("#{path}/public/wordpress")}-branch`
50
+ end
51
+
52
+ puts " > Preparing detached content directory"
53
+ FileUtils.cp_r("#{path}/public/wordpress/wp-content", "#{path}/public/wp-content")
54
+ FileUtils.mkdir("#{path}/public/wp-content/uploads") unless Dir.exist?("#{path}/public/wp-content/uploads")
55
+ FileUtils.touch("#{path}/public/wp-content/uploads/.gitkeep")
56
+ FileUtils.mkdir("#{path}/public/wp-content/upgrade") unless Dir.exist?("#{path}/public/wp-content/upgrade")
57
+ FileUtils.touch("#{path}/public/wp-content/upgrade/.gitkeep")
58
+ Dir.chdir path
59
+
60
+ puts " > Setting permissions"
61
+ WSlaveTools.set_dev_perms
62
+
63
+ `cd #{path} && git add --all && git commit -am "Add and initialize WordPress#{version}"`
64
+ puts " > Done!"
65
+ end
66
+
67
+ def add_path_to_Gemspec(wspath, path)
68
+ gemtext = File.read("#{path}/Gemfile")
69
+ gemtext.gsub!("gem 'wslave'", "gem 'wslave', path: '#{wspath}'")
70
+ File.open("#{path}/Gemfile", "w") {|gemfile| gemfile.puts gemtext}
71
+ end
72
+
73
+ def get_stable_branch_version(path)
74
+ latest = '5.4' # This is just a fallback (latest at time of update)
75
+ # TODO Implementation requires this issue be resolved: https://github.com/ruby-git/ruby-git/issues/424
76
+ #g = Git.open(path)
77
+ #g.brances.remote.each do |branch|
78
+ #end
79
+
80
+ latest
81
+ end
82
+ end
@@ -0,0 +1,76 @@
1
+ require 'yaml'
2
+
3
+ class WSlaveSage
4
+ attr_reader :theme_name
5
+
6
+ def initialize()
7
+ @theme_name = ''
8
+ end
9
+
10
+ def create(name)
11
+ unless File.exist?("./config/.wslave")
12
+ puts "This command must be run in the root of a WSlave setup"
13
+ end
14
+
15
+ name = 'wslave-sage-theme' if name.empty?
16
+ project_root = Dir.pwd
17
+
18
+ puts "Creating Sage theme at public/wp-content/themes/#{name}"
19
+ `cd public/wp-content/themes && composer create-project roots/sage #{name} dev-master`
20
+
21
+ Dir.chdir project_root
22
+ _write_wslave_sage_config(name)
23
+ _overwrite_sage_webpack_browsersync_config
24
+ end
25
+
26
+ def update()
27
+ return unless _check()
28
+ system("cd public/wp-content/themes/#{@theme_name} && yarn && yarn build")
29
+ end
30
+
31
+ def dev()
32
+ return unless _check()
33
+ system("cd public/wp-content/themes/#{@theme_name} && yarn start")
34
+ end
35
+
36
+ def build()
37
+ return unless _check()
38
+ system("cd public/wp-content/themes/#{@theme_name} && yarn build")
39
+ end
40
+
41
+ def production()
42
+ return unless _check()
43
+ system("cd public/wp-content/themes/#{@theme_name} && yarn build:production")
44
+ end
45
+
46
+ def theme_name?()
47
+ return '' unless _check()
48
+ @theme_name
49
+ end
50
+
51
+ def _write_wslave_sage_config(name)
52
+ File.open("./config/sage.yml", 'w') {|f| YAML.dump({theme: name}, f)}
53
+ end
54
+
55
+ def _overwrite_sage_webpack_browsersync_config
56
+ return unless _check()
57
+ theme_info = YAML.load_file("./config/sage.yml")
58
+ Dir.chdir "#{Dir.pwd}/public/wp-content/themes/#{theme_info[:theme]}"
59
+
60
+ webpack_config_path = './webpack.mix.js'
61
+ new_webpack_config = File.read(webpack_config_path).gsub(
62
+ /browserSync\('sage.test'\)/, "browserSync('localhost:8000')"
63
+ )
64
+ File.open(webpack_config_path, 'w') { |f| f.puts new_webpack_config }
65
+ end
66
+
67
+ def _check()
68
+ if (File.exist?("./config/.wslave") && File.exist?("./config/sage.yml"))
69
+ theme_info = YAML.load_file("./config/sage.yml")
70
+ @theme_name = theme_info[:theme]
71
+ return true
72
+ end
73
+ puts "This does not appear to be the root of a WSlave managed app with a Sage theme."
74
+ false
75
+ end
76
+ end
@@ -0,0 +1,80 @@
1
+ require 'fileutils'
2
+
3
+ class WSlaveTools
4
+ def self.wslave_root?()
5
+ return true if (File.exist?("./config/.wslave") &&
6
+ File.exist?("docker-compose.yml"))
7
+ puts "This does not appear to be the root of a WSlave managed app."
8
+ puts "Run command again from the root directory of a WSlave app."
9
+ false
10
+ end
11
+
12
+ def self.set_dev_perms(path = '.')
13
+ begin
14
+ unless Dir.exist?("#{path}/public/wp-content/upgrade")
15
+ FileUtils.mkdir("#{path}/public/wp-content/upgrade")
16
+ FileUtils.touch("#{path}/public/wp-content/upgrade/.gitkeep")
17
+ end
18
+ FileUtils.chown(nil, 'www-data', "#{path}/public/wp-content/themes")
19
+ FileUtils.chmod(0775, "#{path}/public/wp-content/themes")
20
+ FileUtils.chown(nil, 'www-data', "#{path}/public/wp-content/uploads")
21
+ FileUtils.chmod(0775, "#{path}/public/wp-content/uploads")
22
+ FileUtils.chown(nil, 'www-data', "#{path}/public/wp-content/plugins")
23
+ FileUtils.chmod(0775, "#{path}/public/wp-content/plugins")
24
+ FileUtils.chown(nil, 'www-data', "#{path}/public/wp-content/upgrade")
25
+ FileUtils.chmod(0775, "#{path}/public/wp-content/upgrade")
26
+
27
+ unless Dir.exist?("#{path}/db")
28
+ FileUtils.mkdir("#{path}/db")
29
+ end
30
+ FileUtils.chown(nil, 'www-data', "#{path}/db")
31
+ FileUtils.chmod(0775, "#{path}/db")
32
+
33
+ unless Dir.exist?("#{path}/db/active")
34
+ FileUtils.mkdir("#{path}/db/active")
35
+ FileUtils.touch("#{path}/db/active/.gitkeep")
36
+ end
37
+ FileUtils.chown(nil, 'www-data', "#{path}/db/active")
38
+ FileUtils.chmod(0775, "#{path}/db/active")
39
+
40
+ unless Dir.exist?("#{path}/db/dev")
41
+ FileUtils.mkdir("#{path}/db/dev")
42
+ FileUtils.touch("#{path}/db/dev/.gitkeep")
43
+ end
44
+ FileUtils.chown(nil, 'www-data', "#{path}/db/dev")
45
+ FileUtils.chmod(0775, "#{path}/db/dev")
46
+
47
+ unless Dir.exist?("#{path}/db/staging")
48
+ FileUtils.mkdir("#{path}/db/staging")
49
+ FileUtils.touch("#{path}/db/staging/.gitkeep")
50
+ end
51
+ FileUtils.chown(nil, 'www-data', "#{path}/db/staging")
52
+ FileUtils.chmod(0775, "#{path}/db/staging")
53
+
54
+ unless Dir.exist?("#{path}/db/production")
55
+ FileUtils.mkdir("#{path}/db/production")
56
+ FileUtils.touch("#{path}/db/production/.gitkeep")
57
+ end
58
+ FileUtils.chown(nil, 'www-data', "#{path}/db/production")
59
+ FileUtils.chmod(0775, "#{path}/db/production")
60
+ rescue Errno::EPERM
61
+ puts "!!!WARNING!!! Your user does not belong to the www-data group!\n" \
62
+ " >>> Unable to make folders writable for devlopment. <<<\n" \
63
+ " >>> You will not be able to edit files or themes in the WP dev container! <<<\n"
64
+ end
65
+ end
66
+
67
+ def self._check_and_mk_dirs(path = '.')
68
+ end
69
+
70
+ def self.update_submodules
71
+ `git submodule update --init --recursive`
72
+ end
73
+
74
+ def self.sync
75
+ if wslave_root?
76
+ update_submodules
77
+ set_dev_perms
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,38 @@
1
+ require 'fileutils'
2
+ require 'rubygems'
3
+ require_relative 'wslave_tools'
4
+
5
+ class WSlaveUpdate
6
+ def initialize()
7
+ puts '⚙ Updating Toolchain・・・'
8
+
9
+ path = Dir.pwd
10
+ if !File.exist?("#{path}/config/.wslave")
11
+ puts "!!!This command must be run in a WSlave generated project!!!"
12
+ return
13
+ end
14
+
15
+ base_path = File.expand_path "#{__dir__}/../base/"
16
+ template_path = File.expand_path "#{__dir__}/../templates/"
17
+
18
+
19
+ Dir.chdir path
20
+
21
+ FileUtils.cp("#{base_path}/Capfile", "#{path}/Capfile")
22
+ # FileUtils.cp("#{base_path}/Gemfile", "#{path}/Gemfile")
23
+ FileUtils.cp("#{base_path}/Rakefile", "#{path}/Rakefile")
24
+ FileUtils.cp_r("#{base_path}/docker", "#{path}/")
25
+ FileUtils.cp("#{base_path}/docker-compose.yml", "#{path}/docker-compose.yml")
26
+ FileUtils.cp("#{base_path}/public/.htaccess", "#{path}/public/.htaccess")
27
+ FileUtils.cp_r(Dir.glob("#{base_path}/config/*"), "#{path}/config")
28
+ FileUtils.cp("#{template_path}/config/database.yml", "#{path}/config/database.yml") unless File.exist? "#{path}/config/database.yml"
29
+ FileUtils.cp("#{template_path}/config/definitions.yml", "#{path}/config/definitions.yml") unless File.exist? "#{path}/config/definitions.yml"
30
+
31
+ spec = Gem::Specification::load("#{__dir__}/../wslave.gemspec")
32
+ FileUtils.rm("#{path}/config/.wslave")
33
+ File.open("#{path}/config/.wslave", 'w') {|f| f.write(spec.version)}
34
+
35
+ Dir.chdir path
36
+ WSlaveTools.set_dev_perms(path)
37
+ end
38
+ end
@@ -0,0 +1,16 @@
1
+ default: &default
2
+ adapter: mysql2
3
+ encoding: utf8
4
+ reconnect: false
5
+ pool: 5
6
+ username:
7
+ password:
8
+ host:
9
+
10
+ staging:
11
+ <<: *default
12
+ database: _staging
13
+
14
+ production:
15
+ <<: *default
16
+ database: _production
@@ -0,0 +1,22 @@
1
+ deployer:
2
+ user:
3
+ # Uncomment this line if you are not on a shared host/if your web server runs under a different user than what you specified in the user field above
4
+ # www_data_group: www-data
5
+ host:
6
+ staging:
7
+ production:
8
+ root:
9
+ fqdn:
10
+ staging:
11
+ production:
12
+ branch:
13
+ staging: master
14
+ production: master
15
+ app:
16
+ name:
17
+ repo:
18
+ options:
19
+ # Choose from: git-with-submodules, git, scp
20
+ deploy_method: git-with-submodules
21
+ # Use rsync to upload auxialiary content files (set to false if your server doesn't support rsync)
22
+ rsync_enabled: true
@@ -0,0 +1,32 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'wslave'
3
+ s.version = '0.2.2'
4
+ s.licenses = ['GPL-3.0', 'AGPL-3.0']
5
+ s.summary = '"Word Slave" generates and controls a WordPress installation'
6
+ s.description = 'Word Slave includes the wslave command and a control library to generate a ' \
7
+ '"best practice" WordPress installation and includes a pre-rolled Docker ' \
8
+ 'setup for running a development server and a Capistrano setup for deployment.'
9
+ s.authors = ['Rei Kagetsuki']
10
+ s.email = 'info@phantom.industries'
11
+ s.homepage = 'https://github.com/PhantomCreation/wslave'
12
+
13
+ s.required_ruby_version = '>= 2.0.0'
14
+ s.files = Dir.glob('lib/**/*.rb', File::FNM_DOTMATCH) +
15
+ Dir.glob('bin/**/*.rb', File::FNM_DOTMATCH) +
16
+ Dir.glob("base/**/*", File::FNM_DOTMATCH) +
17
+ Dir.glob("templates/**/*", File::FNM_DOTMATCH) +
18
+ ['wslave.gemspec']
19
+ s.require_paths = ['lib']
20
+ s.bindir = 'bin'
21
+ s.executables << 'wslave'
22
+
23
+ s.add_dependency 'capistrano', '= 3.14.1'
24
+ s.add_dependency 'capistrano-git-with-submodules', '~> 2.0', '2.0.4'
25
+ s.add_dependency 'capistrano-scm-copy', '~> 0.7', '0.7.0'
26
+ s.add_dependency 'capistrano-file-permissions', '~> 1.0', '1.0.0'
27
+
28
+ s.add_dependency 'git', '~> 1.7', '1.7.0'
29
+
30
+ s.add_dependency 'thor', '~> 1.0', '1.0.1'
31
+ s.add_dependency 'haikunator', '~> 1.1', '1.1.0'
32
+ end
metadata ADDED
@@ -0,0 +1,211 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wslave
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Rei Kagetsuki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.14.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.14.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano-git-with-submodules
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ - - '='
35
+ - !ruby/object:Gem::Version
36
+ version: 2.0.4
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '2.0'
44
+ - - '='
45
+ - !ruby/object:Gem::Version
46
+ version: 2.0.4
47
+ - !ruby/object:Gem::Dependency
48
+ name: capistrano-scm-copy
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.7'
54
+ - - '='
55
+ - !ruby/object:Gem::Version
56
+ version: 0.7.0
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '0.7'
64
+ - - '='
65
+ - !ruby/object:Gem::Version
66
+ version: 0.7.0
67
+ - !ruby/object:Gem::Dependency
68
+ name: capistrano-file-permissions
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.0'
74
+ - - '='
75
+ - !ruby/object:Gem::Version
76
+ version: 1.0.0
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.0'
84
+ - - '='
85
+ - !ruby/object:Gem::Version
86
+ version: 1.0.0
87
+ - !ruby/object:Gem::Dependency
88
+ name: git
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '1.7'
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.7.0
97
+ type: :runtime
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.7'
104
+ - - '='
105
+ - !ruby/object:Gem::Version
106
+ version: 1.7.0
107
+ - !ruby/object:Gem::Dependency
108
+ name: thor
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '1.0'
114
+ - - '='
115
+ - !ruby/object:Gem::Version
116
+ version: 1.0.1
117
+ type: :runtime
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '1.0'
124
+ - - '='
125
+ - !ruby/object:Gem::Version
126
+ version: 1.0.1
127
+ - !ruby/object:Gem::Dependency
128
+ name: haikunator
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - "~>"
132
+ - !ruby/object:Gem::Version
133
+ version: '1.1'
134
+ - - '='
135
+ - !ruby/object:Gem::Version
136
+ version: 1.1.0
137
+ type: :runtime
138
+ prerelease: false
139
+ version_requirements: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '1.1'
144
+ - - '='
145
+ - !ruby/object:Gem::Version
146
+ version: 1.1.0
147
+ description: Word Slave includes the wslave command and a control library to generate
148
+ a "best practice" WordPress installation and includes a pre-rolled Docker setup
149
+ for running a development server and a Capistrano setup for deployment.
150
+ email: info@phantom.industries
151
+ executables:
152
+ - wslave
153
+ extensions: []
154
+ extra_rdoc_files: []
155
+ files:
156
+ - base/.gitignore
157
+ - base/Capfile
158
+ - base/Gemfile
159
+ - base/Rakefile
160
+ - base/config/deploy-tools/gen-nginx-vhost.rb
161
+ - base/config/deploy-tools/gen-salts.rb
162
+ - base/config/deploy-tools/gen-wp-config.rb
163
+ - base/config/deploy-tools/nginx.vhost.erb
164
+ - base/config/deploy-tools/wp-config.php.erb
165
+ - base/config/deploy-tools/wp-config.php.local
166
+ - base/config/deploy.rb
167
+ - base/config/deploy/.production.rb.swp
168
+ - base/config/deploy/.staging.rb.swp
169
+ - base/config/deploy/production.rb
170
+ - base/config/deploy/staging.rb
171
+ - base/docker-compose.yml
172
+ - base/docker/apache/Dockerfile
173
+ - base/docker/nginx/Dockerfile
174
+ - base/docker/nginx/nginx.vhost
175
+ - base/docker/nginx/supervisord.conf
176
+ - base/public/.htaccess
177
+ - base/public/wp-config.php
178
+ - bin/wslave
179
+ - lib/wslave_docker.rb
180
+ - lib/wslave_new.rb
181
+ - lib/wslave_sage.rb
182
+ - lib/wslave_tools.rb
183
+ - lib/wslave_update.rb
184
+ - templates/config/database.yml
185
+ - templates/config/definitions.yml
186
+ - wslave.gemspec
187
+ homepage: https://github.com/PhantomCreation/wslave
188
+ licenses:
189
+ - GPL-3.0
190
+ - AGPL-3.0
191
+ metadata: {}
192
+ post_install_message:
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: 2.0.0
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ requirements: []
207
+ rubygems_version: 3.1.2
208
+ signing_key:
209
+ specification_version: 4
210
+ summary: '"Word Slave" generates and controls a WordPress installation'
211
+ test_files: []