gem-compact 0.5.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: abcb8919a1aaf5941bb9cb74b82f847be0459f4c7d8cdda2e40f36a19fd6a7da
4
+ data.tar.gz: dfd4265464da6fc82450924eded075c590adbfdd40ccefb90c2eb99e0e29bb15
5
+ SHA512:
6
+ metadata.gz: 714ef890f7ce2556d0c31514401776fb37c71ac6492957389d3b214fb0656325340bb7dbcd39a07d26af6946a8324d9cb3ed1fd112332451194cf9adb01d92bd
7
+ data.tar.gz: e30adc4897dd655ea5b6a4d15c899082988656cade2ce352b4ceaff8cc5a900834e0ebfb9b03c747b9a6159107085c1b609912479aaf43bc9028381842adb608
@@ -0,0 +1,3 @@
1
+ [submodule "task"]
2
+ path = task
3
+ url = git://github.com/godfat/gemgem.git
@@ -0,0 +1,5 @@
1
+ # CHANGES
2
+
3
+ ## gem-compact 0.5.0 -- 2017-12-25
4
+
5
+ * Birthday!
@@ -0,0 +1,52 @@
1
+ # gem-compact [![Build Status](https://secure.travis-ci.org/godfat/gem-compact.png?branch=master)](http://travis-ci.org/godfat/gem-compact)
2
+
3
+ by Lin Jen-Shin ([godfat](http://godfat.org))
4
+
5
+ ## LINKS:
6
+
7
+ * [github](https://github.com/godfat/gem-compact)
8
+ * [rubygems](https://rubygems.org/gems/gem-compact)
9
+
10
+ ## DESCRIPTION:
11
+
12
+ Clean up gems for all the paths, including development dependencies.
13
+
14
+ This is mainly to cleanup gems installed with `--user-install`, because
15
+ `gem cleanup` would not try to cleanup gems installed there, and would also
16
+ ignore development dependencies. With `gem compact` it would try to cleanup
17
+ everything it could.
18
+
19
+ ## REQUIREMENTS:
20
+
21
+ * Tested with MRI (official CRuby), Rubinius and JRuby.
22
+
23
+ ## INSTALLATION:
24
+
25
+ gem install gem-compact
26
+
27
+ ## SYNOPSIS:
28
+
29
+ gem compact # For all the gems
30
+ gem compact rake # For a particular gem
31
+
32
+ ## CONTRIBUTORS:
33
+
34
+ * Lin Jen-Shin (@godfat)
35
+
36
+ ## LICENSE:
37
+
38
+ Apache License 2.0 (Apache-2)
39
+
40
+ Copyright (c) 2017, Lin Jen-Shin (godfat)
41
+
42
+ Licensed under the Apache License, Version 2.0 (the "License");
43
+ you may not use this file except in compliance with the License.
44
+ You may obtain a copy of the License at
45
+
46
+ <http://www.apache.org/licenses/LICENSE-2.0>
47
+
48
+ Unless required by applicable law or agreed to in writing, software
49
+ distributed under the License is distributed on an "AS IS" BASIS,
50
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
51
+ See the License for the specific language governing permissions and
52
+ limitations under the License.
@@ -0,0 +1,12 @@
1
+
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
8
+
9
+ Gemgem.init(__dir__) do |s|
10
+ s.name = 'gem-compact'
11
+ s.version = '0.5.0'
12
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # stub: gem-compact 0.5.0 ruby lib
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "gem-compact".freeze
6
+ s.version = "0.5.0"
7
+
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 = "2017-12-25"
12
+ s.description = "Clean up gems for all the paths, including development dependencies.\n\nThis is mainly to cleanup gems installed with `--user-install`, because\n`gem cleanup` would not try to cleanup gems installed there, and would also\nignore development dependencies. With `gem compact` it would try to cleanup\neverything it could.".freeze
13
+ s.email = ["godfat (XD) godfat.org".freeze]
14
+ s.files = [
15
+ ".gitmodules".freeze,
16
+ "CHANGES.md".freeze,
17
+ "README.md".freeze,
18
+ "Rakefile".freeze,
19
+ "gem-compact.gemspec".freeze,
20
+ "lib/rubygems/commands/compact_command.rb".freeze,
21
+ "lib/rubygems_plugin.rb".freeze,
22
+ "pkg/gem-compact-0.5.0.gem".freeze,
23
+ "task/README.md".freeze,
24
+ "task/gemgem.rb".freeze]
25
+ s.homepage = "https://github.com/godfat/gem-compact".freeze
26
+ s.licenses = ["Apache-2".freeze]
27
+ s.rubygems_version = "2.7.3".freeze
28
+ s.summary = "Clean up gems for all the paths, including development dependencies.".freeze
29
+ end
@@ -0,0 +1,37 @@
1
+
2
+ class Gem::Commands::CompactCommand < Gem::Command
3
+ def description
4
+ 'Clean up gems for all the paths'
5
+ end
6
+
7
+ def initialize
8
+ super('compact', description)
9
+ end
10
+
11
+ def execute
12
+ require 'rubygems/commands/cleanup_command'
13
+
14
+ cmd = Gem::Commands::CleanupCommand.new
15
+ args, build_args = options.values_at(:args, :build_args)
16
+ args.unshift('--no-check-development')
17
+
18
+ with_path do
19
+ cmd.invoke_with_build_args(args, build_args)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def with_path
26
+ path = Gem.path
27
+ path.each do |dir|
28
+ if Dir.exist?(dir)
29
+ say "Checking #{dir}"
30
+ Gem.use_paths(dir)
31
+ yield
32
+ end
33
+ end
34
+ ensure
35
+ Gem.use_paths(*path)
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+
2
+ require 'rubygems/command_manager'
3
+ Gem::CommandManager.instance.register_command(:compact)
Binary file
@@ -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.
@@ -0,0 +1,338 @@
1
+
2
+ module Gemgem
3
+ class << self
4
+ attr_accessor :dir, :spec, :submodules, :spec_create
5
+ end
6
+
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
+
24
+ def create
25
+ spec = Gem::Specification.new do |s|
26
+ s.authors = ['Lin Jen-Shin (godfat)']
27
+ s.email = ['godfat (XD) godfat.org']
28
+
29
+ s.description = description.join
30
+ s.summary = description.first
31
+ s.license = license
32
+
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)
39
+ spec.homepage ||= "https://github.com/godfat/#{spec.name}"
40
+ self.spec = spec
41
+ end
42
+
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"
57
+ end
58
+
59
+ def gem_spec
60
+ create
61
+ write
62
+ end
63
+
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"
74
+ end
75
+
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)
81
+ end
82
+
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)
95
+
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)
101
+ end
102
+ end
103
+
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]}" }
125
+ end
126
+
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"
144
+ end
145
+
146
+ def write
147
+ File.open(spec_path, 'w'){ |f| f << split_lines(spec.to_ruby) }
148
+ end
149
+
150
+ def split_lines ruby
151
+ ruby.gsub(/(.+?)\s*=\s*\[(.+?)\]/){ |s|
152
+ if $2.index(',')
153
+ "#{$1} = [\n #{$2.split(',').map(&:strip).join(",\n ")}]"
154
+ else
155
+ s
156
+ end
157
+ }
158
+ end
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
+
216
+ def all_files
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)))))
228
+ else
229
+ r
230
+ end
231
+ }
232
+ end
233
+
234
+ def gem_files
235
+ @gem_files ||= all_files.reject{ |f|
236
+ f =~ submodules_pattern ||
237
+ (f =~ ignored_pattern && !git_files.include?(f))
238
+ }
239
+ end
240
+
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) }
247
+ end
248
+
249
+ def git_files
250
+ @git_files ||= if File.exist?("#{dir}/.git")
251
+ git('ls-files').split("\n")
252
+ else
253
+ []
254
+ end
255
+ end
256
+
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
267
+ end
268
+
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
276
+ end
277
+
278
+ def expand_patterns pathes
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
+ }
284
+ end
285
+
286
+ def gitignore
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
293
+ end
294
+ end
295
+
296
+ namespace :gem do
297
+
298
+ desc 'Install gem'
299
+ task :install => [:build] do
300
+ Gemgem.gem_install
301
+ end
302
+
303
+ desc 'Build gem'
304
+ task :build => [:spec] do
305
+ Gemgem.gem_build
306
+ end
307
+
308
+ desc 'Generate gemspec'
309
+ task :spec do
310
+ Gemgem.gem_spec
311
+ end
312
+
313
+ desc 'Release gem'
314
+ task :release => [:spec, :check, :build] do
315
+ Gemgem.gem_release
316
+ end
317
+
318
+ task :check do
319
+ Gemgem.gem_check
320
+ end
321
+
322
+ end # of gem namespace
323
+
324
+ desc 'Run tests'
325
+ task :test do
326
+ Gemgem.test
327
+ end
328
+
329
+ desc 'Trash ignored files'
330
+ task :clean => ['gem:spec'] do
331
+ Gemgem.clean
332
+ end
333
+
334
+ task :default do
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"
338
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem-compact
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Lin Jen-Shin (godfat)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ Clean up gems for all the paths, including development dependencies.
15
+
16
+ This is mainly to cleanup gems installed with `--user-install`, because
17
+ `gem cleanup` would not try to cleanup gems installed there, and would also
18
+ ignore development dependencies. With `gem compact` it would try to cleanup
19
+ everything it could.
20
+ email:
21
+ - godfat (XD) godfat.org
22
+ executables: []
23
+ extensions: []
24
+ extra_rdoc_files: []
25
+ files:
26
+ - ".gitmodules"
27
+ - CHANGES.md
28
+ - README.md
29
+ - Rakefile
30
+ - gem-compact.gemspec
31
+ - lib/rubygems/commands/compact_command.rb
32
+ - lib/rubygems_plugin.rb
33
+ - pkg/gem-compact-0.5.0.gem
34
+ - task/README.md
35
+ - task/gemgem.rb
36
+ homepage: https://github.com/godfat/gem-compact
37
+ licenses:
38
+ - Apache-2
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.7.3
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Clean up gems for all the paths, including development dependencies.
60
+ test_files: []