marv 0.6.5 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,9 @@
1
+ require 'marv/cli/base'
1
2
  require 'marv/project/project'
2
3
 
3
4
  module Marv
4
5
  module CLI
5
- class Project < Thor
6
-
7
- def self.source_root
8
- ::File.expand_path(::File.join(Marv.root, 'layouts'))
9
- end
10
-
11
- include Thor::Actions
6
+ class Project < Base
12
7
 
13
8
  # Create a new Marv project
14
9
  desc "create DIRECTORY", "Creates a Marv project into specified directory"
@@ -38,7 +33,7 @@ module Marv
38
33
  end
39
34
 
40
35
  # Build a Marv project to a directory
41
- desc "build DIRECTORY", "Build your theme into specified directory"
36
+ desc "build DIRECTORY", "Build your project into specified directory"
42
37
  method_option :config, :type => :string, :desc => "Name of alternate config file"
43
38
  def build(dir='build')
44
39
  project = Marv::Project::Project.new(self, '.', options[:config])
@@ -58,4 +53,4 @@ module Marv
58
53
 
59
54
  end
60
55
  end
61
- end
56
+ end
@@ -1,14 +1,9 @@
1
+ require 'marv/cli/base'
1
2
  require 'marv/server/server'
2
3
 
3
4
  module Marv
4
5
  module CLI
5
- class Server < Thor
6
-
7
- def self.source_root
8
- ::File.expand_path(::File.join(Marv.root, 'layouts'))
9
- end
10
-
11
- include Thor::Actions
6
+ class Server < Base
12
7
 
13
8
  # List all Marv servers
14
9
  desc "list", "List all Marv servers"
@@ -16,31 +11,32 @@ module Marv
16
11
  servers = Marv::Global.new(self).servers
17
12
 
18
13
  if dir == 'all'
19
- say "Available marv servers:"
20
- servers.each_with_index do |server, index|
21
- say "#{index + 1}. #{server}", :cyan
14
+ say_info "Available marv servers:", true
15
+ servers.each_with_index do |server_dir, index|
16
+ server = Marv::Server::Server.new(self, server_dir)
17
+ say_message "#{index + 1}. #{server.name} [http://#{server.host}:#{server.port}]", false
22
18
  end
23
19
 
24
20
  if servers.empty?
25
- say "No servers found", :yellow
21
+ say_warning "No servers found", false
26
22
  end
27
23
  end
28
24
 
29
25
  if dir == 'running'
30
26
  index = 0
31
- say "Running marv servers:"
32
- servers.each do |dir|
33
- server = Marv::Server::Server.new(self, dir)
27
+ say_success "Running marv servers:", true
28
+ servers.each do |server_dir|
29
+ server = Marv::Server::Server.new(self, server_dir)
34
30
  action = Marv::Server::Actions.new(server)
35
31
 
36
32
  if action.is_server_running?
37
- say "#{index + 1}. #{server.name} [http://#{server.host}:#{server.port}]", :green
33
+ say_message "#{index + 1}. #{server.name} [http://#{server.host}:#{server.port}]", false
38
34
  index += 1
39
35
  end
40
36
  end
41
37
 
42
38
  if index == 0
43
- say "No running servers found", :yellow
39
+ say_warning "No running servers found", false
44
40
  end
45
41
  end
46
42
  end
@@ -66,8 +62,9 @@ module Marv
66
62
 
67
63
  # Create server if it does not exist
68
64
  unless ::File.directory?(::File.join(servers_path, dir))
69
- say "Server #{dir} does not exist.", :yellow
70
- if yes?("Would you like to create the server?")
65
+ say_warning "Server #{dir} does not exist."
66
+ if said_yes?("Would you like to create the server?")
67
+ say_empty
71
68
  create(dir)
72
69
  end
73
70
  end
@@ -85,8 +82,8 @@ module Marv
85
82
  if dir == 'all'
86
83
  servers = Marv::Global.new(self).servers
87
84
 
88
- servers.each do |dir|
89
- server = Marv::Server::Server.new(self, dir)
85
+ servers.each do |server_dir|
86
+ server = Marv::Server::Server.new(self, server_dir)
90
87
  action = Marv::Server::Actions.new(server)
91
88
 
