passify 0.1.2 → 0.2.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.
data/README.md CHANGED
@@ -15,7 +15,7 @@ This is necessary to ensure that Apache is set up correctly. If Passenger and th
15
15
 
16
16
  The application name is optional, if none is provided `passify` creates the name from the current working directory. After creating an application it can be opened in the browser by running
17
17
 
18
- passify open [name]
18
+ passify open
19
19
 
20
20
  To restart the application run
21
21
 
@@ -23,7 +23,15 @@ To restart the application run
23
23
 
24
24
  To remove the application run
25
25
 
26
- passify remove [name]
26
+ passify remove
27
+
28
+ To change the rack environment to e.g. production run
29
+
30
+ passify env production
31
+
32
+ To show the current rack environment run
33
+
34
+ passify env
27
35
 
28
36
  A list of all applications served with `passify` can be viewed by running
29
37
 
@@ -43,6 +51,10 @@ It makes sense to create a wrapper for `passify` if you are using multiple versi
43
51
  rvm wrapper 1.8.7 --no-prefix passify
44
52
 
45
53
  ## Changelog
54
+ ### 0.2.0
55
+ * create a `.passify` file to save the host
56
+ * added `-h` and `-v` shortcuts
57
+
46
58
  ### 0.1.2
47
59
  * added env-command to change rack environment
48
60
 
@@ -6,58 +6,63 @@ module Passify
6
6
  class CLI < Thor
7
7
  include Thor::Actions
8
8
 
9
+ map '-h' => 'help'
10
+ map '-v' => 'version'
11
+
9
12
  APACHE_CONF = '/etc/apache2/httpd.conf'
10
13
  VHOSTS_DIR = '/private/etc/apache2/passenger_pane_vhosts'
11
14
 
12
15
  desc "add", "Creates an application from the current working directory."
13
16
  def add(name = nil)
14
- error("Passify is currently not installed. Please run `passify install` first.") unless passify_installed?
17
+ check_for_passify
15
18
  error("This directory can not be served with Passenger. Please create a `config.ru`-file.") unless is_valid_app?
16
19
  name = File.basename(pwd) if name.nil? || name.empty?
17
20
  name = urlify(name)
18
21
  host = "#{name}.local"
19
22
  if app_exists?(host)
20
23
  if is_same_app?(host, pwd)
21
- notice("This directory is already being served from http://#{host}. Run `passify open #{name}` to view it.")
24
+ notice("This directory is already being served from http://#{host}. Run `passify open` to view it.")
22
25
  else
23
- exit if no?("A different app already exists with under http://#{host}. Do you want to overwrite it?")
24
- remove(name)
26
+ exit if no?("A different app already exists under http://#{host}. Do you want to overwrite it?")
27
+ sudome
28
+ remove_app(host)
25
29
  end
26
30
  end
27
31
 
32
+ silent_create_file ".passify", host
28
33
  sudome
29
34
  create_vhost(host, pwd)
30
35
  register_host(host)
31
36
  restart_apache
32
- say "The application was successfully set up and can be reached from http://#{host} . Run `passify open #{name}` to view it."
37
+ say "The application was successfully set up and can be reached from http://#{host} . Run `passify open` to view it."
33
38
  end
34
39
 
35
40
  desc "remove", "Removes an existing link to the current working directory."
36
- def remove(name = nil)
37
- error("Passify is currently not installed. Please run `passify install` first.") unless passify_installed?
38
- name = File.basename(pwd) if name.nil? || name.empty?
39
- name = urlify(name)
40
- host = "#{name}.local"
41
- notice("No application exists under http://#{host} .") unless app_exists?(host)
41
+ def remove
42
+ check_for_passify
43
+ host = find_host
44
+
42
45
  sudome
43
- remove_file(vhost_file(host))
44
- unregister_host(host)
46
+ remove_app(host)
47
+ say "The application was successfully removed."
45
48
  end
46
49
 
47
50
  desc "env", "Change the environment of the current app"
48
- def env(name = nil, env = 'production')
49
- error("Passify is currently not installed. Please run `passify install` first.") unless passify_installed?
50
- name = File.basename(pwd) if name.nil? || name.empty?
51
- name = urlify(name)
52
- host = "#{name}.local"
53
- notice("No application exists under http://#{host} .") unless app_exists?(host)
51
+ def env(env = nil)
52
+ check_for_passify
53
+ host = find_host
54
+
54
55
  line_no, rack_env = `grep -n 'RackEnv' #{vhost_file(host)}`.split(":")
55
56
  current_env = rack_env.strip.split(" ")[1]
