ggem 1.8.1 → 1.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/Gemfile +3 -1
- data/README.md +2 -2
- data/bin/ggem +1 -1
- data/ggem.gemspec +8 -6
- data/lib/ggem.rb +2 -2
- data/lib/ggem/cli.rb +49 -54
- data/lib/ggem/cli/clirb.rb +44 -48
- data/lib/ggem/cli/commands.rb +23 -56
- data/lib/ggem/gem.rb +43 -43
- data/lib/ggem/gemspec.rb +68 -73
- data/lib/ggem/git_repo.rb +39 -44
- data/lib/ggem/template.rb +52 -54
- data/lib/ggem/template_file/Gemfile.erb +3 -1
- data/lib/ggem/template_file/README.md.erb +4 -4
- data/lib/ggem/template_file/gemspec.erb +10 -8
- data/lib/ggem/template_file/lib.rb.erb +2 -2
- data/lib/ggem/template_file/lib_version.rb.erb +1 -1
- data/lib/ggem/template_file/ruby-version.erb +1 -0
- data/lib/ggem/template_file/test_helper.rb.erb +2 -11
- data/lib/ggem/template_file/test_support_factory.rb.erb +1 -2
- data/lib/ggem/version.rb +1 -1
- data/log/.keep +0 -0
- data/test/helper.rb +6 -15
- data/test/support/cmd_tests_helpers.rb +35 -40
- data/test/support/factory.rb +1 -2
- data/test/support/gem1/gem1.gemspec +1 -1
- data/test/support/gem2/gem2.gemspec +2 -2
- data/test/support/name_set.rb +53 -53
- data/test/system/ggem_tests.rb +7 -12
- data/test/unit/cli_tests.rb +100 -121
- data/test/unit/gem_tests.rb +1 -5
- data/test/unit/gemspec_tests.rb +19 -26
- data/test/unit/git_repo_tests.rb +3 -14
- metadata +64 -57
- data/.gitignore +0 -19
data/lib/ggem/gem.rb
CHANGED
@@ -1,58 +1,58 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "fileutils"
|
2
|
+
require "ggem/template"
|
3
3
|
|
4
|
-
module GGem
|
4
|
+
module GGem; end
|
5
|
+
class GGem::Gem
|
6
|
+
NoNameError = Class.new(ArgumentError)
|
5
7
|
|
6
|
-
|
8
|
+
attr_reader :root_path, :name
|
7
9
|
|
8
|
-
|
10
|
+
def initialize(path, name)
|
11
|
+
raise NoNameError if name.to_s.empty?
|
12
|
+
@root_path, self.name = path, name
|
13
|
+
end
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
def save!
|
16
|
+
GGem::Template.new(self).save
|
17
|
+
self
|
18
|
+
end
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
20
|
+
def path
|
21
|
+
File.join(@root_path, @name)
|
22
|
+
end
|
19
23
|
|
20
|
-
|
21
|
-
|
24
|
+
def name=(name)
|
25
|
+
@name = normalize_name(name)
|
26
|
+
end
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def module_name
|
29
|
+
transforms = {
|
30
|
+
"_" => "",
|
31
|
+
"-" => ""
|
32
|
+
}
|
33
|
+
@module_name ||= transform_name(transforms){ |part| part.capitalize }
|
34
|
+
end
|
30
35
|
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
def ruby_name
|
37
|
+
@ruby_name ||= transform_name{ |part| part.downcase }
|
38
|
+
end
|
34
39
|
|
35
|
-
|
40
|
+
private
|
36
41
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
def normalize_name(name)
|
43
|
+
und_camelcs = [/([A-Z])([a-z])/, '_\1\2']
|
44
|
+
rm_dup_und = [/_+/, "_"]
|
45
|
+
rm_lead_und = [/^_/, "" ]
|
46
|
+
name.gsub(*und_camelcs).gsub(*rm_dup_und).sub(*rm_lead_und).downcase
|
47
|
+
end
|
43
48
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
49
|
+
def transform_name(conditions = {}, &block)
|
50
|
+
n = (block ? block.call(self.name) : self.name)
|
51
|
+
conditions.each do |on, glue|
|
52
|
+
if (a = n.split(on)).size > 1
|
53
|
+
n = a.map{ |part| block.call(part) if block }.join(glue)
|
50
54
|
end
|
51
|
-
n
|
52
55
|
end
|
53
|
-
|
54
|
-
NoNameError = Class.new(ArgumentError)
|
55
|
-
|
56
|
+
n
|
56
57
|
end
|
57
|
-
|
58
58
|
end
|
data/lib/ggem/gemspec.rb
CHANGED
@@ -1,85 +1,80 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
|
4
|
-
module GGem
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
run_cmd("gem build --verbose #{@path}").tap do
|
35
|
-
gem_path = @root.join(@gem_file_name)
|
36
|
-
run_cmd("mkdir -p #{@built_gem_path.dirname}")
|
37
|
-
run_cmd("mv #{gem_path} #{@built_gem_path}")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def run_install_cmd
|
42
|
-
run_cmd("gem install #{@built_gem_path}")
|
43
|
-
end
|
1
|
+
require "pathname"
|
2
|
+
require "scmd"
|
3
|
+
|
4
|
+
module GGem; end
|
5
|
+
class GGem::Gemspec
|
6
|
+
PUSH_HOST_META_KEY = "allowed_push_host"
|
7
|
+
DEFAULT_PUSH_HOST = "https://rubygems.org".freeze
|
8
|
+
BUILD_TO_DIRNAME = "pkg".freeze
|
9
|
+
|
10
|
+
NotFoundError = Class.new(ArgumentError)
|
11
|
+
LoadError = Class.new(ArgumentError)
|
12
|
+
CmdError = Class.new(RuntimeError)
|
13
|
+
|
14
|
+
attr_reader :path, :name, :version, :version_tag
|
15
|
+
attr_reader :gem_file_name, :gem_file, :push_host
|
16
|
+
|
17
|
+
def initialize(root_path)
|
18
|
+
@root = Pathname.new(File.expand_path(root_path))
|
19
|
+
raise NotFoundError unless @root.exist?
|
20
|
+
@path = Pathname.new(Dir[File.join(@root, "{,*}.gemspec")].first.to_s)
|
21
|
+
raise NotFoundError unless @path.exist?
|
22
|
+
|
23
|
+
@spec = load_gemspec(@path)
|
24
|
+
@name = @spec.name
|
25
|
+
@version = @spec.version
|
26
|
+
@version_tag = "v#{@version}"
|
27
|
+
|
28
|
+
@gem_file_name = "#{@name}-#{@version}.gem"
|
29
|
+
@gem_file = File.join(BUILD_TO_DIRNAME, @gem_file_name)
|
30
|
+
@built_gem_path = @root.join(@gem_file)
|
31
|
+
|
32
|
+
@push_host = get_push_host(@spec)
|
33
|
+
end
|
44
34
|
|
45
|
-
|
46
|
-
|
35
|
+
def run_build_cmd
|
36
|
+
run_cmd("gem build --verbose #{@path}").tap do
|
37
|
+
gem_path = @root.join(@gem_file_name)
|
38
|
+
run_cmd("mkdir -p #{@built_gem_path.dirname}")
|
39
|
+
run_cmd("mv #{gem_path} #{@built_gem_path}")
|
47
40
|
end
|
41
|
+
end
|
48
42
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
cmd = Scmd.new(cmd_string)
|
53
|
-
cmd.run
|
54
|
-
if !cmd.success?
|
55
|
-
raise CmdError, "#{cmd_string}\n" \
|
56
|
-
"#{cmd.stderr.empty? ? cmd.stdout : cmd.stderr}"
|
57
|
-
end
|
58
|
-
[cmd_string, cmd.exitstatus, cmd.stdout]
|
59
|
-
end
|
43
|
+
def run_install_cmd
|
44
|
+
run_cmd("gem install #{@built_gem_path}")
|
45
|
+
end
|
60
46
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
original_line = e.backtrace.find{ |line| line.include?(path.to_s) }
|
65
|
-
msg = "There was a #{e.class} while loading #{path.basename}: \n#{e.message}"
|
66
|
-
msg << " from\n #{original_line}" if original_line
|
67
|
-
msg << "\n"
|
68
|
-
raise LoadError, msg
|
69
|
-
end
|
47
|
+
def run_push_cmd
|
48
|
+
run_cmd("gem push #{@built_gem_path} --host #{@push_host}")
|
49
|
+
end
|
70
50
|
|
71
|
-
|
72
|
-
ENV['GGEM_PUSH_HOST'] || get_meta(spec)[PUSH_HOST_META_KEY] || DEFAULT_PUSH_HOST
|
73
|
-
end
|
51
|
+
private
|
74
52
|
|
75
|
-
|
76
|
-
|
53
|
+
def run_cmd(cmd_string)
|
54
|
+
cmd = Scmd.new(cmd_string)
|
55
|
+
cmd.run
|
56
|
+
if !cmd.success?
|
57
|
+
raise CmdError, "#{cmd_string}\n" \
|
58
|
+
"#{cmd.stderr.empty? ? cmd.stdout : cmd.stderr}"
|
77
59
|
end
|
60
|
+
[cmd_string, cmd.exitstatus, cmd.stdout]
|
61
|
+
end
|
78
62
|
|
79
|
-
|
80
|
-
|
81
|
-
|
63
|
+
def load_gemspec(path)
|
64
|
+
eval(path.read, TOPLEVEL_BINDING, path.expand_path.to_s)
|
65
|
+
rescue ScriptError, StandardError => e
|
66
|
+
original_line = e.backtrace.find{ |line| line.include?(path.to_s) }
|
67
|
+
msg = "There was a #{e.class} while loading #{path.basename}: \n#{e.message}"
|
68
|
+
msg << " from\n #{original_line}" if original_line
|
69
|
+
msg << "\n"
|
70
|
+
raise LoadError, msg
|
71
|
+
end
|
82
72
|
|
73
|
+
def get_push_host(spec)
|
74
|
+
ENV["GGEM_PUSH_HOST"] || get_meta(spec)[PUSH_HOST_META_KEY] || DEFAULT_PUSH_HOST
|
83
75
|
end
|
84
76
|
|
77
|
+
def get_meta(spec)
|
78
|
+
(spec.respond_to?(:metadata) ? spec.metadata : {}) || {}
|
79
|
+
end
|
85
80
|
end
|
data/lib/ggem/git_repo.rb
CHANGED
@@ -1,60 +1,55 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "pathname"
|
2
|
+
require "scmd"
|
3
3
|
|
4
|
-
module GGem
|
4
|
+
module GGem; end
|
5
|
+
class GGem::GitRepo
|
6
|
+
NotFoundError = Class.new(ArgumentError)
|
7
|
+
CmdError = Class.new(RuntimeError)
|
5
8
|
|
6
|
-
|
9
|
+
attr_reader :path
|
7
10
|
|
8
|
-
|
11
|
+
def initialize(repo_path)
|
12
|
+
@path = Pathname.new(File.expand_path(repo_path))
|
13
|
+
end
|
9
14
|
|
10
|
-
|
11
|
-
|
15
|
+
def run_init_cmd
|
16
|
+
run_cmd("git init").tap do
|
17
|
+
run_cmd("git add --all && git add -f *.keep")
|
12
18
|
end
|
19
|
+
end
|
13
20
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
21
|
+
def run_validate_clean_cmd
|
22
|
+
run_cmd("git diff --exit-code")
|
23
|
+
end
|
19
24
|
|
20
|
-
|
21
|
-
|
22
|
-
|
25
|
+
def run_validate_committed_cmd
|
26
|
+
run_cmd("git diff-index --quiet --cached HEAD")
|
27
|
+
end
|
23
28
|
|
24
|
-
|
25
|
-
|
29
|
+
def run_push_cmd
|
30
|
+
run_cmd("git push").tap do
|
31
|
+
run_cmd("git push --tags")
|
26
32
|
end
|
33
|
+
end
|
27
34
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
35
|
+
def run_add_version_tag_cmd(version, tag)
|
36
|
+
run_cmd("git tag -a -m \"Version #{version}\" #{tag}")
|
37
|
+
end
|
33
38
|
|
34
|
-
|
35
|
-
|
36
|
-
|
39
|
+
def run_rm_tag_cmd(tag)
|
40
|
+
run_cmd("git tag -d #{tag}")
|
41
|
+
end
|
37
42
|
|
38
|
-
|
39
|
-
run_cmd("git tag -d #{tag}")
|
40
|
-
end
|
43
|
+
private
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
raise CmdError, "#{cmd_string}\n" \
|
50
|
-
"#{cmd.stderr.empty? ? cmd.stdout : cmd.stderr}"
|
51
|
-
end
|
52
|
-
[cmd_string, cmd.exitstatus, cmd.stdout]
|
45
|
+
def run_cmd(cmd_string)
|
46
|
+
cmd_string = "cd #{@path} && #{cmd_string}"
|
47
|
+
cmd = Scmd.new(cmd_string)
|
48
|
+
cmd.run
|
49
|
+
if !cmd.success?
|
50
|
+
raise CmdError, "#{cmd_string}\n" \
|
51
|
+
"#{cmd.stderr.empty? ? cmd.stdout : cmd.stderr}"
|
53
52
|
end
|
54
|
-
|
55
|
-
NotFoundError = Class.new(ArgumentError)
|
56
|
-
CmdError = Class.new(RuntimeError)
|
57
|
-
|
53
|
+
[cmd_string, cmd.exitstatus, cmd.stdout]
|
58
54
|
end
|
59
|
-
|
60
55
|
end
|
data/lib/ggem/template.rb
CHANGED
@@ -1,64 +1,62 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "erb"
|
2
|
+
require "fileutils"
|
3
3
|
|
4
|
-
module GGem
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@gem = ggem
|
10
|
-
end
|
11
|
-
|
12
|
-
def save
|
13
|
-
save_folder # (gem root path)
|
14
|
-
save_folder "lib/#{@gem.ruby_name}"
|
15
|
-
save_folder "test/support"
|
16
|
-
save_folder "test/system"
|
17
|
-
save_folder "test/unit"
|
18
|
-
save_folder "log"
|
19
|
-
save_folder "tmp"
|
20
|
-
|
21
|
-
save_file('gitignore.erb', '.gitignore')
|
22
|
-
save_file('Gemfile.erb', 'Gemfile')
|
23
|
-
save_file('gemspec.erb', "#{@gem.name}.gemspec")
|
24
|
-
save_file('README.md.erb', 'README.md')
|
25
|
-
save_file('LICENSE.erb', 'LICENSE')
|
26
|
-
|
27
|
-
save_file('lib.rb.erb', "lib/#{@gem.ruby_name}.rb")
|
28
|
-
save_file('lib_version.rb.erb', "lib/#{@gem.ruby_name}/version.rb")
|
29
|
-
|
30
|
-
save_file('test_helper.rb.erb', 'test/helper.rb')
|
31
|
-
save_file('test_support_factory.rb.erb', 'test/support/factory.rb')
|
4
|
+
module GGem; end
|
5
|
+
class GGem::Template
|
6
|
+
def initialize(ggem)
|
7
|
+
@ggem = ggem
|
8
|
+
end
|
32
9
|
|
33
|
-
|
34
|
-
|
35
|
-
|
10
|
+
def save
|
11
|
+
save_folder # (gem root path)
|
12
|
+
save_folder "lib/#{@ggem.ruby_name}"
|
13
|
+
save_folder "test/support"
|
14
|
+
save_folder "test/system"
|
15
|
+
save_folder "test/unit"
|
16
|
+
save_folder "log"
|
17
|
+
save_folder "tmp"
|
18
|
+
|
19
|
+
save_file("ruby-version.erb", ".ruby-version")
|
20
|
+
save_file("gitignore.erb", ".gitignore")
|
21
|
+
save_file("Gemfile.erb", "Gemfile")
|
22
|
+
save_file("gemspec.erb", "#{@ggem.name}.gemspec")
|
23
|
+
save_file("README.md.erb", "README.md")
|
24
|
+
save_file("LICENSE.erb", "LICENSE")
|
25
|
+
|
26
|
+
save_file("lib.rb.erb", "lib/#{@ggem.ruby_name}.rb")
|
27
|
+
save_file("lib_version.rb.erb", "lib/#{@ggem.ruby_name}/version.rb")
|
28
|
+
|
29
|
+
save_file("test_helper.rb.erb", "test/helper.rb")
|
30
|
+
save_file("test_support_factory.rb.erb", "test/support/factory.rb")
|
31
|
+
|
32
|
+
save_empty_file("log/.keep")
|
33
|
+
save_empty_file("test/system/.keep")
|
34
|
+
save_empty_file("test/unit/.keep")
|
35
|
+
save_empty_file("tmp/.keep")
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
+
private
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
def save_folder(relative_path=nil)
|
41
|
+
path = File.join([@ggem.path, relative_path].compact)
|
42
|
+
FileUtils.mkdir_p(path)
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
def save_empty_file(relative_path)
|
46
|
+
path = File.join(@ggem.path, relative_path)
|
47
|
+
FileUtils.touch(path)
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
def save_file(source, output)
|
51
|
+
source_file = File.join(File.dirname(__FILE__), "template_file", source)
|
52
|
+
output_file = File.join(@ggem.root_path, @ggem.name, output)
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
54
|
+
if File.exists?(source_file)
|
55
|
+
FileUtils.mkdir_p(File.dirname(output_file))
|
56
|
+
erb = ERB.new(File.read(source_file))
|
57
|
+
File.open(output_file, "w") {|f| f << erb.result(binding) }
|
58
|
+
else
|
59
|
+
raise ArgumentError, "the source file `#{source_file}` does not exist"
|
60
60
|
end
|
61
|
-
|
62
61
|
end
|
63
|
-
|
64
62
|
end
|