marv 0.6.5 → 0.7.0

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.
@@ -1,5 +1,3 @@
1
- gem 'tilt', '!= 1.3', '~> 1.1'
2
-
3
1
  require 'tilt'
4
2
 
5
3
  module Tilt
@@ -23,20 +23,20 @@ module Marv
23
23
  def project_options
24
24
  # Check if project exists and abort
25
25
  if ::File.directory?(@path)
26
- @task.say "Project already exists", :red
26
+ @task.say_error "Project already exists", nil, false
27
27
  abort
28
28
  end
29
29
 
30
- @task.say "This will create a new project.", :cyan
31
- @task.say "Please enter project details below."
30
+ @task.say_info "This will create a new project."
31
+ @task.say_warning "Please enter project details below."
32
32
 
33
33
  # Get project options
34
34
  options = {}
35
35
 
36
- options[:name] = @task.ask "Enter project name", :default => @global.config[:name]
37
- options[:uri] = @task.ask "Enter project URI", :default => @global.config[:uri]
38
- options[:version] = @task.ask "Enter project version", :default => @global.config[:version]
39
- options[:description] = @task.ask "Enter project description", :default => @global.config[:description]
36
+ options[:name] = @task.ask_input "Enter project name:", :default => @global.config.fetch(:name, @dir)
37
+ options[:uri] = @task.ask_input "Enter project URI:", :default => @global.config[:uri]
38
+ options[:version] = @task.ask_input "Enter project version:", :default => @global.config.fetch(:version, '0.1.0')
39
+ options[:description] = @task.ask_input "Enter project description:", :default => @global.config.fetch(:description, 'Created with Marv')
40
40
 
41
41
  options.merge!(ask_author_details)
42
42
  options.merge!(ask_project_layout)
@@ -48,10 +48,10 @@ module Marv
48
48
  def ask_author_details
49
49
  options = {}
50
50
 
51
- options[:author] = @task.ask "Enter project author", :default => @global.config[:author]
52
- options[:author_uri] = @task.ask "Enter project author URI", :default => @global.config[:author_uri]
53
- options[:license_name] = @task.ask "Enter project license name", :default => @global.config[:license_name]
54
- options[:license_uri] = @task.ask "Enter project license URI", :default => @global.config[:license_uri]
51
+ options[:author] = @task.ask_input "Enter project author:", :default => @global.config[:author]
52
+ options[:author_uri] = @task.ask_input "Enter project author URI:", :default => @global.config[:author_uri]
53
+ options[:license_name] = @task.ask_input "Enter project license name:", :default => @global.config[:license_name]
54
+ options[:license_uri] = @task.ask_input "Enter project license URI:", :default => @global.config[:license_uri]
55
55
 
56
56
  return options
57
57
  end
@@ -60,17 +60,30 @@ module Marv
60
60
  def ask_project_layout
61
61
  options = {}
62
62
 
63
- if @task.yes?("Do you want to use a local layout?")
64
- options[:local_layout] = true
65
- options[:layout] = @task.ask "Which layout do you want to use?", :limited_to => @global.layouts
63
+ if @global.layouts.empty?
64
+ options.merge!(ask_builtin_project_layout)
66
65
  else
67
- options[:local_layout] = false
68
- options[:layout] = @task.ask "Which layout do you want to use?", :limited_to => ["theme", "plugin"], :default => "theme"
66
+ if @task.said_yes?("Do you want to use a local layout?")
67
+ options[:local_layout] = true
68
+ options[:layout] = @task.ask_input "Which layout do you want to use?", :limited_to => @global.layouts
69
+ else
70
+ options.merge!(ask_builtin_project_layout)
71
+ end
69
72
  end
70
73
 
71
74
  return options
72
75
  end
73
76
 
77
+ # Ask builtin project layout
78
+ def ask_builtin_project_layout
79
+ options = {}
80
+
81
+ options[:local_layout] = false
82
+ options[:layout] = @task.ask_input "Which layout do you want to use?", :limited_to => ["theme", "plugin"], :default => "theme"
83
+
84
+ return options
85
+ end
86
+
74
87
  # Choosen layout path
75
88
  def layout_path
