shere 0.9.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9d91304e3c548a3f7cb2e1a16ca838bfd26f0c5e8646cf02aacf34e90433160c
4
+ data.tar.gz: 5a272db79714765ede6014d568b9669997006b16e955ee5bff35788a50b811da
5
+ SHA512:
6
+ metadata.gz: 7da9957010d7711ab5ccd3918301322514e1d5a064c6e59e121ca6319b57eb271f1050aaf1b14fa6461d4eac77062e8dc3ce9d8d4e4291ba2b347b8c2d36f8d6
7
+ data.tar.gz: cac36be074fb73966194e862967789dd097595a3a8eaf354f6087427db7542924f0c0efe253267663e8f14f14ad06c63dc76e7b3e961e9e99bdbaae265e534a6
data/.gitignore CHANGED
@@ -1,2 +1,2 @@
1
- pkg
2
- *.rbc
1
+ /pkg/
2
+ /coverage/
data/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGES
2
2
 
3
+ ## shere 1.0.0 -- ?
4
+
5
+ * Also try to reverse lookup and show hostname
6
+ * Prefix shere- for the temporary directory
7
+
3
8
  ## shere 0.9.2 -- 2012-01-13
4
9
 
5
10
  Fixed a bug where root path is not quoted.
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- source 'http://rubygems.org'
2
+ source 'https://rubygems.org'
3
3
 
4
4
  gemspec
5
5
 
data/README.md CHANGED
@@ -33,9 +33,9 @@ Nginx instance to serve the directory you specified.
33
33
 
34
34
  ## LICENSE:
35
35
 
36
- Apache License 2.0
36
+ Apache License 2.0 (Apache-2.0)
37
37
 
38
- Copyright (c) 2011, Lin Jen-Shin (godfat)
38
+ Copyright (c) 2011-2018, Lin Jen-Shin (godfat)
39
39
 
40
40
  Licensed under the Apache License, Version 2.0 (the "License");
41
41
  you may not use this file except in compliance with the License.
data/Rakefile CHANGED
@@ -1,18 +1,13 @@
1
1
 
2
- require "#{dir = File.dirname(__FILE__)}/task/gemgem"
3
- Gemgem.dir = dir
4
-
5
- ($LOAD_PATH << File.expand_path("#{Gemgem.dir}/lib")).uniq!
6
-
7
- desc 'Generate gemspec'
8
- task 'gem:spec' do
9
- Gemgem.spec = Gemgem.create do |s|
10
- require 'shere/version'
11
- s.name = 'shere'
12
- s.version = Shere::VERSION
13
-
14
- %w[].each{ |g| s.add_runtime_dependency(g) }
15
- end
2
+ begin
3
+ require "#{__dir__}/task/gemgem"
4
+ rescue LoadError
5
+ sh 'git submodule update --init --recursive'
6
+ exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
7
+ end
16
8
 
17
- Gemgem.write
9
+ Gemgem.init(__dir__) do |s|
10
+ require 'shere/version'
11
+ s.name = 'shere'
12
+ s.version = Shere::VERSION
18
13
  end
@@ -1,5 +1,30 @@
1
1
 
2
+ require 'socket'
3
+
2
4
  module Shere
5
+ class ExternalAddress < Struct.new(:address)
6
+ def initialize
7
+ super(external_address)
8
+ end
9
+
10
+ def ip_address
11
+ address.ip_address
12
+ end
13
+
14
+ def reverse_lookup_host
15
+ Socket.getaddrinfo(
16
+ ip_address, 0, Socket::AF_UNSPEC, Socket::SOCK_STREAM, nil,
17
+ Socket::AI_CANONNAME, true).dig(0, 2)
18
+ end
19
+
20
+ private
21
+ def external_address
22
+ Socket.ip_address_list.find do |addr|
23
+ addr.ipv4? && !addr.ipv4_loopback? && !addr.ipv4_private?
24
+ end
25
+ end
26
+ end
27
+
3
28
  module_function
4
29
  def run opts={}
5
30
  root = File.expand_path(opts[:root] || '.')
@@ -8,18 +33,17 @@ module Shere
8
33
  user = opts[:user]
9
34
 
10
35
  require 'tmpdir'
11
- tmpdir = Dir.mktmpdir
36
+ tmpdir = Dir.mktmpdir('shere-')
12
37
  File.open("#{tmpdir}/nginx.conf", 'w'){ |conf|
13
38
  conf.puts(nginx_config(root, port, host, user, tmpdir))
14
39
  }
15
40
  sh('nginx', '-c', "#{tmpdir}/nginx.conf")
