marv 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +8 -10
- data/Gemfile.lock +16 -43
- data/LICENSE +0 -24
- data/README.md +9 -10
- data/Rakefile +4 -20
- data/VERSION +1 -1
- data/bin/marv +1 -1
- data/layouts/config/global.rb +31 -0
- data/layouts/config/project.rb +27 -0
- data/layouts/config/{router.php.erb → router.php} +5 -1
- data/layouts/config/server.rb +12 -0
- data/layouts/config/{wp-config.php.erb → wp-config.php} +0 -0
- data/layouts/plugin/{images → assets/images}/screenshot.png +0 -0
- data/layouts/plugin/{javascripts → assets/javascripts}/admin.coffee +0 -0
- data/layouts/plugin/{javascripts → assets/javascripts}/admin.js +0 -0
- data/layouts/plugin/{javascripts → assets/javascripts}/plugin.coffee +0 -0
- data/layouts/plugin/assets/javascripts/plugin.js +1 -0
- data/layouts/plugin/{stylesheets → assets/stylesheets}/plugin.scss +0 -0
- data/layouts/plugin/functions/{plugin.php.erb → plugin.php} +8 -7
- data/layouts/theme/{images → assets/images}/screenshot.png +0 -0
- data/layouts/theme/{javascripts → assets/javascripts}/admin.coffee +0 -0
- data/layouts/theme/{javascripts → assets/javascripts}/admin.js +0 -0
- data/layouts/theme/{javascripts → assets/javascripts}/theme.coffee +0 -0
- data/layouts/theme/{javascripts → assets/javascripts}/theme.js +0 -0
- data/layouts/theme/assets/stylesheets/_header.scss +18 -0
- data/layouts/theme/{stylesheets/style.scss.erb → assets/stylesheets/style.scss} +0 -0
- data/layouts/theme/functions/{functions.php.erb → functions.php} +0 -0
- data/layouts/theme/includes/{filters-admin.php.erb → filters-admin.php} +0 -0
- data/layouts/theme/includes/{filters.php.erb → filters.php} +0 -0
- data/layouts/theme/includes/{helpers.php.erb → helpers.php} +0 -0
- data/layouts/theme/templates/{404.php.erb → pages/404.php} +0 -0
- data/layouts/theme/templates/{archive.php.erb → pages/archive.php} +0 -0
- data/layouts/theme/templates/{author.php.erb → pages/author.php} +0 -0
- data/layouts/theme/templates/{search.php.erb → pages/search.php} +0 -0
- data/layouts/theme/templates/partials/{comments.php.erb → comments.php} +0 -0
- data/layouts/theme/templates/partials/{content-none.php.erb → content-none.php} +0 -0
- data/layouts/theme/templates/partials/{content.php.erb → content.php} +0 -0
- data/layouts/theme/templates/partials/{searchform.php.erb → searchform.php} +0 -0
- data/lib/marv.rb +8 -8
- data/lib/marv/cli.rb +15 -192
- data/lib/marv/cli/project.rb +57 -0
- data/lib/marv/cli/server.rb +65 -0
- data/lib/marv/global.rb +285 -0
- data/lib/marv/project/actions.rb +144 -0
- data/lib/marv/project/builder.rb +61 -0
- data/lib/marv/project/builder/assets.rb +112 -0
- data/lib/marv/{engines.rb → project/builder/engines.rb} +3 -1
- data/lib/marv/project/builder/functions.rb +112 -0
- data/lib/marv/project/builder/templates.rb +37 -0
- data/lib/marv/project/create.rb +139 -0
- data/lib/marv/project/guard.rb +83 -0
- data/lib/marv/project/guard/assets.rb +37 -0
- data/lib/{guard/marv → marv/project/guard}/config.rb +5 -9
- data/lib/marv/project/guard/functions.rb +44 -0
- data/lib/marv/project/guard/templates.rb +35 -0
- data/lib/marv/project/project.rb +149 -0
- data/lib/marv/server/actions.rb +79 -0
- data/lib/marv/server/create.rb +100 -0
- data/lib/marv/server/server.rb +201 -0
- data/marv.gemspec +69 -71
- metadata +82 -107
- data/.rspec +0 -1
- data/features/step_definitions/marv_steps.rb +0 -38
- data/features/support/env.rb +0 -17
- data/layouts/config/project-config.rb +0 -17
- data/layouts/plugin/javascripts/plugin.js +0 -1
- data/layouts/theme/stylesheets/_header.scss.erb +0 -18
- data/lib/guard/marv/assets.rb +0 -33
- data/lib/guard/marv/folders.rb +0 -33
- data/lib/guard/marv/functions.rb +0 -34
- data/lib/guard/marv/templates.rb +0 -33
- data/lib/marv/builder.rb +0 -355
- data/lib/marv/error.rb +0 -8
- data/lib/marv/generator.rb +0 -140
- data/lib/marv/guard.rb +0 -68
- data/lib/marv/project.rb +0 -134
- data/lib/marv/server.rb +0 -284
- data/spec/lib/marv/project_spec.rb +0 -34
- data/spec/spec_helper.rb +0 -12
data/lib/marv/error.rb
DELETED
data/lib/marv/generator.rb
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
module Marv
|
2
|
-
class Generator
|
3
|
-
|
4
|
-
class << self
|
5
|
-
def run(project, layout, local_layout)
|
6
|
-
generator = self.new(project, layout, local_layout)
|
7
|
-
generator.run
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def initialize(project, layout, local_layout)
|
12
|
-
@project = project
|
13
|
-
@task = project.task
|
14
|
-
@layout = layout
|
15
|
-
@local = local_layout
|
16
|
-
end
|
17
|
-
|
18
|
-
def create_structure
|
19
|
-
# Create the build directory for Marv output
|
20
|
-
@task.empty_directory @project.build_path
|
21
|
-
|
22
|
-
source_paths = [
|
23
|
-
['assets', 'images'],
|
24
|
-
['assets', 'javascripts'],
|
25
|
-
['assets', 'stylesheets'],
|
26
|
-
|
27
|
-
['functions'],
|
28
|
-
['includes'],
|
29
|
-
|
30
|
-
['templates', 'pages'],
|
31
|
-
['templates', 'partials'],
|
32
|
-
]
|
33
|
-
|
34
|
-
# Build out Marv structure in the source directory
|
35
|
-
source_paths.each do |path|
|
36
|
-
@task.empty_directory File.join(@project.source_path, path)
|
37
|
-
end
|
38
|
-
|
39
|
-
self
|
40
|
-
end
|
41
|
-
|
42
|
-
def copy_assets
|
43
|
-
['stylesheets', 'javascripts', 'images'].each do |folder|
|
44
|
-
source = File.expand_path(File.join(self.layout_path, folder))
|
45
|
-
target = File.expand_path(File.join(@project.assets_path, folder))
|
46
|
-
|
47
|
-
render_directory(source, target)
|
48
|
-
end
|
49
|
-
|
50
|
-
self
|
51
|
-
end
|
52
|
-
|
53
|
-
def copy_folders
|
54
|
-
['templates', 'includes'].each do |folder|
|
55
|
-
source = File.expand_path(File.join(self.layout_path, folder))
|
56
|
-
target = File.expand_path(File.join(@project.source_path, folder))
|
57
|
-
|
58
|
-
render_directory(source, target)
|
59
|
-
end
|
60
|
-
|
61
|
-
self
|
62
|
-
end
|
63
|
-
|
64
|
-
def copy_functions
|
65
|
-
['functions.php', @project.project_php_file].each do |file|
|
66
|
-
source = File.expand_path(File.join(self.layout_path, 'functions', "#{file}.erb"))
|
67
|
-
if File.exist?(source)
|
68
|
-
target = File.expand_path(File.join(@project.source_path, 'functions', file))
|
69
|
-
write_template(source, target)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def layout_path
|
75
|
-
if @local
|
76
|
-
@layout_path ||= File.join(ENV['HOME'], '.marv', 'layouts', @layout)
|
77
|
-
else
|
78
|
-
@layout_path ||= File.join(Marv::ROOT, 'layouts', @layout)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def run
|
83
|
-
write_config
|
84
|
-
create_structure
|
85
|
-
copy_assets
|
86
|
-
copy_folders
|
87
|
-
copy_functions
|
88
|
-
|
89
|
-
return self
|
90
|
-
end
|
91
|
-
|
92
|
-
def write_config
|
93
|
-
unless File.exists?(@project.global_config_file)
|
94
|
-
@task.shell.mute do
|
95
|
-
@task.create_file(@project.global_config_file) do
|
96
|
-
"# Place your global configuration values here\n# config[:livereload] = true"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
write_template(['config', 'project-config.rb'], @project.config_file)
|
102
|
-
|
103
|
-
self
|
104
|
-
end
|
105
|
-
|
106
|
-
def write_template(source, target)
|
107
|
-
source = File.join(source)
|
108
|
-
template = File.expand_path(@task.find_in_source_paths((source)))
|
109
|
-
target = File.expand_path(File.join(target))
|
110
|
-
|
111
|
-
@task.create_file target do
|
112
|
-
@project.parse_erb(template)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
protected
|
117
|
-
|
118
|
-
def render_directory(source, target)
|
119
|
-
Dir.glob("#{source}/**/*") do |file|
|
120
|
-
unless File.directory?(file)
|
121
|
-
source_file = file.gsub(source, '')
|
122
|
-
target_file = File.join(target, source_file)
|
123
|
-
|
124
|
-
if source_file.end_with? ".erb"
|
125
|
-
target_file = target_file.slice(0..-5)
|
126
|
-
|
127
|
-
content = @project.parse_erb(file)
|
128
|
-
else
|
129
|
-
content = File.open(file).read
|
130
|
-
end
|
131
|
-
|
132
|
-
@task.create_file target_file do
|
133
|
-
content
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
140
|
-
end
|
data/lib/marv/guard.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'guard'
|
2
|
-
require 'guard/guard'
|
3
|
-
|
4
|
-
module Marv
|
5
|
-
module Guard
|
6
|
-
|
7
|
-
class << self
|
8
|
-
attr_accessor :project, :task, :builder
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.add_guard(&block)
|
12
|
-
@additional_guards ||= []
|
13
|
-
@additional_guards << block
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.start(project, task, options={}, livereload={})
|
17
|
-
@project = project
|
18
|
-
@task = task
|
19
|
-
@builder = Builder.new(project)
|
20
|
-
|
21
|
-
options_hash = ""
|
22
|
-
options.each do |k,v|
|
23
|
-
options_hash << ", :#{k} => '#{v}'"
|
24
|
-
end
|
25
|
-
|
26
|
-
assets_path = @project.assets_path.gsub(/#{@project.root}\//, '')
|
27
|
-
source_path = @project.source_path.gsub(/#{@project.root}\//, '')
|
28
|
-
config_file = @project.config_file.gsub(/#{@project.root}\//, '')
|
29
|
-
|
30
|
-
guardfile_contents = %Q{
|
31
|
-
guard 'marvconfig'#{options_hash} do
|
32
|
-
watch("#{config_file}")
|
33
|
-
end
|
34
|
-
guard 'marvassets' do
|
35
|
-
watch(%r{#{assets_path}/javascripts/*})
|
36
|
-
watch(%r{#{assets_path}/stylesheets/*})
|
37
|
-
watch(%r{#{assets_path}/images/*})
|
38
|
-
end
|
39
|
-
guard 'marvtemplates' do
|
40
|
-
watch(%r{#{source_path}/templates/*})
|
41
|
-
watch(%r{#{source_path}/partials/*})
|
42
|
-
end
|
43
|
-
guard 'marvfunctions' do
|
44
|
-
watch(%r{#{source_path}/functions/*})
|
45
|
-
watch(%r{#{source_path}/includes/*})
|
46
|
-
end
|
47
|
-
guard 'marvfolders' do
|
48
|
-
watch(%r{#{source_path}/*})
|
49
|
-
end
|
50
|
-
}
|
51
|
-
|
52
|
-
if @project.config[:livereload]
|
53
|
-
guardfile_contents << %Q{
|
54
|
-
guard 'livereload' do
|
55
|
-
watch(%r{#{source_path}/*})
|
56
|
-
end
|
57
|
-
}
|
58
|
-
end
|
59
|
-
|
60
|
-
(@additional_guards || []).each do |block|
|
61
|
-
result = block.call(options, livereload)
|
62
|
-
guardfile_contents << result unless result.nil?
|
63
|
-
end
|
64
|
-
::Guard.start({ :guardfile_contents => guardfile_contents }).join
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
data/lib/marv/project.rb
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
module Marv
|
4
|
-
class Project
|
5
|
-
|
6
|
-
class << self
|
7
|
-
def create(root, config, task, layout, local_layout)
|
8
|
-
root = File.expand_path(root)
|
9
|
-
|
10
|
-
project = self.new(root, task, config)
|
11
|
-
Generator.run(project, layout, local_layout)
|
12
|
-
|
13
|
-
project
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_accessor :root, :config, :task
|
18
|
-
|
19
|
-
def initialize(root, task, config={}, config_file=nil)
|
20
|
-
@root = File.expand_path(root)
|
21
|
-
@config = config || {}
|
22
|
-
@task = task
|
23
|
-
@config_file = config_file
|
24
|
-
|
25
|
-
self.load_config if @config.empty?
|
26
|
-
end
|
27
|
-
|
28
|
-
def assets_path
|
29
|
-
@assets_path ||= File.join(self.source_path, 'assets')
|
30
|
-
end
|
31
|
-
|
32
|
-
def build_path
|
33
|
-
File.join(self.root, '.watch', 'build')
|
34
|
-
end
|
35
|
-
|
36
|
-
def source_path
|
37
|
-
File.join(self.root, 'source')
|
38
|
-
end
|
39
|
-
|
40
|
-
def package_path
|
41
|
-
File.join(self.root, 'package')
|
42
|
-
end
|
43
|
-
|
44
|
-
def templates_path
|
45
|
-
File.join(self.source_path, 'templates')
|
46
|
-
end
|
47
|
-
|
48
|
-
def functions_path
|
49
|
-
File.join(self.source_path, 'functions')
|
50
|
-
end
|
51
|
-
|
52
|
-
def includes_path
|
53
|
-
File.join(self.source_path, 'includes')
|
54
|
-
end
|
55
|
-
|
56
|
-
def config_file
|
57
|
-
@config_file ||= File.join(self.root, 'config.rb')
|
58
|
-
end
|
59
|
-
|
60
|
-
def global_config_file
|
61
|
-
@global_config_file ||= File.join(ENV['HOME'], '.marv', 'config.rb')
|
62
|
-
end
|
63
|
-
|
64
|
-
# Create a symlink from source to the project build dir
|
65
|
-
def link(source)
|
66
|
-
source = File.expand_path(source)
|
67
|
-
|
68
|
-
unless File.writable?(File.dirname(source))
|
69
|
-
@task.say "Permission Denied!", :red
|
70
|
-
@task.say "You do not have write permissions for the destination folder"
|
71
|
-
abort
|
72
|
-
end
|
73
|
-
|
74
|
-
unless File.directory?(File.dirname(source))
|
75
|
-
raise Marv::LinkSourceDirNotFound
|
76
|
-
end
|
77
|
-
|
78
|
-
@task.link_file build_path, source
|
79
|
-
end
|
80
|
-
|
81
|
-
def project_id
|
82
|
-
File.basename(self.root).gsub(/\W/, '_')
|
83
|
-
end
|
84
|
-
|
85
|
-
def project_php_file
|
86
|
-
"#{File.basename(self.root).gsub(/\W/, '-').downcase}.php"
|
87
|
-
end
|
88
|
-
|
89
|
-
def load_config
|
90
|
-
config = {}
|
91
|
-
|
92
|
-
# Check for global (user) config.rb
|
93
|
-
if File.exists?(self.global_config_file)
|
94
|
-
config.merge!(load_ruby_config(self.global_config_file))
|
95
|
-
end
|
96
|
-
|
97
|
-
# Check for config.rb
|
98
|
-
if File.exists?(self.config_file)
|
99
|
-
config.merge!(load_ruby_config(self.config_file))
|
100
|
-
else
|
101
|
-
@task.say "Could not find the config file!", :red
|
102
|
-
@task.say "Are you sure you're in a marv project directory?"
|
103
|
-
abort
|
104
|
-
end
|
105
|
-
|
106
|
-
@config = config
|
107
|
-
end
|
108
|
-
|
109
|
-
def get_binding
|
110
|
-
binding
|
111
|
-
end
|
112
|
-
|
113
|
-
def parse_erb(file)
|
114
|
-
ERB.new(::File.binread(file), nil, '-', '@output_buffer').result(binding)
|
115
|
-
end
|
116
|
-
|
117
|
-
private
|
118
|
-
|
119
|
-
def load_ruby_config(file)
|
120
|
-
config = {}
|
121
|
-
|
122
|
-
begin
|
123
|
-
# Config file is just executed as straight ruby
|
124
|
-
eval(File.read(file))
|
125
|
-
rescue Exception => e
|
126
|
-
@task.say "Error while evaluating config file:"
|
127
|
-
@task.say e.message, :red
|
128
|
-
end
|
129
|
-
|
130
|
-
return config
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
134
|
-
end
|
data/lib/marv/server.rb
DELETED
@@ -1,284 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'mysql2'
|
3
|
-
require 'childprocess'
|
4
|
-
|
5
|
-
module Marv
|
6
|
-
class Server
|
7
|
-
|
8
|
-
def initialize(name, config, options)
|
9
|
-
@task = config
|
10
|
-
|
11
|
-
# Deploy variables
|
12
|
-
@server_name = name
|
13
|
-
@server_path = server_path
|
14
|
-
@db_name = 'marv_'+name.gsub(/\W/, '_').downcase
|
15
|
-
|
16
|
-
# CLI Options
|
17
|
-
unless options.nil?
|
18
|
-
if options[:password] == "required"
|
19
|
-
@task.say "Mysql password is required. Aborting...", :red
|
20
|
-
abort
|
21
|
-
end
|
22
|
-
|
23
|
-
@wp_version = options[:version]
|
24
|
-
@db_user = options[:user]
|
25
|
-
@db_password = options[:password]
|
26
|
-
@db_host = options[:host]
|
27
|
-
@db_port = options[:port]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def servers_root
|
32
|
-
File.join(ENV['HOME'], '.marv', 'servers')
|
33
|
-
end
|
34
|
-
|
35
|
-
def server_path
|
36
|
-
File.join(ENV['HOME'], '.marv', 'servers', @server_name)
|
37
|
-
end
|
38
|
-
|
39
|
-
def db_name
|
40
|
-
@db_name
|
41
|
-
end
|
42
|
-
|
43
|
-
def db_password
|
44
|
-
@db_password
|
45
|
-
end
|
46
|
-
|
47
|
-
def db_host
|
48
|
-
@db_host
|
49
|
-
end
|
50
|
-
|
51
|
-
def run_php_server
|
52
|
-
# Setup server
|
53
|
-
server = TCPServer.new('127.0.0.1', 0)
|
54
|
-
port = server.addr[1]
|
55
|
-
server.close()
|
56
|
-
|
57
|
-
# Run PHP server
|
58
|
-
::Dir.chdir @server_path
|
59
|
-
@php = ChildProcess.build 'php', '-S', "localhost:#{port}", 'router.php'
|
60
|
-
@php.start
|
61
|
-
|
62
|
-
# Write PHP proccess id to file
|
63
|
-
File.open(File.join(@server_path, 'php.pid'), 'w') do |file|
|
64
|
-
file.write(@php.pid)
|
65
|
-
end
|
66
|
-
|
67
|
-
@task.say "Visit http://localhost:#{port}"
|
68
|
-
end
|
69
|
-
|
70
|
-
def create_server
|
71
|
-
create_server_directory
|
72
|
-
|
73
|
-
copy_wordpress_files
|
74
|
-
add_config_file('router.php.erb', 'router.php')
|
75
|
-
|
76
|
-
create_server_database
|
77
|
-
add_config_file('wp-config.php.erb', 'wp-config.php')
|
78
|
-
|
79
|
-
add_global_content
|
80
|
-
|
81
|
-
@task.say "Server #{@server_name} created successfuly!", :green
|
82
|
-
@task.say "Start server using marv server #{@server_name} --start"
|
83
|
-
exit
|
84
|
-
end
|
85
|
-
|
86
|
-
def start_server
|
87
|
-
begin
|
88
|
-
update_global_projects
|
89
|
-
run_php_server
|
90
|
-
rescue Exception => e
|
91
|
-
@task.say "Error while starting server:"
|
92
|
-
@task.say e.message + "\n", :red
|
93
|
-
end
|
94
|
-
@task.say "Server #{@server_name} running", :green
|
95
|
-
end
|
96
|
-
|
97
|
-
def stop_server
|
98
|
-
begin
|
99
|
-
@task.shell.mute do
|
100
|
-
php_pid_file = File.join(@server_path, 'php.pid')
|
101
|
-
|
102
|
-
if File.exists?(php_pid_file)
|
103
|
-
php_pid = File.read(php_pid_file).to_i
|
104
|
-
|
105
|
-
Process.kill('KILL', php_pid)
|
106
|
-
@task.say "Server #{@server_name} stopped", :yellow
|
107
|
-
else
|
108
|
-
@task.say "Server #{@server_name} is not running", :red
|
109
|
-
end
|
110
|
-
end
|
111
|
-
rescue Exception => e
|
112
|
-
@task.say "Error while stoping server:"
|
113
|
-
@task.say e.message + "\n", :red
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def restart_server
|
118
|
-
stop_server
|
119
|
-
start_server
|
120
|
-
end
|
121
|
-
|
122
|
-
def remove_server
|
123
|
-
@task.say "Removing server..."
|
124
|
-
@task.shell.mute do
|
125
|
-
stop_server
|
126
|
-
end
|
127
|
-
@task.say "Removing server files..."
|
128
|
-
|
129
|
-
begin
|
130
|
-
@task.shell.mute do
|
131
|
-
FileUtils.rm_r(@server_path)
|
132
|
-
end
|
133
|
-
@task.say "Server files removed", :green
|
134
|
-
rescue Exception => e
|
135
|
-
@task.say "Error while removing server files:"
|
136
|
-
@task.say e.message + "\n", :red
|
137
|
-
end
|
138
|
-
|
139
|
-
remove_server_database
|
140
|
-
|
141
|
-
@task.say "Server successfuly removed!", :green
|
142
|
-
exit
|
143
|
-
end
|
144
|
-
|
145
|
-
private
|
146
|
-
|
147
|
-
# Creates a directory for a new server
|
148
|
-
def create_server_directory
|
149
|
-
# Create dir
|
150
|
-
unless ::File.exist?(self.servers_root)
|
151
|
-
::Dir.mkdir(servers_root)
|
152
|
-
end
|
153
|
-
# Exit if dir exists
|
154
|
-
if ::File.exist?(@server_path)
|
155
|
-
@task.say "A server with name #{@server_name} already exists", :red
|
156
|
-
exit
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
# Downloads WordPress from wordpress.org
|
161
|
-
def download_wordpress
|
162
|
-
package = "/tmp/wordpress-#{@wp_version}.tar.gz"
|
163
|
-
|
164
|
-
# Download package file
|
165
|
-
@task.shell.mute do
|
166
|
-
unless ::File.exists?(package)
|
167
|
-
@task.get "https://wordpress.org/wordpress-#{@wp_version}.tar.gz" do |content|
|
168
|
-
@task.create_file package, content
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
# Return package file
|
174
|
-
package
|
175
|
-
end
|
176
|
-
|
177
|
-
# Copy WordPress files
|
178
|
-
def copy_wordpress_files
|
179
|
-
package = download_wordpress
|
180
|
-
|
181
|
-
# Get package content and extract to dir
|
182
|
-
tmp_dir = "/tmp/wordpress-latest-#{Time.now.to_i}"
|
183
|
-
# Create temporary dir
|
184
|
-
unless ::File.exists?(tmp_dir)
|
185
|
-
Dir.mkdir(tmp_dir)
|
186
|
-
end
|
187
|
-
|
188
|
-
# Extract package to temporary dir
|
189
|
-
@task.shell.mute do
|
190
|
-
@task.run "cd #{tmp_dir};tar -xzf #{package}"
|
191
|
-
@task.directory "#{tmp_dir}/wordpress", @server_path
|
192
|
-
end
|
193
|
-
|
194
|
-
# Remove temporary dir
|
195
|
-
if ::File.exists?(tmp_dir)
|
196
|
-
FileUtils.rm_r(tmp_dir)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
def add_config_file(source, target)
|
201
|
-
unless File.exists?(target)
|
202
|
-
config = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'layouts', 'config', source))
|
203
|
-
config_template = ERB.new(::File.binread(config), nil, '-', '@output_buffer')
|
204
|
-
|
205
|
-
File.open(File.join(@server_path, target), 'w') do |file|
|
206
|
-
file.write(config_template.result(binding))
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
def create_server_database
|
212
|
-
begin
|
213
|
-
@task.shell.mute do
|
214
|
-
client = Mysql2::Client.new(:host => @db_host, :port => @db_port, :username => @db_user, :password => @db_password)
|
215
|
-
client.query("CREATE DATABASE IF NOT EXISTS #{@db_name}")
|
216
|
-
client.query("GRANT ALL PRIVILEGES ON #{@db_name}.* TO '#{@db_user}'@'#{@db_host}'")
|
217
|
-
client.query("FLUSH PRIVILEGES")
|
218
|
-
client.close
|
219
|
-
end
|
220
|
-
rescue Exception => e
|
221
|
-
@task.say "Error while creating Mysql database:"
|
222
|
-
@task.say e.message + "\n", :red
|
223
|
-
exit
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
def remove_server_database
|
228
|
-
begin
|
229
|
-
@task.shell.mute do
|
230
|
-
client = Mysql2::Client.new(:host => @db_host, :port => @db_port, :username => @db_user, :password => @db_password)
|
231
|
-
client.query("DROP DATABASE IF EXISTS #{@db_name}")
|
232
|
-
client.query("REVOKE ALL PRIVILEGES ON #{@db_name}.* FROM '#{@db_user}'@'#{@db_host}'")
|
233
|
-
client.query("FLUSH PRIVILEGES")
|
234
|
-
client.close
|
235
|
-
end
|
236
|
-
rescue Exception => e
|
237
|
-
@task.say "Error while removing Mysql database:"
|
238
|
-
@task.say e.message + "\n", :red
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
def add_global_content
|
243
|
-
@task.shell.mute do
|
244
|
-
global = File.join(ENV['HOME'], '.marv')
|
245
|
-
themes = Dir.glob(File.join(global, 'themes', '*'))
|
246
|
-
|
247
|
-
themes.each do |theme|
|
248
|
-
@task.create_link File.join(@server_path, 'wp-content', 'themes', File.basename(theme)), theme
|
249
|
-
end
|
250
|
-
|
251
|
-
plugins = Dir.glob(File.join(global, 'plugins', '*'))
|
252
|
-
|
253
|
-
plugins.each do |plugin|
|
254
|
-
@task.create_link File.join(@server_path, 'wp-content', 'plugins', File.basename(plugin)), plugin
|
255
|
-
end
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
def update_global_folders(dir, folders)
|
260
|
-
begin
|
261
|
-
folders.each do |folder|
|
262
|
-
if File.symlink?(folder)
|
263
|
-
unless File.exists?(folder)
|
264
|
-
File.delete(folder)
|
265
|
-
File.delete(File.join(ENV['HOME'], '.marv', dir, File.basename(folder)))
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
rescue Exception => e
|
270
|
-
@task.say "Error while updating global projects:"
|
271
|
-
@task.say e.message + "\n", :red
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
def update_global_projects
|
276
|
-
themes = Dir.glob(File.join(@server_path, 'wp-content', 'themes', '*'))
|
277
|
-
update_global_folders('themes', themes)
|
278
|
-
|
279
|
-
plugins = Dir.glob(File.join(@server_path, 'wp-content', 'plugins', '*'))
|
280
|
-
update_global_folders('plugins', plugins)
|
281
|
-
end
|
282
|
-
|
283
|
-
end
|
284
|
-
end
|