76
89
  layout = ::File.expand_path(::File.join(Marv.root, 'layouts', @options[:layout]))
@@ -129,6 +142,8 @@ module Marv
129
142
 
130
143
  # Create a new project
131
144
  def create_project
145
+ @task.say_empty(2)
146
+
132
147
  create_project_dirs
133
148
  create_config_file
134
149
  parse_layout_files
@@ -1,9 +1,9 @@
1
- gem 'guard', '~> 2.8', '< 2.9'
2
-
3
1
  require 'guard'
4
2
  require 'guard/plugin'
5
3
 
6
4
  # Marv Guard plugins
5
+ require 'marv/project/guard/pry'
6
+ require 'marv/project/guard/commander'
7
7
  require 'marv/project/guard/assets'
8
8
  require 'marv/project/guard/config'
9
9
  require 'marv/project/guard/functions'
@@ -0,0 +1,14 @@
1
+ module Guard
2
+ module Commander
3
+
4
+ # Stop proccess
5
+ def stop
6
+ listener.stop
7
+ interactor.background
8
+ ::Guard::UI.debug "Guard stops all plugins"
9
+ runner.run(:stop)
10
+ ::Guard::Notifier.turn_off
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,41 @@
1
+ module Guard
2
+ module Jobs
3
+ class PryWrapper < Base
4
+
5
+ private
6
+
7
+ attr_reader :thread
8
+
9
+ # Colorizes message using Thor Color Util
10
+ #
11
+ def _colorize(text, color)
12
+ Marv.colorize(text, color)
13
+ end
14
+
15
+ # Configures the pry prompt to see `guard` instead of
16
+ # `pry`.
17
+ #
18
+ def _configure_prompt
19
+ Pry.config.prompt = [_prompt(_colorize("\u00BB", :green)), _prompt(_colorize("*", :yellow))]
20
+ end
21
+
22
+ # Returns a proc that will return itself a string ending with the given
23
+ # `ending_char` when called.
24
+ #
25
+ def _prompt(ending_char)
26
+ proc do |target_self, nest_level, pry|
27
+ history = pry.input_ring.size
28
+ process = ::Guard.listener.paused? ? _colorize("pause", :yellow) : _colorize("marv", :green)
29
+ level = ":#{nest_level}" unless nest_level.zero?
30
+ hist_text = _colorize("[#{history}]", :yellow)
31
+ clip_text = _colorize("(#{_clip_name(target_self)})", :cyan)
32
+ level_text = _colorize("#{level}", :cyan)
33
+ path_text = _colorize(Dir.pwd.sub(Dir.home, '~'), :magenta)
34
+
35
+ "#{hist_text} #{_scope_for_prompt}#{process} #{path_text} #{clip_text}#{level_text} #{ending_char} "
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -106,8 +106,7 @@ module Marv
106
106
  if ::File.exists?(@config_file)
107
107
  config_file = @global.load_ruby_config(@config_file)
108
108
  else
109
- @task.say "Could not find the config file!", :red
110
- @task.say "Are you sure you're in a marv project directory?"
109
+ @task.say_error "Could not find the config file!", "Are you sure you're in a marv project directory?", false
111
110
  abort
112
111
  end
113
112
 
@@ -146,4 +145,4 @@ module Marv
146
145
 
147
146
  end
148
147
  end
149
- end
148
+ end
@@ -1,4 +1,4 @@
1
- require 'socket'
1
+ require 'net/http'
2
2
  require 'childprocess'
3
3
 
4
4
  module Marv
@@ -15,22 +15,23 @@ module Marv
15
15
  end
16
16
 
17
17
  # Initialize server start
18
- def start
18
+ def start(from_command=true)
19
19
  if is_server_running?
20
- @task.say "Server is already running", :yellow
21
- exit
20
+ @task.say_warning "Server is already running.", false
21
+ abort
22
22
  end
23
23
 
24
- unless is_port_available?
25
- @task.say "Port is not available!", :yellow
24
+ unless is_port_available?(@server.host, @server.port)
25
+ @task.say_warning "Port is not available!", false, true
26
26
  change_server_port
27
27
  end
28
28
 
29
- run_server
29
+ run_server(from_command)
30
30
  end
31
31
 
