gem-sweep 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/lib/rubygems/commands/sweep_command.rb +49 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5c68c560cc9e65be251fe942759ebd0cffcaa4eac563404e0e64d16c1e43684
|
4
|
+
data.tar.gz: 97cd1b17370e0f5d54ba9964db4c219475367c2fd864e89e12cb17e3480f3eba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7712862259767144e657591e907ae08859c0db1b25a161b45280eb4e05e43d7b1745c3c9ddbdd547812215854d1ae2b6cec7d00b564fe7b6d2b88b823e9eea4
|
7
|
+
data.tar.gz: 92c659ecf2aebbfa1f56b9461ed24366710cf338c2a72fa0cf578c14d06a269bd85d3c176fc8764af13507f42e0defb1b8fc67fd59c96be1cf0894b50f3c3189
|
@@ -3,7 +3,15 @@ require "pathname"
|
|
3
3
|
require "rubygems/command"
|
4
4
|
|
5
5
|
module GemSweep
|
6
|
-
def self.clean(spec, aggressive: false)
|
6
|
+
def self.clean(spec, aggressive: false, dryrun: false)
|
7
|
+
targets = collect_cleanup_targets(spec, aggressive: aggressive)
|
8
|
+
remove_targets(targets, dryrun: dryrun)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.collect_cleanup_targets(spec, aggressive: false)
|
12
|
+
targets = []
|
13
|
+
|
14
|
+
# Collect extension files
|
7
15
|
(spec.full_require_paths - [spec.extension_dir]).each do |path|
|
8
16
|
begin
|
9
17
|
Dir.glob(File.join(path, "**/*")).each do |file|
|
@@ -11,30 +19,45 @@ module GemSweep
|
|
11
19
|
next if file.sub(/#{spec.full_gem_path}\//, "") =~ /(\d+\.\d+\/)/
|
12
20
|
|
13
21
|
if Pathname(file).extname == ".#{RbConfig::CONFIG["DLEXT"]}"
|
14
|
-
|
15
|
-
puts "Delete #{file}"
|
22
|
+
targets << file
|
16
23
|
end
|
17
24
|
end
|
18
25
|
rescue Errno::EPERM
|
19
26
|
end
|
20
27
|
end
|
21
28
|
|
29
|
+
# Collect development directories if aggressive mode
|
22
30
|
if aggressive
|
23
|
-
|
31
|
+
# Collect test/spec/features directories
|
32
|
+
%w[test spec features].each do |dir_name|
|
33
|
+
dir_path = File.join(spec.full_gem_path, dir_name)
|
34
|
+
targets << dir_path if Dir.exist?(dir_path)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Collect tmp directories recursively
|
38
|
+
begin
|
39
|
+
Dir.glob(File.join(spec.full_gem_path, "**/tmp")).each do |tmp_dir|
|
40
|
+
targets << tmp_dir if Dir.exist?(tmp_dir)
|
41
|
+
end
|
42
|
+
rescue Errno::EPERM
|
43
|
+
end
|
24
44
|
end
|
45
|
+
|
46
|
+
targets
|
25
47
|
end
|
26
48
|
|
27
|
-
def self.
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
49
|
+
def self.remove_targets(targets, dryrun: false)
|
50
|
+
targets.each do |path|
|
51
|
+
begin
|
52
|
+
if dryrun
|
53
|
+
puts "Would delete #{path}#{Dir.exist?(path) ? '/' : ''}"
|
54
|
+
else
|
32
55
|
require "fileutils"
|
33
|
-
FileUtils.rm_rf(
|
34
|
-
puts "Delete #{
|
35
|
-
rescue Errno::EPERM
|
36
|
-
puts "Permission denied: #{test_dir}/"
|
56
|
+
FileUtils.rm_rf(path)
|
57
|
+
puts "Delete #{path}#{Dir.exist?(path) ? '/' : ''}"
|
37
58
|
end
|
59
|
+
rescue Errno::EPERM
|
60
|
+
puts "Permission denied: #{path}#{Dir.exist?(path) ? '/' : ''}"
|
38
61
|
end
|
39
62
|
end
|
40
63
|
end
|
@@ -43,18 +66,28 @@ end
|
|
43
66
|
class Gem::Commands::SweepCommand < Gem::Command
|
44
67
|
def initialize
|
45
68
|
super "sweep", "Clean up unnecessary extension files"
|
46
|
-
|
69
|
+
|
47
70
|
add_option("-a", "--aggressive", "Also remove test, spec, and features directories") do |value, options|
|
48
71
|
options[:aggressive] = true
|
49
72
|
end
|
73
|
+
|
74
|
+
add_option("-n", "--dryrun", "Show what would be deleted without actually deleting") do |value, options|
|
75
|
+
options[:dryrun] = true
|
76
|
+
end
|
50
77
|
end
|
51
78
|
|
52
79
|
def execute
|
53
80
|
aggressive = options[:aggressive]
|
54
|
-
|
81
|
+
dryrun = options[:dryrun]
|
82
|
+
|
83
|
+
if dryrun
|
84
|
+
puts "Dry run mode: showing what would be deleted"
|
85
|
+
puts
|
86
|
+
end
|
87
|
+
|
55
88
|
Gem::Specification.each do |spec|
|
56
89
|
if aggressive || !spec.extensions.empty?
|
57
|
-
GemSweep.clean(spec, aggressive: aggressive)
|
90
|
+
GemSweep.clean(spec, aggressive: aggressive, dryrun: dryrun)
|
58
91
|
end
|
59
92
|
end
|
60
93
|
end
|