16
41
  puts("PID: #{File.read("#{tmpdir}/nginx.pid")}")
17
- puts("http://#{local_ip}:#{port}")
18
- end
19
42
 
20
- def local_ip
21
- require 'socket'
22
- Socket.getaddrinfo(Socket.gethostname, 'echo', Socket::AF_INET)[0][3]
43
+ address = ExternalAddress.new
44
+
45
+ puts("http://#{address.ip_address}:#{port}" \
46
+ " or http://#{address.reverse_lookup_host}:#{port}")
23
47
  end
24
48
 
25
49
  def root_privilege?
@@ -43,175 +67,175 @@ module Shere
43
67
  end
44
68
  else
45
69
  ''
46
- end +
47
- <<-NGINX
48
- worker_processes 2;
70
+ end + <<~NGINX
71
+ worker_processes 2;
49
72
 
50
- error_log #{tmpdir}/nginx_error.log;
51
- pid #{tmpdir}/nginx.pid;
73
+ error_log #{tmpdir}/nginx_error.log;
74
+ pid #{tmpdir}/nginx.pid;
52
75
 
53
- events {
54
- worker_connections 1024;
55
- }
76
+ events {
77
+ worker_connections 1024;
78
+ }
56
79
 
57
- http {
58
- #{nginx_mime_types}
59
- default_type application/octet-stream;
80
+ http {
81
+ #{nginx_mime_types}
60
82
 
61
- log_format main '$remote_addr - $remote_user [$time_local] $request '
62
- '"$status" $body_bytes_sent "$http_referer" '
63
- '"$http_user_agent" "$http_x_forwarded_for"';
83
+ default_type application/octet-stream;
64
84
 
65
- access_log #{tmpdir}/nginx_access.log main;
85
+ log_format main '$remote_addr - $remote_user [$time_local] $request '
86
+ '"$status" $body_bytes_sent "$http_referer" '
87
+ '"$http_user_agent" "$http_x_forwarded_for"';
66
88
 
67
- fastcgi_temp_path #{tmpdir}/fcgi_temp;
68
- client_body_temp_path #{tmpdir}/client_body 1 2;
69
- proxy_temp_path #{tmpdir}/proxy_temp;
89
+ access_log #{tmpdir}/nginx_access.log main;
70
90
 
71
- client_header_timeout 10m;
72
- client_body_timeout 10m;
73
- send_timeout 10m;
91
+ fastcgi_temp_path #{tmpdir}/fcgi_temp;
92
+ client_body_temp_path #{tmpdir}/client_body 1 2;
93
+ proxy_temp_path #{tmpdir}/proxy_temp;
74
94
 
75
- connection_pool_size 256;
76
- client_header_buffer_size 1k;
77
- large_client_header_buffers 4 2k;
78
- request_pool_size 4k;
95
+ client_header_timeout 10m;
96
+ client_body_timeout 10m;
97
+ send_timeout 10m;
79
98
 
80
- output_buffers 1 32k;
81
- postpone_output 1460;
99
+ connection_pool_size 256;
100
+ client_header_buffer_size 1k;
101
+ large_client_header_buffers 4 2k;
102
+ request_pool_size 4k;
82
103
 
83
- sendfile on;
84
- tcp_nopush on;
85
- tcp_nodelay on;
104
+ output_buffers 1 32k;
105
+ postpone_output 1460;
86
106
 
87
- keepalive_timeout 75 20;
88
- ignore_invalid_headers on;
107
+ sendfile on;
108
+ tcp_nopush on;
109
+ tcp_nodelay on;
89
110
 
90
- gzip on;
91
- gzip_min_length 1100;
92
- gzip_buffers 4 8k;
93
- gzip_types text/plain text/css application/xhtml+xml application/javascript;
111
+ keepalive_timeout 75 20;
112
+ ignore_invalid_headers on;
94
113
 
95
- server {
96
- listen #{port};
97
- server_name #{host};
98
- index index.xhtml index.html index.htm;
114
+ gzip on;
115
+ gzip_min_length 1100;
116
+ gzip_buffers 4 8k;
117
+ gzip_types text/plain text/css application/xhtml+xml application/javascript;
99
118
 
100
- location / {
101
- root "#{root}";
102
- autoindex on;
119
+ server {
120
+ listen #{port};
121
+ server_name #{host};
122
+ index index.xhtml index.html index.htm;
123
+
124
+ location / {
125
+ root "#{root}";
126
+ autoindex on;
127
+ }
103
128
  }
104
- }
105
- }
106
- NGINX
129
+ }
130
+ NGINX
107
131
  end
108
132
 
109
133
  def nginx_mime_types
110
- <<-NGINX
111
- types {
112
- # text
113
- text/plain txt;
114
- text/html html htm shtml;
115
- text/css css;
116
- text/xml xml;
117
-
118
- # images
119
- image/gif gif;
120
- image/jpeg jpeg jpg;
121
- image/png png;
122
- image/tiff tif tiff;
123
- image/vnd.microsoft.icon ico;
124
-
125
- # common application
126
- application/atom+xml atom;
127
- application/rss+xml rss;
128
- application/xhtml+xml xhtml;
129
-
130
- application/javascript js;
131
- application/postscript ps eps ai;
132
- application/rtf rtf;
133
-
134
- application/x-shockwave-flash swf;
135
- application/pdf pdf;
136
- application/java-archive jar war ear;
137
-
138
- application/zip zip;
139
- application/x-gzip gz;
140
- application/x-tar tar;
141
- application/x-rar-compressed rar;
142
-
143
- application/vnd.mozilla.xul+xml xul;
144
- application/msword doc;
145
- application/vnd.ms-excel xls;
146
- application/vnd.ms-powerpoint ppt;
147
-
148
- # audio
149
- audio/midi mid midi kar;
150
- audio/mpeg mp3;
151
- audio/ogg ogg;
152
- audio/aac m4a;
153
-
154
- audio/vnd.rn-realaudio ra;
155
-
156
- audio/x-wav wav;
157
- audio/x-ms-wma wma;
158
-
159
- # video
160
- video/mpeg mpeg mpg;
161
- video/quicktime mov;
162
- video/mp4 mp4;
163
-
164
- video/x-ms-wmv wmv;
165
- video/x-ms-asf asx asf;
166
- video/x-aif aif aiff aifc;
167
- video/x-msvideo avi;
168
-
169
- # others
170
- text/mathml mml;
171
- text/vnd.sun.j2me.app-descriptor jad;
172
- text/vnd.wap.wml wml;
173
- text/x-component htc;
174
-
175
- image/x-portable-pixmap ppm;
176
- image/x-portable-graymap pgm;
177
- image/x-portable-bitmap pbm;
178
- image/x-portable-anymap pnm;
179
- image/x-xwindowdump xwd;
180
- image/x-xpixmap xpm;
181
- image/x-xbitmap xbm;
182
-
183
- image/vnd.wap.wbmp wbmp;
184
- image/x-jng jng;
185
- image/x-ms-bmp bmp;
186
-
187
- video/3gpp 3gpp 3gp;
188
- video/x-flv flv;
189
- video/x-mng mng;
190
-
191
- application/mac-binhex40 hqx;
192
- application/vnd.wap.wmlc wmlc;
193
-
194
- application/x-cocoa cco;
195
- application/x-java-archive-diff jardiff;
196
- application/x-java-jnlp-file jnlp;
197
- application/x-makeself run;
198
- application/x-perl pl pm;
199
- application/x-pilot prc pdb;
200
-
201
- application/x-redhat-package-manager rpm;
202
- application/x-sea sea;
203
- application/x-stuffit sit;
204
- application/x-tcl tcl tk;
205
- application/x-x509-ca-cert der pem crt;
206
- application/x-xpinstall xpi;
207
-
208
- application/octet-stream bin exe dll;
209
- application/octet-stream deb;
210
- application/octet-stream dmg;
211
- application/octet-stream eot;
212
- application/octet-stream iso img;
213
- application/octet-stream msi msp msm;
214
- }
215
- NGINX
134
+ <<~NGINX
135
+ types {
136
+ # text
137
+ text/plain txt;
138
+ text/html html htm shtml;
139
+ text/css css;
140
+ text/xml xml;
141
+
142
+ # images
143
+ image/gif gif;
144
+ image/jpeg jpeg jpg;
145
+ image/png png;
146
+ image/tiff tif tiff;
147
+ image/vnd.microsoft.icon ico;
148
+
149
+ # common application
150
+ application/atom+xml atom;
151
+ application/rss+xml rss;
152
+ application/xhtml+xml xhtml;
153
+
154
+ application/javascript js;
155
+ application/postscript ps eps ai;
156
+ application/rtf rtf;
157
+
158
+ application/x-shockwave-flash swf;
159
+ application/pdf pdf;
160
+ application/java-archive jar war ear;
161
+
162
+ application/zip zip;
163
+ application/x-gzip gz;
164
+ application/x-tar tar;
165
+ application/x-rar-compressed rar;
166
+
167
+ application/vnd.mozilla.xul+xml xul;
168
+ application/msword doc;
169
+ application/vnd.ms-excel xls;
170
+ application/vnd.ms-powerpoint ppt;
171
+
172
+ # audio
173
+ audio/midi mid midi kar;
174
+ audio/mpeg mp3;
175
+ audio/ogg ogg;
176
+ audio/aac m4a;
177
+
178
+ audio/vnd.rn-realaudio ra;
179
+
180
+ audio/x-wav wav;
181
+ audio/x-ms-wma wma;
182
+
183
+ # video
184
+ video/mpeg mpeg mpg;
185
+ video/quicktime mov;
186
+ video/mp4 mp4;
187
+
188
+ video/x-ms-wmv wmv;
189
+ video/x-ms-asf asx asf;
190
+ video/x-aif aif aiff aifc;
191
+ video/x-msvideo avi;
192
+
193
+ # others
194
+ text/mathml mml;
195
+ text/vnd.sun.j2me.app-descriptor jad;
196
+ text/vnd.wap.wml wml;
197
+ text/x-component htc;
198
+
199
+ image/x-portable-pixmap ppm;
200
+ image/x-portable-graymap pgm;
201
+ image/x-portable-bitmap pbm;
202
+ image/x-portable-anymap pnm;
203
+ image/x-xwindowdump xwd;
204
+ image/x-xpixmap xpm;
205
+ image/x-xbitmap xbm;
206
+
207
+ image/vnd.wap.wbmp wbmp;
208
+ image/x-jng jng;
209
+ image/x-ms-bmp bmp;
210
+
211
+ video/3gpp 3gpp 3gp;
212
+ video/x-flv flv;
213
+ video/x-mng mng;
214
+
215
+ application/mac-binhex40 hqx;
216
+ application/vnd.wap.wmlc wmlc;
217
+
218
+ application/x-cocoa cco;
219
+ application/x-java-archive-diff jardiff;
220
+ application/x-java-jnlp-file jnlp;
221
+ application/x-makeself run;
222
+ application/x-perl pl pm;
223
+ application/x-pilot prc pdb;
224
+
225
+ application/x-redhat-package-manager rpm;
226
+ application/x-sea sea;
227
+ application/x-stuffit sit;
228
+ application/x-tcl tcl tk;
229
+ application/x-x509-ca-cert der pem crt;
230
+ application/x-xpinstall xpi;
231
+
232
+ application/octet-stream bin exe dll;
233
+ application/octet-stream deb;
234
+ application/octet-stream dmg;
235
+ application/octet-stream eot;
236
+ application/octet-stream iso img;
237
+ application/octet-stream msi msp msm;
238
+ }
239
+ NGINX
216
240
  end
217
241
  end
@@ -48,8 +48,9 @@ module Shere::Runner
48
48
  end
49
49
 
50
50
  def help
51
- maxn = options.transpose.first.map(&:size).max
52
- maxd = options.transpose.last .map(&:size).max
51
+ optt = options.transpose
52
+ maxn = optt.first.map(&:size).max
53
+ maxd = optt.last .map(&:size).max
53
54
  "Usage: shere ROOT\n" +
54
55
  options.map{ |(name, desc)|
55
56
  if desc.empty?
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Shere
3
- VERSION = '0.9.2'
3
+ VERSION = '1.0.0'
4
4
  end
@@ -1,42 +1,35 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # stub: shere 1.0.0 ruby lib
2
3
 
3
4
  Gem::Specification.new do |s|
4
- s.name = "shere"
5
- s.version = "0.9.2"
5
+ s.name = "shere".freeze
6
+ s.version = "1.0.0"
6
7
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Lin Jen-Shin (godfat)"]
9
- s.date = "2012-01-13"
10
- s.description = "_Share_ the directory _here_ with [Nginx][]!\nShere would create a temporary Nginx config and run an\nNginx instance to serve the directory you specified."
11
- s.email = ["godfat (XD) godfat.org"]
12
- s.executables = ["shere"]
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib".freeze]
10
+ s.authors = ["Lin Jen-Shin (godfat)".freeze]
11
+ s.date = "2018-03-14"
12
+ s.description = "_Share_ the directory _here_ with [Nginx][]!\nShere would create a temporary Nginx config and run an\nNginx instance to serve the directory you specified.".freeze
13
+ s.email = ["godfat (XD) godfat.org".freeze]
14
+ s.executables = ["shere".freeze]
13
15
  s.files = [
14
- ".gitignore",
15
- ".gitmodules",
16
- "CHANGES.md",
17
- "Gemfile",
18
- "LICENSE",
19
- "README.md",
20
- "Rakefile",
21
- "TODO.md",
22
- "bin/shere",
23
- "lib/shere.rb",
24
- "lib/shere/runner.rb",
25
- "lib/shere/version.rb",
26
- "shere.gemspec",
27
- "task/.gitignore",
28
- "task/gemgem.rb"]
29
- s.homepage = "https://github.com/godfat/shere"
30
- s.require_paths = ["lib"]
31
- s.rubygems_version = "1.8.15"
32
- s.summary = "_Share_ the directory _here_ with [Nginx][]!"
33
-
34
- if s.respond_to? :specification_version then
35
- s.specification_version = 3
36
-
37
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
38
- else
39
- end
40
- else
41
- end
16
+ ".gitignore".freeze,
17
+ ".gitmodules".freeze,
18
+ "CHANGES.md".freeze,
19
+ "Gemfile".freeze,
20
+ "LICENSE".freeze,
21
+ "README.md".freeze,
22
+ "Rakefile".freeze,
23
+ "TODO.md".freeze,
24
+ "bin/shere".freeze,
25
+ "lib/shere.rb".freeze,
26
+ "lib/shere/runner.rb".freeze,
27
+ "lib/shere/version.rb".freeze,
28
+ "shere.gemspec".freeze,
29
+ "task/README.md".freeze,
30
+ "task/gemgem.rb".freeze]
31
+ s.homepage = "https://github.com/godfat/shere".freeze
32
+ s.licenses = ["Apache-2.0".freeze]
33
+ s.rubygems_version = "2.7.6".freeze
34
+ s.summary = "_Share_ the directory _here_ with [Nginx][]!".freeze
42
35
  end
@@ -0,0 +1,54 @@
1
+ # Gemgem
2
+
3
+ ## DESCRIPTION:
4
+
5
+ Provided tasks:
6
+
7
+ rake clean # Trash ignored files
8
+ rake gem:build # Build gem
9
+ rake gem:install # Install gem
10
+ rake gem:release # Release gem
11
+ rake gem:spec # Generate gemspec
12
+ rake test # Run tests
13
+
14
+ ## REQUIREMENTS:
15
+
16
+ * Tested with MRI (official CRuby), Rubinius and JRuby.
17
+
18
+ ## INSTALLATION:
19
+
20
+ git submodule add git://github.com/godfat/gemgem.git task
21
+
22
+ And in Rakefile:
23
+
24
+ ``` ruby
25
+ begin
26
+ require "#{__dir__}/task/gemgem"
27
+ rescue LoadError
28
+ sh 'git submodule update --init --recursive'
29
+ exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
30
+ end
31
+
32
+ Gemgem.init(__dir__, :submodules => %w[your-dep]) do |s|
33
+ s.name = 'your-gem'
34
+ s.version = '0.1.0'
35
+ end
36
+ ```
37
+
38
+ ## LICENSE:
39
+
40
+ Apache License 2.0 (Apache-2.0)
41
+
42
+ Copyright (c) 2011-2017, Lin Jen-Shin (godfat)
43
+
44
+ Licensed under the Apache License, Version 2.0 (the "License");
45
+ you may not use this file except in compliance with the License.
46
+ You may obtain a copy of the License at
47
+
48
+ <http://www.apache.org/licenses/LICENSE-2.0>
49
+
50
+ Unless required by applicable law or agreed to in writing, software
51
+ distributed under the License is distributed on an "AS IS" BASIS,
52
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
53
+ See the License for the specific language governing permissions and
54
+ limitations under the License.
@@ -1,175 +1,295 @@
1
1
 
2
- require 'pathname'
3
-
4
2
  module Gemgem
5
3
  class << self
6
- attr_accessor :dir, :spec
4
+ attr_accessor :dir, :spec, :submodules, :spec_create
7
5
  end
8
6
 
9
7
  module_function
8
+ def gem_tag ; "#{spec.name}-#{spec.version}" ; end
9
+ def gem_path ; "#{pkg_dir}/#{gem_tag}.gem" ; end
10
+ def spec_path ; "#{dir}/#{spec.name}.gemspec" ; end
11
+ def pkg_dir ; "#{dir}/pkg" ; end
12
+ def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
13
+
14
+ def init dir, options={}, &block
15
+ self.dir = dir
16
+ ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
17
+ ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
18
+ self.submodules = options[:submodules] || []
19
+ self.spec_create = block
20
+
21
+ $LOAD_PATH.unshift("#{dir}/lib", *submodules_libs)
22
+ end
23
+
10
24
  def create
11
- yield(spec = Gem::Specification.new{ |s|
25
+ spec = Gem::Specification.new do |s|
12
26
  s.authors = ['Lin Jen-Shin (godfat)']
13
27
  s.email = ['godfat (XD) godfat.org']
14
28
 
15
29
  s.description = description.join
16
30
  s.summary = description.first
31
+ s.license = license
17
32
 
18
- s.rubygems_version = Gem::VERSION
19
- s.date = Time.now.strftime('%Y-%m-%d')
20
- s.files = gem_files
21
- s.test_files = gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
22
- s.executables = Dir['bin/*'].map{ |f| File.basename(f) }
23
- s.require_paths = %w[lib]
24
- })
33
+ s.date = Time.now.strftime('%Y-%m-%d')
34
+ s.files = gem_files
35
+ s.test_files = test_files
36
+ s.executables = bin_files
37
+ end
38
+ spec_create.call(spec)
25
39
  spec.homepage ||= "https://github.com/godfat/#{spec.name}"
26
- spec
40
+ self.spec = spec
27
41
  end
28
42
 
29
- def readme
30
- path = %w[README.md README].find{ |name|
31
- File.exist?("#{Gemgem.dir}/#{name}")
32
- }
33
- @readme ||=
34
- if path
35
- ps = File.read(path).scan(/#+[^\n]+\n\n.+?(?=\n\n#+[^\n]+\n)/m)
36
- ps.inject({'HEADER' => ps.first}){ |r, s, i|
37
- r[s[/\w+/]] = s
38
- r
39
- }
40
- else
41
- {}
42
- end
43
+ def gem_install
44
+ require 'rubygems/commands/install_command'
45
+ # read ~/.gemrc
46
+ Gem.use_paths(Gem.configuration[:gemhome], Gem.configuration[:gempath])
47
+ Gem::Command.extra_args = Gem.configuration[:gem]
48
+
49
+ # setup install options
50
+ cmd = Gem::Commands::InstallCommand.new
51
+ cmd.handle_options([])
52
+
53
+ # install
54
+ install = Gem::Installer.new(gem_path, cmd.options)
55
+ install.install
56
+ puts "\e[35mGem installed: \e[33m#{strip_path(install.gem_dir)}\e[0m"
43
57
  end
44
58
 
45
- def description
46
- @description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
59
+ def gem_spec
60
+ create
61
+ write
47
62
  end
48
63
 
49
- def changes
50
- path = %w[CHANGES.md CHANGES].find{ |name|
51
- File.exist?("#{Gemgem.dir}/#{name}")
52
- }
53
- @changes ||=
54
- if path
55
- date = '\d+{4}\-\d+{2}\-\d{2}'
56
- File.read(path).match(
57
- /([^\n]+#{date}\n\n(.+?))(?=\n\n[^\n]+#{date}\n|\Z)/m)[1]
58
- else
59
- ''
60
- end
64
+ def gem_build
65
+ require 'fileutils'
66
+ require 'rubygems/package'
67
+ gem = nil
68
+ Dir.chdir(dir) do
69
+ gem = Gem::Package.build(Gem::Specification.load(spec_path))
70
+ FileUtils.mkdir_p(pkg_dir)
71
+ FileUtils.mv(gem, pkg_dir) # gem is relative path, but might be ok
72
+ end
73
+ puts "\e[35mGem built: \e[33m#{strip_path("#{pkg_dir}/#{gem}")}\e[0m"
61
74
  end
62
75
 
63
- def ann_md
64
- "##{readme['HEADER'].sub(/([\w\-]+)/, "[\\1](#{spec.homepage})")}\n\n" \
65
- "##{readme['DESCRIPTION'][/[^\n]+\n\n[^\n]+/]}\n\n" \
66
- "### CHANGES:\n\n" \
67
- "###{changes}\n\n" \
68
- "##{readme['INSTALLATION']}\n\n" +
69
- if readme['SYNOPSIS'] then "##{readme['SYNOPSIS']}" else '' end
76
+ def gem_release
77
+ sh_git('tag', gem_tag)
78
+ sh_git('push')
79
+ sh_git('push', '--tags')
80
+ sh_gem('push', gem_path)
70
81
  end
71
82
 
72
- def ann_html
73
- gem 'nokogiri'
74
- gem 'kramdown'
83
+ def gem_check
84
+ unless git('status', '--porcelain').empty?
85
+ puts("\e[35mWorking copy is not clean.\e[0m")
86
+ exit(3)
87
+ end
88
+
89
+ ver = spec.version.to_s
90
+
91
+ if ENV['VERSION'].nil?
92
+ puts("\e[35mExpected " \
93
+ "\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
94
+ exit(1)
75
95
 
76
- IO.popen('kramdown', 'r+') do |md|
77
- md.puts Gemgem.ann_md
78
- md.close_write
79
- require 'nokogiri'
80
- html = Nokogiri::XML.parse("<gemgem>#{md.read}</gemgem>")
81
- html.css('*').each{ |n| n.delete('id') }
82
- html.root.children.to_html
96
+ elsif ENV['VERSION'] != ver
97
+ puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
98
+ "\e[35mbut got\n " \
99
+ "\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
100
+ exit(2)
83
101
  end
84
102
  end
85
103
 
86
- def ann_email
87
- "#{readme['HEADER'].sub(/([\w\-]+)/, "\\1 <#{spec.homepage}>")}\n\n" \
88
- "#{readme['DESCRIPTION']}\n\n" \
89
- "#{readme['INSTALLATION']}\n\n" +
90
- if readme['SYNOPSIS'] then "##{readme['SYNOPSIS']}\n\n" else '' end +
91
- "## CHANGES:\n\n" \
92
- "##{changes}\n\n"
104
+ def test
105
+ return if test_files.empty?
106
+
107
+ if ENV['COV'] || ENV['CI']
108
+ require 'simplecov'
109
+ if ENV['CI']
110
+ begin
111
+ require 'coveralls'
112
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
113
+ rescue LoadError => e
114
+ puts "Cannot load coveralls, skip: #{e}"
115
+ end
116
+ end
117
+ SimpleCov.start do
118
+ add_filter('test/')
119
+ add_filter('test.rb')
120
+ submodules_libs.each(&method(:add_filter))
121
+ end
122
+ end
123
+
124
+ test_files.each{ |file| require "#{dir}/#{file[0..-4]}" }
93
125
  end
94
126
 
95
- def gem_tag
96
- "#{spec.name}-#{spec.version}"
127
+ def clean
128
+ return if ignored_files.empty?
129
+
130
+ require 'fileutils'
131
+ trash = File.expand_path("~/.Trash/#{spec.name}")
132
+ puts "Move the following files into: \e[35m#{strip_path(trash)}\e[33m"
133
+
134
+ ignored_files.each do |file|
135
+ from = "#{dir}/#{file}"
136
+ to = "#{trash}/#{File.dirname(file)}"
137
+ puts strip_path(from)
138
+
139
+ FileUtils.mkdir_p(to)
140
+ FileUtils.mv(from, to)
141
+ end
142
+
143
+ print "\e[0m"
97
144
  end
98
145
 
99
146
  def write
100
- File.open("#{dir}/#{spec.name}.gemspec", 'w'){ |f|
101
- f << split_lines(spec.to_ruby) }
147
+ File.open(spec_path, 'w'){ |f| f << split_lines(spec.to_ruby) }
102
148
  end
103
149
 
104
150
  def split_lines ruby
105
- ruby.gsub(/(.+?)\[(.+?)\]/){ |s|
151
+ ruby.gsub(/(.+?)\s*=\s*\[(.+?)\]/){ |s|
106
152
  if $2.index(',')
107
- "#{$1}[\n #{$2.split(',').map(&:strip).join(",\n ")}]"
153
+ "#{$1} = [\n #{$2.split(',').map(&:strip).join(",\n ")}]"
108
154
  else
109
155
  s
110
156
  end
111
157
  }
112
158
  end
113
159
 
160
+ def strip_path path
161
+ strip_home_path(strip_cwd_path(path))
162
+ end
163
+
164
+ def strip_home_path path
165
+ path.sub(/\A#{Regexp.escape(ENV['HOME'])}\//, '~/')
166
+ end
167
+
168
+ def strip_cwd_path path
169
+ path.sub(/\A#{Regexp.escape(Dir.pwd)}\//, '')
170
+ end
171
+
172
+ def submodules_libs
173
+ submodules.map{ |path| "#{dir}/#{path}/lib" }
174
+ end
175
+
176
+ def git *args
177
+ `git --git-dir=#{dir}/.git #{args.join(' ')}`
178
+ end
179
+
180
+ def sh_git *args
181
+ Rake.sh('git', "--git-dir=#{dir}/.git", *args)
182
+ end
183
+
184
+ def sh_gem *args
185
+ Rake.sh(Gem.ruby, '-S', 'gem', *args)
186
+ end
187
+
188
+ def glob path=dir
189
+ Dir.glob("#{path}/**/*", File::FNM_DOTMATCH)
190
+ end
191
+
192
+ def readme
193
+ @readme ||=
194
+ if (path = "#{Gemgem.dir}/README.md") && File.exist?(path)
195
+ ps = "##{File.read(path)}".
196
+ scan(/((#+)[^\n]+\n\n.+?(?=(\n\n\2[^#\n]+\n)|\Z))/m).map(&:first)
197
+ ps.inject('HEADER' => ps.first){ |r, s, i|
198
+ r[s[/\w+/]] = s
199
+ r
200
+ }
201
+ else
202
+ {}
203
+ end
204
+ end
205
+
206
+ def description
207
+ # JRuby String#lines is returning an enumerator
208
+ @description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
209
+ end
210
+
211
+ def license
212
+ readme['LICENSE'].sub(/.+\n\n/, '').lines.first.
213
+ split(/[()]/).map(&:strip).reject(&:empty?).last
214
+ end
215
+
114
216
  def all_files
115
- @all_files ||= find_files(Pathname.new(dir)).map{ |file|
116
- if file.to_s =~ %r{\.git/}
117
- nil
217
+ @all_files ||= fold_files(glob).sort
218
+ end
219
+
220
+ def fold_files files
221
+ files.inject([]){ |r, path|
222
+ if File.file?(path) && path !~ %r{/\.git(/|$)} &&
223
+ (rpath = path[%r{^#{escaped_dir}/(.*$)}, 1])
224
+ r << rpath
225
+ elsif File.symlink?(path) # walk into symlinks...
226
+ r.concat(fold_files(glob(File.expand_path(path,
227
+ File.readlink(path)))))
118
228
  else
119
- file.to_s
229
+ r
120
230
  end
121
- }.compact.sort
231
+ }
122
232
  end
123
233
 
124
234
  def gem_files
125
- @gem_files ||= all_files - ignored_files
235
+ @gem_files ||= all_files.reject{ |f|
236
+ f =~ submodules_pattern ||
237
+ (f =~ ignored_pattern && !git_files.include?(f))
238
+ }
126
239
  end
127
240
 
128
- def ignored_files
129
- @ignored_file ||= all_files.select{ |path| ignore_patterns.find{ |ignore|
130
- path =~ ignore && !git_files.include?(path)}}
241
+ def test_files
242
+ @test_files ||= gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
243
+ end
244
+
245
+ def bin_files
246
+ @bin_files ||= gem_files.grep(%r{^bin/}).map{ |f| File.basename(f) }
131
247
  end
132
248
 
133
249
  def git_files
134
250
  @git_files ||= if File.exist?("#{dir}/.git")
135
- `git ls-files`.split("\n")
251
+ git('ls-files').split("\n")
136
252
  else
137
253
  []
138
254
  end
139
255
  end
140
256
 
141
- # protected
142
- def find_files path
143
- path.children.select(&:file?).map{|file| file.to_s[(dir.size+1)..-1]} +
144
- path.children.select(&:directory?).map{|dir| find_files(dir)}.flatten
257
+ def ignored_files
258
+ @ignored_files ||= all_files.grep(ignored_pattern)
259
+ end
260
+
261
+ def ignored_pattern
262
+ @ignored_pattern ||= if gitignore.empty?
263
+ /^$/
264
+ else
265
+ Regexp.new(expand_patterns(gitignore).join('|'))
266
+ end
145
267
  end
146
268
 
147
- def ignore_patterns
148
- @ignore_files ||= expand_patterns(
149
- gitignore.split("\n").reject{ |pattern|
150
- pattern.strip == ''
151
- }).map{ |pattern| %r{^([^/]+/)*?#{Regexp.escape(pattern)}(/[^/]+)*?$} }
269
+ def submodules_pattern
270
+ @submodules_pattern ||= if submodules.empty?
271
+ /^$/
272
+ else
273
+ Regexp.new(submodules.map{ |path|
274
+ "^#{Regexp.escape(path)}/" }.join('|'))
275
+ end
152
276
  end
153
277
 
154
278
  def expand_patterns pathes
155
- pathes.map{ |path|
156
- if path !~ /\*/
157
- path
158
- else
159
- expand_patterns(
160
- Dir[path] +
161
- Pathname.new(File.dirname(path)).children.select(&:directory?).
162
- map{ |prefix| "#{prefix}/#{File.basename(path)}" })
163
- end
164
- }.flatten
279
+ # http://git-scm.com/docs/gitignore
280
+ pathes.flat_map{ |path|
281
+ # we didn't implement negative pattern for now
282
+ Regexp.escape(path).sub(%r{^/}, '^').gsub(/\\\*/, '[^/]*')
283
+ }
165
284
  end
166
285
 
167
286
  def gitignore
168
- if File.exist?(path = "#{dir}/.gitignore")
169
- File.read(path)
170
- else
171
- ''
172
- end
287
+ @gitignore ||= if File.exist?(path = "#{dir}/.gitignore")
288
+ File.read(path).lines.
289
+ reject{ |l| l == /^\s*(#|\s+$)/ }.map(&:strip)
290
+ else
291
+ []
292
+ end
173
293
  end
174
294
  end
175
295
 
@@ -177,89 +297,42 @@ namespace :gem do
177
297
 
178
298
  desc 'Install gem'
179
299
  task :install => [:build] do
180
- sh("#{Gem.ruby} -S gem install pkg/#{Gemgem.gem_tag}")
300
+ Gemgem.gem_install
181
301
  end
182
302
 
183
303
  desc 'Build gem'
184
304
  task :build => [:spec] do
185
- sh("#{Gem.ruby} -S gem build #{Gemgem.spec.name}.gemspec")
186
- sh("mkdir -p pkg")
187
- sh("mv #{Gemgem.gem_tag}.gem pkg/")
305
+ Gemgem.gem_build
306
+ end
307
+
308
+ desc 'Generate gemspec'
309
+ task :spec do
310
+ Gemgem.gem_spec
188
311
  end
189
312
 
190
313
  desc 'Release gem'
191
314
  task :release => [:spec, :check, :build] do
192
- sh("git tag #{Gemgem.gem_tag}")
193
- sh("git push")
194
- sh("git push --tags")
195
- sh("#{Gem.ruby} -S gem push pkg/#{Gemgem.gem_tag}.gem")
315
+ Gemgem.gem_release
196
316
  end
197
317
 
198
318
  task :check do
199
- ver = Gemgem.spec.version.to_s
200
-
201
- if ENV['VERSION'].nil?
202
- puts("\e[35mExpected " \
203
- "\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
204
- exit(1)
205
-
206
- elsif ENV['VERSION'] != ver
207
- puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
208
- "\e[35mbut got\n " \
209
- "\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
210
- exit(2)
211
- end
319
+ Gemgem.gem_check
212
320
  end
213
321
 
214
322
  end # of gem namespace
215
323
 
216
- desc 'Run tests in memory'
324
+ desc 'Run tests'
217
325
  task :test do
218
- require 'bacon'
219
- Bacon.extend(Bacon::TestUnitOutput)
220
- Bacon.summary_on_exit
221
- $LOAD_PATH.unshift('lib')
222
- Dir['./test/**/test_*.rb'].each{ |file| require file[0..-4] }
223
- end
224
-
225
- desc 'Run tests with shell'
226
- task 'test:shell', :RUBY_OPTS do |t, args|
227
- files = Dir['test/**/test_*.rb'].join(' ')
228
-
229
- cmd = [Gem.ruby, args[:RUBY_OPTS],
230
- '-I', 'lib', '-S', 'bacon', '--quiet', files]
231
-
232
- sh(cmd.compact.join(' '))
233
- end
234
-
235
- desc 'Generate ann markdown'
236
- task 'ann:md' => ['gem:spec'] do
237
- puts Gemgem.ann_md
238
- end
239
-
240
- desc 'Generate ann html'
241
- task 'ann:html' => ['gem:spec'] do
242
- puts Gemgem.ann_html
243
- end
244
-
245
- desc 'Generate ann email'
246
- task 'ann:email' => ['gem:spec'] do
247
- puts Gemgem.ann_email
248
- end
249
-
250
- desc 'Generate rdoc'
251
- task :doc => ['gem:spec'] do
252
- sh("yardoc -o rdoc --main README.md" \
253
- " --files #{Gemgem.spec.extra_rdoc_files.join(',')}")
326
+ Gemgem.test
254
327
  end
255
328
 
256
- desc 'Remove ignored files'
329
+ desc 'Trash ignored files'
257
330
  task :clean => ['gem:spec'] do
258
- trash = "~/.Trash/#{Gemgem.spec.name}/"
259
- sh "mkdir -p #{trash}" unless File.exist?(File.expand_path(trash))
260
- Gemgem.ignored_files.each{ |file| sh "mv #{file} #{trash}" }
331
+ Gemgem.clean
261
332
  end
262
333
 
263
334
  task :default do
264
- puts `#{Gem.ruby} -S #{$PROGRAM_NAME} -T`
335
+ # Is there a reliable way to do this in the current process?
336
+ # It failed miserably before between Rake versions...
337
+ exec "#{Gem.ruby} -S #{$PROGRAM_NAME} -f #{Rake.application.rakefile} -T"
265
338
  end
metadata CHANGED
@@ -1,21 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Lin Jen-Shin (godfat)
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-01-13 00:00:00.000000000 Z
11
+ date: 2018-03-14 00:00:00.000000000 Z
13
12
  dependencies: []
14
- description: ! '_Share_ the directory _here_ with [Nginx][]!
15
-
13
+ description: |-
14
+ _Share_ the directory _here_ with [Nginx][]!
16
15
  Shere would create a temporary Nginx config and run an
17
-
18
- Nginx instance to serve the directory you specified.'
16
+ Nginx instance to serve the directory you specified.
19
17
  email:
20
18
  - godfat (XD) godfat.org
21
19
  executables:
@@ -23,8 +21,8 @@ executables:
23
21
  extensions: []
24
22
  extra_rdoc_files: []
25
23
  files:
26
- - .gitignore
27
- - .gitmodules
24
+ - ".gitignore"
25
+ - ".gitmodules"
28
26
  - CHANGES.md
29
27
  - Gemfile
30
28
  - LICENSE
@@ -36,30 +34,30 @@ files:
36
34
  - lib/shere/runner.rb
37
35
  - lib/shere/version.rb
38
36
  - shere.gemspec
39
- - task/.gitignore
37
+ - task/README.md
40
38
  - task/gemgem.rb
41
39
  homepage: https://github.com/godfat/shere
42
- licenses: []
40
+ licenses:
41
+ - Apache-2.0
42
+ metadata: {}
43
43
  post_install_message:
44
44
  rdoc_options: []
45
45
  require_paths:
46
46
  - lib
47
47
  required_ruby_version: !ruby/object:Gem::Requirement
48
- none: false
49
48
  requirements:
50
- - - ! '>='
49
+ - - ">="
51
50
  - !ruby/object:Gem::Version
52
51
  version: '0'
53
52
  required_rubygems_version: !ruby/object:Gem::Requirement
54
- none: false
55
53
  requirements:
56
- - - ! '>='
54
+ - - ">="
57
55
  - !ruby/object:Gem::Version
58
56
  version: '0'
59
57
  requirements: []
60
58
  rubyforge_project:
61
- rubygems_version: 1.8.15
59
+ rubygems_version: 2.7.6
62
60
  signing_key:
63
- specification_version: 3
61
+ specification_version: 4
64
62
  summary: _Share_ the directory _here_ with [Nginx][]!
65
63
  test_files: []
@@ -1 +0,0 @@
1
- *.rbc