32
32
  # Initialize server stop
33
- def stop
33
+ def stop(message=true)
34
+ abort_noexist
34
35
  pid_file = ::File.join(@path, 'php.pid')
35
36
 
36
37
  begin
@@ -38,40 +39,47 @@ module Marv
38
39
  pid = ::File.read(pid_file).to_i
39
40
 
40
41
  ::Process.kill('KILL', pid)
41
- @task.say "Server #{@name} stopped", :yellow
42
+ @task.say_warning("Server #{@name} stopped.", false) if message
42
43
  end
43
44
  rescue
44
- @task.say "Server #{@name} is not running", :yellow
45
+ @task.say_warning("Server #{@name} is not running.", false) if message
45
46
  end
46
47
  end
47
48
 
48
49
  # Initialize server restart
49
50
  def restart
50
- stop
51
+ stop(false)
52
+ @task.say_info "Restarting server #{@name}...", true
51
53
  sleep 3
52
54
  start
53
55
  end
54
56
 
55
57
  # Remove server
56
58
  def remove
57
- begin
58
- @server.remove_database
59
-
60
- @task.shell.mute do
61
- stop
62
- @task.remove_dir @path
59
+ abort_noexist
60
+ @task.say_warning("This will remove server #{@name} and all data will be lost.")
61
+
62
+ if @task.said_yes?("Are you sure you want to remove server?")
63
+ begin
64
+ @server.remove_database
65
+
66
+ @task.shell.mute do
67
+ stop(false)
68
+ remove_hotel_server
69
+ @task.remove_dir @path
70
+ end
71
+ rescue Exception => e
72
+ @task.say_error "Error while removing server:", e.message
73
+ abort
63
74
  end
64
- rescue Exception => e
65
- @task.say "Error while removing server:"
66
- @task.say e.message + "\n", :red
67
- exit
68
- end
69
75
 
70
- @task.say "Server successfully removed", :green
76
+ @task.say_success "Server successfully removed.", false, true
77
+ end
71
78
  end
72
79
 
73
80
  # Run server
74
- def run_server
81
+ def run_server(from_command=true)
82
+ abort_noexist_cmd('php')
75
83
  ::Dir.chdir @path
76
84
 
77
85
  unless @debug
@@ -84,19 +92,49 @@ module Marv
84
92
  end
85
93
  end
86
94
 
87
- @task.say "Server #{@server.name} is running", :cyan
88
- @task.say "Visit http://#{@server.host}:#{@server.port}", :green
95
+ @task.say_success "Server #{@server.name} is running.", false, !from_command
96
+ @task.say_message " http://#{@server.host}:#{@server.port}", false, false
89
97
 
90
98
  # Start server in debug mode
91
99
  if @debug
100
+ @task.say_empty
92
101
  system "php -S #{@server.host}:#{@server.port} router.php"
93
102
  end
94
103
  end
95
104
 
105
+ # Abort if not exists
106
+ def abort_noexist
107
+ unless @server.exists?
108
+ @task.say_error("Server #{@name} does not exist!")
109
+ abort
110
+ end
111
+ end
112
+
113
+ # Abort if command does no exist
114
+ def abort_noexist_cmd(exec_name, text=nil)
115
+ unless @task.exec_exixts?(exec_name)
116
+ text ||= exec_name.upcase
117
+
118
+ @task.say_error("#{text} is not installed on your system!")
119
+ abort
120
+ end
121
+ end
122
+
123
+ # Remove hotel server if it exists
124
+ def remove_hotel_server
125
+ if @task.exec_exixts?('hotel')
126
+ begin
127
+ `cd #{@path} && hotel rm`
128
+ rescue ExceptionName
129
+ return true
130
+ end
131
+ end
132
+ end
133
+
96
134
  # Change server port
97
135
  def change_server_port
98
- @task.say "Use another port to run the server", :cyan
99
- port = @task.ask "Which port would you like to use?"
136
+ @task.say_info "Use another port to run the server.", true
137
+ port = @task.ask_input "Which port would you like to use?"
100
138
 
101
139
  # Check if port available
102
140
  if is_port_available?(@server.host, port)
@@ -118,10 +156,10 @@ module Marv
118
156
 