92
89
  if action.is_server_running?
@@ -114,4 +111,4 @@ module Marv
114
111
 
115
112
  end
116
113
  end
117
- end
114
+ end
@@ -3,11 +3,15 @@ module Marv
3
3
 
4
4
  attr_accessor :config, :path, :servers, :plugins, :themes, :layouts
5
5
 
6
- def initialize(task)
6
+ def initialize(task, from_command=false)
7
7
  @task = task
8
8
 
9
9
  create_global_folders
10
- create_global_config
10
+
11
+ @current = current_options
12
+ @default = default_options
13
+
14
+ generate_config(from_command)
11
15
 
12
16
  @path = global_path
13
17
  @config = global_config
@@ -22,6 +26,49 @@ module Marv
22
26
  end
23
27
  end
24
28
 
29
+ # Generate configuration
30
+ def generate_config(from_command=false)
31
+ if from_command
32
+ ::File.exists?(config_file) ? reconfigure : configure(from_command)
33
+ else
34
+ configure unless ::File.exists?(config_file)
35
+ end
36
+ end
37
+
38
+ # Default config options
39
+ def default_options
40
+ defaults = {
41
+ :server_host => "localhost",
42
+ :server_port => "3000",
43
+ :db_user => "root",
44
+ :db_password => "root",
45
+ :db_host => "localhost",
46
+ :db_port => "3306",
47
+ :wp_version => "latest",
48
+ :uri => "https://wordpress.org",
49
+ :author => username,
50
+ :author_uri => "https://wordpress.org",
51
+ :license_name => "GPLv3",
52
+ :license_uri => "http://www.gnu.org/licenses/gpl.html"
53
+ }
54
+
55
+ defaults.merge(@current)
56
+ end
57
+
58
+ # Get current options
59
+ def current_options
60
+ if ::File.exists?(config_file)
61
+ global_config.reject { |opt| opt.nil? || opt == '' }
62
+ else
63
+ {}
64
+ end
65
+ end
66
+
67
+ # Get user name
68
+ def username
69
+ ENV['USERNAME'] || 'marv'
70
+ end
71
+
25
72
  # Global Marv folder path
26
73
  def global_path
27
74
  ::File.join(ENV['HOME'], '.marv')
@@ -34,7 +81,11 @@ module Marv
34
81
 
35
82
  # Load global config file
36
83
  def global_config
37
- load_ruby_config(config_file)
84
+ if ::File.exists?(config_file)
85
+ load_ruby_config(config_file)
86
+ else
87
+ {}
88
+ end
38
89
  end
39
90
 
40
91
  # Servers folder path
@@ -123,13 +174,28 @@ module Marv
123
174
  end
124
175
  end
125
176
 
177
+ # Project details
178
+ def ask_project_details
179
+ options = {}
180
+
181
+ if @task.said_change?("Do you want to set default project details?")
182
+ options[:uri] = @task.ask_option "Default project URI:", :default => @default[:uri]
183
+ options[:author] = @task.ask_option "Default project author:", :default => @default[:author]
184
+ options[:author_uri] = @task.ask_option "Default project author URI:", :default => @default[:author_uri]
185
+ options[:license_name] = @task.ask_option "Default project license name:", :default => @default[:license_name]
186
+ options[:license_uri] = @task.ask_option "Default project license URI:", :default => @default[:license_uri]
187
+ end
188
+
189
+ return options
190
+ end
191
+
126
192
  # Server details
127
193
  def ask_server_details
128
194
  options = {}
129
195
 
130
- if @task.yes?("Do you want to set default server settings?")
131
- options[:server_host] = @task.ask "Default host for servers?", :default => "localhost"
132
- options[:server_port] = @task.ask "Default port for servers?", :default => "3000"
196
+ if @task.said_change?("Do you want to set default server settings?")
197
+ options[:server_host] = @task.ask_option "Default host for servers:", :default => @default[:server_host]
198
+ options[:server_port] = @task.ask_option "Default port for servers:", :default => @default[:server_port]
133
199
  end
134
200
 
135
201
  return options
@@ -139,11 +205,11 @@ module Marv
139
205
  def ask_database_details
140
206
  options = {}
141
207
 
