ggem 1.9.1 → 1.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/README.md +0 -3
- data/ggem.gemspec +3 -3
- data/lib/ggem/cli.rb +45 -50
- data/lib/ggem/cli/clirb.rb +44 -48
- data/lib/ggem/cli/commands.rb +5 -39
- data/lib/ggem/gem.rb +41 -41
- data/lib/ggem/gemspec.rb +65 -70
- data/lib/ggem/git_repo.rb +37 -42
- data/lib/ggem/template.rb +50 -58
- data/lib/ggem/template_file/Gemfile.erb +2 -2
- data/lib/ggem/template_file/README.md.erb +3 -3
- data/lib/ggem/template_file/gemspec.erb +5 -6
- 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 -1
- data/lib/ggem/template_file/test_support_factory.rb.erb +0 -1
- data/lib/ggem/version.rb +1 -1
- data/log/{.gitkeep → .keep} +0 -0
- data/test/support/cmd_tests_helpers.rb +33 -38
- data/test/support/factory.rb +0 -1
- data/test/support/name_set.rb +53 -59
- data/test/system/ggem_tests.rb +0 -5
- data/test/unit/cli_tests.rb +0 -31
- data/test/unit/gem_tests.rb +0 -4
- data/test/unit/gemspec_tests.rb +1 -8
- data/test/unit/git_repo_tests.rb +1 -12
- metadata +10 -12
- data/lib/ggem/template_file/circleci_config.yml.erb +0 -82
data/lib/ggem/gemspec.rb
CHANGED
@@ -1,85 +1,80 @@
|
|
1
1
|
require "pathname"
|
2
2
|
require "scmd"
|
3
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
|
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
1
|
require "pathname"
|
2
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,70 +1,62 @@
|
|
1
1
|
require "erb"
|
2
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 ".circleci"
|
15
|
-
save_folder "lib/#{@gem.ruby_name}"
|
16
|
-
save_folder "test/support"
|
17
|
-
save_folder "test/system"
|
18
|
-
save_folder "test/unit"
|
19
|
-
save_folder "log"
|
20
|
-
save_folder "tmp"
|
21
|
-
|
22
|
-
save_file("circleci_config.yml.erb", ".circleci/config.yml")
|
23
|
-
|
24
|
-
save_file("ruby-version.erb", ".ruby-version")
|
25
|
-
save_file("gitignore.erb", ".gitignore")
|
26
|
-
save_file("Gemfile.erb", "Gemfile")
|
27
|
-
save_file("gemspec.erb", "#{@gem.name}.gemspec")
|
28
|
-
save_file("README.md.erb", "README.md")
|
29
|
-
save_file("LICENSE.erb", "LICENSE")
|
30
|
-
|
31
|
-
save_file("lib.rb.erb", "lib/#{@gem.ruby_name}.rb")
|
32
|
-
save_file("lib_version.rb.erb", "lib/#{@gem.ruby_name}/version.rb")
|
33
|
-
|
34
|
-
save_file("test_helper.rb.erb", "test/helper.rb")
|
35
|
-
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
|
36
9
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
42
37
|
|
43
|
-
|
38
|
+
private
|
44
39
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
40
|
+
def save_folder(relative_path=nil)
|
41
|
+
path = File.join([@ggem.path, relative_path].compact)
|
42
|
+
FileUtils.mkdir_p(path)
|
43
|
+
end
|
49
44
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
45
|
+
def save_empty_file(relative_path)
|
46
|
+
path = File.join(@ggem.path, relative_path)
|
47
|
+
FileUtils.touch(path)
|
48
|
+
end
|
54
49
|
|
55
|
-
|
56
|
-
|
57
|
-
|
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)
|
58
53
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
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"
|
66
60
|
end
|
67
|
-
|
68
61
|
end
|
69
|
-
|
70
62
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# <%= @
|
1
|
+
# <%= @ggem.module_name %>
|
2
2
|
|
3
3
|
TODO: Write a gem description
|
4
4
|
|
@@ -10,7 +10,7 @@ TODO: Write code samples and usage instructions here
|
|
10
10
|
|
11
11
|
Add this line to your application's Gemfile:
|
12
12
|
|
13
|
-
gem "<%= @
|
13
|
+
gem "<%= @ggem.name %>"
|
14
14
|
|
15
15
|
And then execute:
|
16
16
|
|
@@ -18,7 +18,7 @@ And then execute:
|
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
$ gem install <%= @
|
21
|
+
$ gem install <%= @ggem.name %>
|
22
22
|
|
23
23
|
## Contributing
|
24
24
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "<%= @
|
4
|
+
require "<%= @ggem.ruby_name %>/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name = "<%= @
|
8
|
-
gem.version = <%= @
|
7
|
+
gem.name = "<%= @ggem.name %>"
|
8
|
+
gem.version = <%= @ggem.module_name %>::VERSION
|
9
9
|
gem.authors = ["TODO: authors"]
|
10
10
|
gem.email = ["TODO: emails"]
|
11
11
|
gem.summary = "TODO: Write a gem summary"
|
@@ -18,10 +18,9 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.required_ruby_version =
|
21
|
+
gem.required_ruby_version = "~> 2.5"
|
22
22
|
|
23
|
-
gem.add_development_dependency("assert", ["~> 2.
|
23
|
+
gem.add_development_dependency("assert", ["~> 2.18.2"])
|
24
24
|
|
25
25
|
# TODO: gem.add_dependency("gem-name", ["~> 0.0.0"])
|
26
|
-
|
27
26
|
end
|
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.5
|