119
157
  if ::File.exists?(pid_file)
120
158
  pid = ::File.read(pid_file).to_i
121
-
122
- ::Process.kill(0, pid)
123
- return true
159
+ return ::Process.kill(0, pid) == 1
124
160
  end
161
+
162
+ return false
125
163
  rescue
126
164
  return false
127
165
  end
@@ -130,11 +168,13 @@ module Marv
130
168
  # Check if port is available
131
169
  def is_port_available?(host=@server.host, port=@server.port)
132
170
  begin
133
- server = ::TCPServer.new(host, port)
134
- server.close()
135
- return true
136
- rescue
171
+ url = URI.parse("http://#{host}:#{port}/")
172
+ req = Net::HTTP.new(url.host, url.port)
173
+ req.request_head(url)
174
+
137
175
  return false
176
+ rescue
177
+ return true
138
178
  end
139
179
  end
140
180
 
@@ -19,6 +19,14 @@ module Marv
19
19
 
20
20
  # Create server
21
21
  def create_server
22
+ if ::File.exists?(@server.config_file)
23
+ @task.say_error "A server with the name #{@name} already exists!"
24
+ abort
25
+ end
26
+
27
+ @server.server_options
28
+ @config = @server.server_config
29
+
22
30
  begin
23
31
  @task.shell.mute do
24
32
  create_server_dir
@@ -27,30 +35,29 @@ module Marv
27
35
  add_config_files
28
36
  end
29
37
  rescue Exception => e
30
- @task.say "Error while creating server:"
31
- @task.say e.message + "\n", :red
38
+ @task.say_error "Error while creating server:", e.message
32
39
  abort
33
40
  end
34
41
 
35
- @task.say "Server #{@name} created successfully!", :green
36
- start_server
42
+ @task.say_success "Server #{@name} created successfully!"
43
+
44
+ if @task.exec_exixts?('hotel')
45
+ create_hotel_server
46
+ else
47
+ start_server
48
+ end
37
49
  end
38
50
 
39
51
  # Starts the new server
40
52
  def start_server
41
- unless @task.no?("Would you like to start #{@name} server?")
53
+ if @task.said_yes?("Would you like to start #{@name} server?")
42
54
  action = Marv::Server::Actions.new(@server)
43
- action.start
55
+ action.start(false)
44
56
  end
45
57
  end
46
58
 
47
59
  # Creates a directory for a new server
48
60
  def create_server_dir
49
- if ::File.exists?(@server.config_file)
50
- @task.say "A server with the name #{@name} already exists", :red
51
- abort
52
- end
53
-
54
61
  @task.remove_dir @path
55
62
  @task.empty_directory @path
56
63
  end
@@ -59,8 +66,10 @@ module Marv
59
66
  def download_wordpress
60
67
  package = "/tmp/wordpress-#{@config[:wp_version]}.zip"
61
68
  # Download package file
62
- unless ::File.exists?(package)
63
- @task.say "Downloading WordPress...", :cyan
69
+ if ::File.exists?(package)
70
+ @task.say_warning "WordPress is already downloaded...", false, true
71
+ else ::File.exists?(package)
72
+ @task.say_info "Downloading WordPress...", false, true
64
73
 
65
74
  @task.get "https://wordpress.org/wordpress-#{@config[:wp_version]}.zip" do |content|
66
75
  @task.create_file package, content
@@ -97,6 +106,20 @@ module Marv
97
106
  @global.template ::File.join(layouts, 'wp-config.php'), ::File.join(@path, 'wp-config.php'), @server.context
98
107
  end
99
108
 
109
+ # Create hotel server
110
+ def create_hotel_server
111
+ @task.say_warning "Hotel package detected on your system.", false
112
+
113
+ if @task.yes?("Would you like to create a hotel server?")
114
+ begin
115
+ `hotel add 'php -S 127.0.0.1:$PORT' --port #{@server.port} --dir #{@server.path}`
116
+ @task.say_success "Hotel server created successfully!", false
117
+ rescue Exception => e
118
+ @task.say_error "There was an error while creating hotel server:", e.message, false
119
+ end
120
+ end
121
+ end
122
+
100
123
  end
101
124
  end
102
- end
125
+ end