142
- if @task.yes?("Do you want to set default database settings?")
143
- options[:db_user] = @task.ask "Default database username?", :default => "root"
144
- options[:db_password] = @task.ask "Default database password?", :default => "root"
145
- options[:db_host] = @task.ask "Default database host?", :default => "localhost"
146
- options[:db_port] = @task.ask "Default database port?", :default => "3306"
208
+ if @task.said_change?("Do you want to set default database settings?")
209
+ options[:db_user] = @task.ask_option "Default database username:", :default => @default[:db_user]
210
+ options[:db_password] = @task.ask_option "Default database password:", :default => @default[:db_password]
211
+ options[:db_host] = @task.ask_option "Default database host:", :default => @default[:db_host]
212
+ options[:db_port] = @task.ask_option "Default database port:", :default => @default[:db_port]
147
213
  end
148
214
 
149
215
  return options
@@ -153,8 +219,8 @@ module Marv
153
219
  def ask_wordpress_details
154
220
  options = {}
155
221
 
156
- if @task.yes?("Do you want to set default WordPress version?")
157
- options[:wp_version] = @task.ask "Default WordPress version?", :default => "latest"
222
+ if @task.said_change?("Do you want to set default WordPress version?")
223
+ options[:wp_version] = @task.ask_option "Default WordPress version?", :default => @default[:wp_version]
158
224
  end
159
225
 
160
226
  return options
@@ -167,18 +233,9 @@ module Marv
167
233
 
168
234
  # Ask global options
169
235
  def ask_global_options
170
- options = {}
171
-
172
- @task.say "This will create a new global configuration file.", :cyan
173
-
174
- if @task.yes?("Do you want to set default project details?")
175
- options[:uri] = @task.ask "Default project URI"
176
- options[:author] = @task.ask "Default project author"
177
- options[:author_uri] = @task.ask "Default project author URI"
178
- options[:license_name] = @task.ask "Default project license name"
179
- options[:license_uri] = @task.ask "Default project license URI"
180
- end
236
+ options = @default
181
237
 
238
+ options.merge!(ask_project_details)
182
239
  options.merge!(ask_server_details)
183
240
  options.merge!(ask_database_details)
184
241
  options.merge!(ask_wordpress_details)
@@ -189,22 +246,43 @@ module Marv
189
246
  # Create global config
190
247
  def create_global_config
191
248
  unless ::File.exists?(config_file)
249
+ @task.shell.mute do
250
+ layout = ::File.join(Marv.root, 'layouts', 'config', 'global.rb')
251
+ filepath = ::File.join(global_path, 'config.rb')
252
+
253
+ template layout, filepath, instance_eval('binding')
254
+ end
255
+ end
256
+ end
257
+
258
+ # Configure Marv global options
259
+ def configure(from_command=false)
260
+ @task.say_warning "You do not have a global configuration file.", false
261
+ @task.say_info "This will create a new global configuration file.", true
262
+
263
+ if @task.said_change?("Do you want to change the default options?")
192
264
  ask_global_options
193
- template ::File.join(Marv.root, 'layouts', 'config', 'global.rb'), ::File.join(global_path, 'config.rb'), instance_eval('binding')
194
265
  end
266
+
267
+ @options = @default
268
+ create_global_config
269
+
270
+ @task.say_success "Global configuration created successfully.", !from_command, true
195
271
  end
196
272
 
197
273
  # Reconfig Marv global options
198
274
  def reconfigure
199
- @task.say "This will overwrite your global configuration file.", :cyan
275
+ @task.say_warning "This will overwrite your global configuration file."
200
276
 
201
- if @task.yes?("Do you want to continue?")
277
+ if @task.said_change?("Do you want to continue?")
202
278
  @task.shell.mute do
279
+ ask_global_options
280
+
203
281
  @task.remove_file config_file
282
+ create_global_config
204
283
  end
205
284
 
206
- create_global_folders
207
- create_global_config
285
+ @task.say_success "Global configuration updated successfully.", false, true
208
286
  end
209
287
  end
210
288
 
@@ -248,8 +326,7 @@ module Marv
248
326
  # Config file is just executed as straight ruby
249
327
  eval(::File.read(file))
250
328
  rescue Exception => e
