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