56
- notice("The application is already in '#{env}' environment.") if current_env == env
57
- sudome
58
- `sed -i '' '#{line_no}s!#{current_env}!#{env}!' #{vhost_file(host)}`
59
- restart_apache
60
- say "The application now runs in '#{env}' environment."
57
+ if env.nil? || env.empty?
58
+ say "The application is running in '#{current_env}' environment."
59
+ else
60
+ notice("The application is already in '#{env}' environment.") if current_env == env
61
+ sudome
62
+ `sed -i '' '#{line_no}s!#{current_env}!#{env}!' #{vhost_file(host)}`
63
+ restart_apache
64
+ say "The application now runs in '#{env}' environment."
65
+ end
61
66
  end
62
67
 
63
68
  desc "install", "Installs passify into the local Apache installation."
@@ -100,7 +105,7 @@ module Passify
100
105
 
101
106
  desc "list", "Lists all applications served with passify."
102
107
  def list
103
- error("Passify is currently not installed. Please run `passify install` first.") unless passify_installed?
108
+ check_for_passify
104
109
  Dir.foreach(VHOSTS_DIR) do |entry|
105
110
  if File.file?("#{VHOSTS_DIR}/#{entry}")
106
111
  host = entry[0..-12]
@@ -110,11 +115,10 @@ module Passify
110
115
  end
111
116
 
112
117
  desc "open", "Opens the current working directory in browser."
113
- def open(name = nil)
114
- error("Passify is currently not installed. Please run `passify install` first.") unless passify_installed?
115
- name = File.basename(pwd) if name.nil? || name.empty?
116
- name = urlify(name)
117
- host = "#{name}.local"
118
+ def open
119
+ check_for_passify
120
+ host = find_host
121
+
118
122
  system("open http://#{host}")
119
123
  end
120
124
 
@@ -137,6 +141,10 @@ module Passify
137
141
  system("which rvm > /dev/null 2>&1")
138
142
  end
139
143
 
144
+ def check_for_passify
145
+ error("Passify is currently not installed. Please run `passify install` first.") unless passify_installed?
146
+ end
147
+
140
148
  def passify_installed?
141
149
  system("grep 'Include \\/private\\/etc\\/apache2\\/passenger_pane_vhosts\\/\\*\\.conf' #{APACHE_CONF} > /dev/null 2>&1")
142
150
  end
@@ -145,6 +153,13 @@ module Passify
145
153
  system("grep 'PassengerRuby' #{APACHE_CONF} > /dev/null 2>&1")
146
154
  end
147
155
 
156
+ def remove_app(host)
157
+ app_dir = directory_for_host(host)
158
+ remove_file(vhost_file(host), :verbose => false)
159
+ unregister_host(host)
160
+ remove_file("#{app_dir}/.passify", :verbose => false) if File.exists?("#{app_dir}/.passify")
161
+ end
162
+
148
163
  def is_valid_app?
149
164
  if is_rack_app?
150
165
  FileUtils.mkdir_p('public')
@@ -171,6 +186,18 @@ module Passify
171
186
  File.exists?('index.html') || File.exists?('index.php')
172
187
  end
173
188
 
189
+ def find_host
190
+ if File.exists?('.passify')
191
+ host = File.open('.passify') {|f| f.readline}.strip
192
+ else # support for passify 0.1.x
193
+ name = File.basename(pwd)
194
+ name = urlify(name)
195
+ host = "#{name}.local"
196
+ end
197
+ notice("The current directory is not served via passify. Please run `passify add` first.") unless app_exists?(host)
198
+ host
199
+ end
200
+
174
201
  def app_exists?(host)
175
202
  File.exists?(vhost_file(host))
176
203
  end
@@ -214,7 +241,7 @@ module Passify
214
241
  end
215
242
 
216
243
  def create_passenger_vhost(host, path)
217
- create_file vhost_file(host), <<-eos
244
+ silent_create_file vhost_file(host), <<-eos
218
245
  <VirtualHost *:80>
219
246
  ServerName #{host}
220
247
  DocumentRoot "#{path}/public"
@@ -228,7 +255,7 @@ module Passify
228
255
  end
229
256
 
230
257
  def create_legacy_vhost(host, path)
231
- create_file vhost_file(host), <<-eos
258
+ silent_create_file vhost_file(host), <<-eos
232
259
  <VirtualHost *:80>
233
260
  ServerName #{host}
234
261
  DocumentRoot "#{path}"
@@ -259,5 +286,9 @@ module Passify
259
286
  system("apachectl graceful > /dev/null 2>&1")
260
287
  end
261
288
 
289
+ def silent_create_file(path, content)
290
+ create_file path, content, :verbose => false
291
+ end
292
+
262
293
  end
263
294
  end
@@ -1,3 +1,3 @@
1
1
  module Passify
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Fabian Schwahn