251
- @task.say "Error while evaluating config file:"
252
- @task.say e.message, :red
329
+ @task.say_error "Error while evaluating config file:", e.message
253
330
  end
254
331
 
255
332
  return config
@@ -282,4 +359,4 @@ module Marv
282
359
  end
283
360
 
284
361
  end
285
- end
362
+ end
@@ -16,22 +16,28 @@ module Marv
16
16
  def link(dir)
17
17
  @link_dir = dir
18
18
 
19
+ @task.say_warning "This will link project #{@project.project_id} to server #{dir}."
20
+
19
21
  link_options
20
22
  link_target
23
+
24
+ @task.say_empty
21
25
  create_link
22
26
  end
23
27
 
24
28
  # Packgage project
25
29
  def package(filename)
26
30
  @package_name = filename
31
+ pkg_name = filename || get_package_name
27
32
 
33
+ @task.say_warning "This will package project #{@project.project_id} as #{pkg_name}.zip."
28
34
  create_package
29
35
  end
30
36
 
31
37
  # Ask for link details
32
38
  def link_options
33
39
  options = {}
34
- options[:folder] = @task.ask "Where do you want to link your project?", :limited_to => ["themes", "plugins"], :default => "themes"
40
+ options[:folder] = @task.ask_input "Where do you want to link your project?", :limited_to => ["themes", "plugins"], :default => "themes"
35
41
 
36
42
  @link_options = options
37
43
  end
@@ -70,8 +76,8 @@ module Marv
70
76
  target = link_global unless link_global.nil?
71
77
 
72
78
  if target.nil?
73
- @task.say "Destination server does not exist!", :red
74
- exit
79
+ @task.say_error "Destination server does not exist!", nil, false, true
80
+ abort
75
81
  end
76
82
 
77
83
  @link_target = target
@@ -88,8 +94,8 @@ module Marv
88
94
  begin
89
95
  @task.create_link @link_target, @project.build_path
90
96
  rescue Exception => e
91
- @task.say "An error occured while creating project link", :red
92
- @task.say e.message
97
+ @task.say_error "An error occured while creating project link", e.message, false. true
98
+ abort
93
99
  end
94
100
  end
95
101
 
@@ -115,10 +121,15 @@ module Marv
115
121
  # Set the package file name
116
122
  def set_package_filename
117
123
  if @package_name.nil?
118
- @package_name = ::File.basename(@project.root)
124
+ @package_name = get_package_name
119
125
  end
120
126
  end
121
127
 
128
+ # Get package name
129
+ def get_package_name
130
+ ::File.basename(@project.root)
131
+ end
132
+
122
133
  # Built to a temporary directory
123
134
  def build_to_temp_dir
124
135
  @builder.build_project
@@ -35,13 +35,20 @@ module Marv
35
35
 
36
36
  # Build project to a directory
37
37
  def build_to(dir)
38
- build_project
39
- # Remove build directory
40
- @task.shell.mute do
41
- @task.remove_dir ::File.expand_path(dir)
38
+ @task.say_warning "This will build project #{@project.project_id} in directory #{dir}."
39
+
40
+ begin
41
+ build_project
42
+ # Remove build directory
43
+ @task.shell.mute do
44
+ @task.remove_dir ::File.expand_path(dir)
45
+ end
46
+ # Copy files from .watch/build directory
47
+ @task.directory @project.build_path, ::File.expand_path(dir)
48
+ rescue Exception => e
49
+ @task.say_error "There was an error while building the project:", e.message, false
50
+ abort
42
51
  end
43
- # Copy files from .watch/build directory
44
- @task.directory @project.build_path, ::File.expand_path(dir)
45
52
  end
46
53
 
47
54
  # Clean build directory
@@ -53,4 +60,4 @@ module Marv
53
60
 
54
61
  end
55
62
  end
56
- end
63
+ end
@@ -72,8 +72,7 @@ module Marv
72
72
  def print_asset_error(asset, message)
73
73
  destination = ::File.join(@project.build_path, asset)
74
74
 
75
- @task.say "Error while building #{asset.last}:"
76
- @task.say message, :red
75
+ @task.say_error "Error while building #{asset.last}:", message
77
76
 
78
77
  @task.shell.mute do
79
78
  @task.create_file destination unless ::File.exists?(destination)