gemusta 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -9
- data/Rakefile.rb +44 -0
- data/lib/gemusta.rb +1 -1
- data/lib/gemusta/cli.rb +29 -32
- data/lib/gemusta/gemspec_template_base.erb +17 -2
- data/spec/gemusta/cli_spec.rb +27 -14
- metadata +6 -6
data/README.md
CHANGED
@@ -13,20 +13,21 @@ But handle a gemspec should be a easy thing, I don't believe that we need add de
|
|
13
13
|
You install the gem:
|
14
14
|
|
15
15
|
gem install gemusta
|
16
|
+
|
17
|
+
###Customizing the gemspec generation
|
18
|
+
To create a new and shine `[your_project].gemspec.erb` and use it as base for your gemspec:
|
16
19
|
|
17
|
-
|
18
|
-
And now you have a executable `gemusta`. Your project don't need to know about this gem, neither your team, nobody. You just use:
|
19
|
-
|
20
|
-
gemusta
|
20
|
+
gemusta -e
|
21
21
|
|
22
|
-
|
22
|
+
Edit the generated file and then run `gemusta`. Every time you run this command it will use your customized .erb file or fallback to the internal one to produce a gemspec file.
|
23
23
|
|
24
|
-
###
|
25
|
-
|
24
|
+
###Opinionated?
|
25
|
+
Gemusta make some assumptions:
|
26
26
|
|
27
|
-
|
27
|
+
* Your project version should be a constant on a your_project/your_poroject.rb
|
28
|
+
* You should be using git
|
28
29
|
|
29
|
-
|
30
|
+
But these are just opinions, and they are expressed in some functions on top of the erb file. If you don't follow this conventions, you can just edit the erb and provide change the methods which discover the version for your project, the files that your gem need and so on.
|
30
31
|
|
31
32
|
# The End
|
32
33
|
And this is all, period.
|
data/Rakefile.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require './lib/gemusta'
|
2
|
+
|
1
3
|
task :default => [:specs]
|
2
4
|
task :specs => [:"specs:all"]
|
3
5
|
namespace :specs do
|
@@ -6,4 +8,46 @@ namespace :specs do
|
|
6
8
|
t.pattern = "spec/**/*_spec.rb"
|
7
9
|
t.rspec_opts = ['--color', '--format documentation', '--require spec_helper']
|
8
10
|
end
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "generate gemspec, build and push the gem"
|
14
|
+
task :release => [:"gem:release"]
|
15
|
+
|
16
|
+
namespace :gem do
|
17
|
+
task :gemspec do
|
18
|
+
system "./bin/gemusta"
|
19
|
+
system "gem build gemusta.gemspec"
|
20
|
+
end
|
21
|
+
|
22
|
+
task :local => [:"gem:gemspec"] do
|
23
|
+
if $?.exitstatus > 0
|
24
|
+
raise "gemspec was not generated, exit status #{$?.exitstatus}"
|
25
|
+
end
|
26
|
+
system "gem uninstall gemusta"
|
27
|
+
system "gem install gemusta-#{Gemusta::VERSION}.gem --no-rdoc --no-ri"
|
28
|
+
end
|
29
|
+
|
30
|
+
task :check => [:"gem:local"] do
|
31
|
+
if $?.exitstatus > 0
|
32
|
+
raise "gemusta not installed, exit status #{$?.exitstatus}"
|
33
|
+
end
|
34
|
+
not_correct_installed = `gemusta -v`.strip != Gemusta::VERSION
|
35
|
+
if not_correct_installed
|
36
|
+
raise "impossible to retrieve current version"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :release => [:"gem:check"] do
|
41
|
+
if $?.exitstatus > 0
|
42
|
+
raise "gem build failed, exit status #{$?.exitstatus}"
|
43
|
+
end
|
44
|
+
gem_file = "gemusta-#{Gemusta::VERSION}.gem"
|
45
|
+
puts "preparing to push #{gem_file}"
|
46
|
+
system "gem push gemusta-#{Gemusta::VERSION}.gem"
|
47
|
+
if $?.exitstatus > 0
|
48
|
+
raise "oops, not enough mana to push the gem"
|
49
|
+
else
|
50
|
+
puts "gemusta? Me gusta!"
|
51
|
+
end
|
52
|
+
end
|
9
53
|
end
|
data/lib/gemusta.rb
CHANGED
data/lib/gemusta/cli.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'optparse'
|
2
|
+
require 'gemusta'
|
2
3
|
|
3
4
|
module Gemusta
|
4
5
|
|
@@ -7,23 +8,21 @@ module Gemusta
|
|
7
8
|
attr_accessor :variables
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
def run(args=ARGV)
|
12
|
+
options = parse_options ARGV,
|
13
|
+
:erb => false
|
14
|
+
if (options[:show_version])
|
15
|
+
puts Gemusta::VERSION
|
16
|
+
exit(0)
|
17
|
+
end
|
18
|
+
create_erb if options[:erb]
|
19
|
+
create_gemspec if !options[:erb]
|
18
20
|
end
|
19
|
-
|
21
|
+
|
20
22
|
def create_gemspec
|
21
23
|
template_file = File.exists?(erb_name) ? erb_name : template_path
|
22
|
-
puts "adskfnalkfakldfjakdsjfalkjfdakljfklasdjfklasjdfklasdf"
|
23
|
-
puts IO.read(template_file)
|
24
24
|
erb = ERB.new(IO.read(template_file))
|
25
25
|
erb_result = erb.result(template_variables)
|
26
|
-
puts erb_result
|
27
26
|
File.open(gemspec_name, "w") do |file|
|
28
27
|
file.write(erb_result)
|
29
28
|
end
|
@@ -36,39 +35,37 @@ module Gemusta
|
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
39
|
-
|
40
|
-
def run(args=ARGV)
|
41
|
-
options = parse_options ARGV,
|
42
|
-
:erb => false,
|
43
|
-
:gemspec => true
|
44
|
-
create_erb if options[:erb]
|
45
|
-
create_gemspec if options[:gemspec]
|
46
|
-
end
|
47
38
|
|
48
39
|
private
|
40
|
+
def project_name
|
41
|
+
File.basename(File.expand_path("."))
|
42
|
+
end
|
43
|
+
|
49
44
|
def template_variables
|
50
45
|
cli = self
|
51
46
|
vars = CLI.variables || {}
|
52
47
|
|
53
|
-
Object.new.instance_eval
|
54
|
-
@name
|
55
|
-
@version
|
56
|
-
|
48
|
+
Object.new.instance_eval do
|
49
|
+
@name = vars[:name]
|
50
|
+
@version = vars[:version]
|
51
|
+
@files = vars[:files]
|
52
|
+
@test_files = vars[:test_files]
|
53
|
+
@executable_files = vars[:executable_files]
|
57
54
|
binding
|
58
|
-
|
55
|
+
end
|
59
56
|
end
|
60
57
|
|
61
58
|
def parse_options(args, options={})
|
62
59
|
parser = OptionParser.new do |opts|
|
63
|
-
opts.banner = "
|
60
|
+
opts.banner = "Gemusta v#{Gemusta::VERSION}"
|
61
|
+
opts.banner << " :: generate your gemspec in advance :: Usage: gemusta [options]"
|
64
62
|
|
65
63
|
opts.on "-e", "--erb", "Creates erb file" do
|
66
64
|
options[:erb] = true
|
67
65
|
end
|
68
|
-
|
69
|
-
opts.on "-
|
70
|
-
options[:
|
71
|
-
options[:gemspec] = true
|
66
|
+
|
67
|
+
opts.on "-v", "--version", "Show installed gem version" do
|
68
|
+
options[:show_version] = true
|
72
69
|
end
|
73
70
|
end
|
74
71
|
|
@@ -85,8 +82,8 @@ module Gemusta
|
|
85
82
|
end
|
86
83
|
|
87
84
|
def gemspec_name
|
88
|
-
"#{
|
85
|
+
"#{project_name}.gemspec"
|
89
86
|
end
|
90
87
|
|
91
|
-
end
|
88
|
+
end # CLI
|
92
89
|
end
|
@@ -1,5 +1,20 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
<%
|
3
|
+
def lib
|
4
|
+
File.expand_path('../lib/', __FILE__)
|
5
|
+
end
|
6
|
+
|
7
|
+
def name
|
8
|
+
@name || File.basename(File.expand_path("."))
|
9
|
+
end
|
10
|
+
|
11
|
+
def version # This one is directly from: https://github.com/mojombo/rakegem/blob/master/Rakefile
|
12
|
+
@version || lambda {
|
13
|
+
line = File.read(File.join(lib, "#{name}.rb"))[/^\s*VERSION\s*=\s*.*/]
|
14
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
15
|
+
}.call
|
16
|
+
end
|
17
|
+
|
3
18
|
def git_files(param=nil)
|
4
19
|
`git ls-files #{param}`.split("\n")
|
5
20
|
end
|
@@ -22,8 +37,8 @@ lib = File.expand_path('../lib/', __FILE__)
|
|
22
37
|
$:.unshift lib unless $:.include?(lib)
|
23
38
|
|
24
39
|
Gem::Specification.new do |s|
|
25
|
-
s.name = "<%=
|
26
|
-
s.version = "<%=
|
40
|
+
s.name = "<%= name %>"
|
41
|
+
s.version = "<%= version %>"
|
27
42
|
s.platform = Gem::Platform::RUBY
|
28
43
|
s.authors = ["your name here"]
|
29
44
|
s.email = ["you_email@your_site", "omg@team_member.com"]
|
data/spec/gemusta/cli_spec.rb
CHANGED
@@ -20,14 +20,6 @@ module Gemusta
|
|
20
20
|
@cli = CLI.new
|
21
21
|
end
|
22
22
|
|
23
|
-
it "discover the project name by the execution dir" do
|
24
|
-
@cli.project_name.should == project_name
|
25
|
-
end
|
26
|
-
|
27
|
-
it "use 'main project file' convension to discover the version" do
|
28
|
-
@cli.project_version.should == Gemusta::VERSION
|
29
|
-
end
|
30
|
-
|
31
23
|
context "file generation" do
|
32
24
|
|
33
25
|
it "should create gemusta.gemspec file" do
|
@@ -48,6 +40,27 @@ module Gemusta
|
|
48
40
|
end
|
49
41
|
end # "file generation"
|
50
42
|
|
43
|
+
context "erb functions" do
|
44
|
+
|
45
|
+
before do
|
46
|
+
@cli.create_erb
|
47
|
+
end
|
48
|
+
|
49
|
+
it "discover the project name by the execution dir" do
|
50
|
+
File.open(erb_name, "a") {|file| file.write "\n'<%= name %>'"}
|
51
|
+
system executable
|
52
|
+
name = eval(IO.read(gemspec_name))
|
53
|
+
name.should == project_name
|
54
|
+
end
|
55
|
+
|
56
|
+
it "use 'main project file' convension to discover the version" do
|
57
|
+
File.open(erb_name, "a") {|file| file.write "\n'<%= version %>'"}
|
58
|
+
system executable
|
59
|
+
version = eval(IO.read(gemspec_name))
|
60
|
+
version.should == Gemusta::VERSION
|
61
|
+
end
|
62
|
+
end # erb functions
|
63
|
+
|
51
64
|
context "command (line) execution" do
|
52
65
|
|
53
66
|
it "gemusta: create gemspec" do
|
@@ -60,15 +73,10 @@ module Gemusta
|
|
60
73
|
system "#{executable} -e"
|
61
74
|
File.exists?(erb_name).should be_true
|
62
75
|
end
|
63
|
-
|
64
|
-
it "gemusta -a: create both (erb and gemspec)" do
|
65
|
-
system "#{executable} -a"
|
66
|
-
File.exists?(gemspec_name).should be_true
|
67
|
-
File.exists?(erb_name).should be_true
|
68
|
-
end
|
69
76
|
end # command (line) execution
|
70
77
|
|
71
78
|
context "generating gemspec from erb" do
|
79
|
+
|
72
80
|
it "generate valid gemspec, without local erb" do
|
73
81
|
system executable
|
74
82
|
spec = eval(IO.read(gemspec_name))
|
@@ -87,6 +95,11 @@ module Gemusta
|
|
87
95
|
`gem build #{gemspec_name}`
|
88
96
|
File.exists?(gem_name).should be_true
|
89
97
|
end
|
98
|
+
|
99
|
+
it "show gemusta version with -v option" do
|
100
|
+
version = `#{executable} -v`
|
101
|
+
version.strip.should == Gemusta::VERSION
|
102
|
+
end
|
90
103
|
end # generating gemspec from erb
|
91
104
|
|
92
105
|
after do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gemusta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-31 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70243674653080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,9 +21,9 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
25
|
-
description:
|
26
|
-
|
24
|
+
version_requirements: *70243674653080
|
25
|
+
description: Creates an executable to help you generate your gemspec based on an erb
|
26
|
+
template
|
27
27
|
email:
|
28
28
|
- ricardo.valeriano@gmail.com
|
29
29
|
executables:
|
@@ -63,7 +63,7 @@ rubyforge_project:
|
|
63
63
|
rubygems_version: 1.8.10
|
64
64
|
signing_key:
|
65
65
|
specification_version: 3
|
66
|
-
summary:
|
66
|
+
summary: gemusta was created to help you generate your gemspec in advance
|
67
67
|
test_files:
|
68
68
|
- spec/gemusta/cli_spec.rb
|
69
69
|
- spec/spec_helper.rb
|