makegem 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/makegem +146 -0
- data/bin/templates/LICENSE.erb +20 -0
- data/bin/templates/VERSION.erb +1 -0
- data/bin/templates/gemspec.erb +23 -0
- metadata +70 -0
data/bin/makegem
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'date'
|
4
|
+
require 'erb'
|
5
|
+
|
6
|
+
class String
|
7
|
+
def color(value)
|
8
|
+
colors = {:red =>"\033[93m", :blue => "\033[94m", :purple => "\033[95m", :green => "\033[92m"}
|
9
|
+
endc = "\033[0m"
|
10
|
+
(colors[value] || "") + self + endc
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def assert(b, msg)
|
15
|
+
unless b
|
16
|
+
puts msg.color(:red)
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def log(x)
|
22
|
+
puts "\n#{x}".color(:blue)
|
23
|
+
end
|
24
|
+
|
25
|
+
def err(x)
|
26
|
+
puts x.color(:red)
|
27
|
+
end
|
28
|
+
|
29
|
+
def exc(x)
|
30
|
+
puts "$ #{x}".color(:purple)
|
31
|
+
`#{x}`
|
32
|
+
end
|
33
|
+
|
34
|
+
assert ARGV.size != 0, "USAGE: #{$0} [gem name]"
|
35
|
+
|
36
|
+
name = ARGV[0]
|
37
|
+
assert name !~ /\s/, "gem name cannot contain spaces."
|
38
|
+
|
39
|
+
version = "0.0.1"
|
40
|
+
date = Date.today.to_s
|
41
|
+
year = Date.today.year
|
42
|
+
log "Making directory structure"
|
43
|
+
begin
|
44
|
+
Dir.mkdir(name)
|
45
|
+
rescue Errno::EEXIST
|
46
|
+
puts "Directory exists.".color(:red)
|
47
|
+
exit
|
48
|
+
end
|
49
|
+
log "Trying to get your name from your git file..."
|
50
|
+
author = exc("git config --global user.name").chomp
|
51
|
+
|
52
|
+
unless author
|
53
|
+
err "Failed."
|
54
|
+
print "What is your name? "
|
55
|
+
author = STDIN.readline.chomp
|
56
|
+
end
|
57
|
+
|
58
|
+
log "Trying to get your email from your git file..."
|
59
|
+
email = exc("git config --global user.email").chomp
|
60
|
+
|
61
|
+
unless email
|
62
|
+
err "Failed."
|
63
|
+
print "What is your email? "
|
64
|
+
email = STDIN.readline.chomp
|
65
|
+
end
|
66
|
+
|
67
|
+
log "What is the one line summary of your gem?"
|
68
|
+
summary = STDIN.readline.chomp
|
69
|
+
|
70
|
+
log ("Optional: If you have any executables, what are they called? Multiple names should be separated with a space.")
|
71
|
+
executables = STDIN.readline.chomp.split
|
72
|
+
|
73
|
+
executables = executables.map do |e|
|
74
|
+
if e =~ /^bin\//
|
75
|
+
return e.gsub("bin/", "")
|
76
|
+
end
|
77
|
+
e
|
78
|
+
end
|
79
|
+
|
80
|
+
log "Optional: If you have any files, what are they called? Multiple names should be separated with a space. Example: lib/test.rb bin/test"
|
81
|
+
files = STDIN.readline.chomp.split
|
82
|
+
|
83
|
+
executables.each do |exe|
|
84
|
+
files << "bin/" + exe
|
85
|
+
end
|
86
|
+
|
87
|
+
log "Optional: If the project has a homepage, enter it now:"
|
88
|
+
homepage = STDIN.readline.chomp
|
89
|
+
|
90
|
+
log "writing gemspec and other files"
|
91
|
+
|
92
|
+
Dir.glob(File.dirname(__FILE__) + "/templates/*.erb").each do |file|
|
93
|
+
# second param to erb.new: safety level (0=min, 4=max).
|
94
|
+
# third param: suppress newlines after <%= %> tags
|
95
|
+
res = ERB.new(File.open(file).read, 0, "<>").result(binding)
|
96
|
+
if file =~ /gemspec.erb$/
|
97
|
+
new_name = name + ".gemspec"
|
98
|
+
else
|
99
|
+
new_name = File.basename(file).gsub(".erb", "")
|
100
|
+
end
|
101
|
+
File.open(name + "/" + new_name, "w+").write(res)
|
102
|
+
end
|
103
|
+
|
104
|
+
unless executables.empty?
|
105
|
+
log "making executables directory"
|
106
|
+
exc "mkdir #{name}/bin"
|
107
|
+
end
|
108
|
+
|
109
|
+
unless files.empty?
|
110
|
+
log "making lib directory"
|
111
|
+
exc "mkdir #{name}/lib"
|
112
|
+
end
|
113
|
+
|
114
|
+
log("DONE!")
|
115
|
+
|
116
|
+
puts <<-EOF
|
117
|
+
A basic structure for your gem has been created.
|
118
|
+
Next Steps:
|
119
|
+
|
120
|
+
#{("STEP 1: ADD FILES").color(:blue)}
|
121
|
+
Add your project's files to #{name.color(:blue)}.
|
122
|
+
|
123
|
+
#{("STEP 2: INSPECT").color(:blue)}
|
124
|
+
Check out #{(name + "/" + name + ".gemspec").color(:blue)} and
|
125
|
+
make any additional changes you need.
|
126
|
+
|
127
|
+
#{("STEP 3: BUILD").color(:blue)}
|
128
|
+
run `#{("gem build " + name + ".gemspec").color(:purple)}`
|
129
|
+
|
130
|
+
#{("STEP 4: INSTALL").color(:blue)}
|
131
|
+
run `#{("gem install " + name).color(:purple)}`
|
132
|
+
|
133
|
+
#{("STEP 5: TEST").color(:blue)}
|
134
|
+
run `#{("irb -r rubygems -r " + name).color(:purple)}` and
|
135
|
+
make sure the gem gets loaded.
|
136
|
+
|
137
|
+
#{("STEP 6: DISTRIBUTE").color(:blue)}
|
138
|
+
If everything looks good, push your gem to rubygems.org!
|
139
|
+
run `#{("gem push " + name + "-" + version + ".gem").color(:purple)}`
|
140
|
+
|
141
|
+
You need to have a rubygems account set up on your machine for this.
|
142
|
+
If you do not, check out:
|
143
|
+
|
144
|
+
#{"http://guides.rubygems.org/make-your-own-gem/#first-gem".color(:green)}
|
145
|
+
|
146
|
+
EOF
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) <%= year %> <%= author %>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= version %>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "<%= name %>"
|
3
|
+
s.version = "<%= version %>"
|
4
|
+
s.date = "<%= date %>"
|
5
|
+
s.summary = "<%= summary %>"
|
6
|
+
s.description = "<%= summary %>"
|
7
|
+
s.author = "<%= author %>"
|
8
|
+
s.email = "<%= email %>"
|
9
|
+
<% if files.empty? %>
|
10
|
+
s.files = "" # TODO put some files here
|
11
|
+
<% else %>
|
12
|
+
s.files = <%= files.inspect %> # + Dir["bin/templates/*"]
|
13
|
+
<% end %>
|
14
|
+
<% if homepage != "" %>
|
15
|
+
s.homepage = "<%= homepage %>"
|
16
|
+
<% end %>
|
17
|
+
<% unless executables.empty? %>
|
18
|
+
s.executables = <%= executables.inspect %>
|
19
|
+
<% end %>
|
20
|
+
# TODO add any dependencies
|
21
|
+
# s.add_dependency("log4r", ">= 1.0.5")
|
22
|
+
# s.add_dependency("log4r")
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: makegem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Aditya Bhargava
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-02-01 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Easy-to-use gem builder for Ruby.
|
23
|
+
email: batman@scribd.com
|
24
|
+
executables:
|
25
|
+
- makegem
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- bin/makegem
|
32
|
+
- bin/templates/gemspec.erb
|
33
|
+
- bin/templates/LICENSE.erb
|
34
|
+
- bin/templates/VERSION.erb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: https://github.com/egonSchiele/makegem
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
hash: 3
|
50
|
+
segments:
|
51
|
+
- 0
|
52
|
+
version: "0"
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.3.7
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Easy-to-use gem builder for Ruby.
|
69
|
+
test_files: []
|
70
|
+
|