gemify 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/gemify +5 -38
- data/lib/gemify.rb +152 -0
- metadata +5 -4
data/bin/gemify
CHANGED
@@ -1,40 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
puts "Ops, no files to make a gem out of."
|
2
|
+
require 'gemify'
|
3
|
+
begin
|
4
|
+
Gemify.new.main
|
5
|
+
rescue Gemify::Exit
|
7
6
|
exit
|
8
|
-
|
9
|
-
puts "These files will be included in the gem:"
|
10
|
-
puts @files.map{|x|" "+x}
|
11
|
-
end
|
12
|
-
|
13
|
-
trap("INT"){puts;exit}
|
14
|
-
|
15
|
-
@config = Hash.new do |h,n|
|
16
|
-
m,e=n.to_s.gsub('_',' ').split("+",2)
|
17
|
-
print m.capitalize+"? "
|
18
|
-
print "(#{e}) " if e
|
19
|
-
h[n]=gets.strip
|
20
|
-
end
|
21
|
-
|
22
|
-
Gem::Builder.new(Gem::Specification.new do |s|
|
23
|
-
s.name = @config[:name_of_the_gem]
|
24
|
-
s.summary = @config[:summary]
|
25
|
-
s.version = @config[:version]
|
26
|
-
s.author = @config[:author]
|
27
|
-
s.email = @config[:email]
|
28
|
-
s.platform = Gem::Platform::RUBY
|
29
|
-
s.files = @files
|
30
|
-
|
31
|
-
if File.directory? "bin"
|
32
|
-
s.bindir = "bin"
|
33
|
-
s.executables << Dir["bin/**/*"].map{|x|x[4..-1]}
|
34
|
-
end
|
35
|
-
s.require_path = "lib" if File.directory? "lib"
|
36
|
-
|
37
|
-
@config[:"dependencies+split_by_space"].split(" ").each do |d|
|
38
|
-
s.add_dependency d
|
39
|
-
end
|
40
|
-
end).build
|
7
|
+
end
|
data/lib/gemify.rb
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class Gemify
|
5
|
+
class Exit < StandardError;end
|
6
|
+
REQUIRED = [:name, :summary, :version]
|
7
|
+
OPTIONAL = [:author, :email, :homepage, :rubyforge_project, :dependencies]
|
8
|
+
ALL = REQUIRED+OPTIONAL
|
9
|
+
REPLACE = {:rubyforge_project => "RubyForge project"}
|
10
|
+
def initialize
|
11
|
+
@settings = {}
|
12
|
+
@bin = Dir["bin/**/*"]
|
13
|
+
@lib = Dir["lib/**/*"]
|
14
|
+
@all = @bin + @lib
|
15
|
+
|
16
|
+
if @all.empty?
|
17
|
+
puts "Can't find anything to make a gem out of..."
|
18
|
+
raise Exit
|
19
|
+
end
|
20
|
+
|
21
|
+
if File.exists? ".gemified"
|
22
|
+
@settings = YAML.load(open(".gemified"))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def main
|
27
|
+
loop do
|
28
|
+
menu
|
29
|
+
puts @result if @result
|
30
|
+
@result = nil
|
31
|
+
l=(o=gets).downcase[0]
|
32
|
+
i=o.to_i
|
33
|
+
|
34
|
+
if l==?x
|
35
|
+
puts "Exiting..."
|
36
|
+
raise Exit
|
37
|
+
end
|
38
|
+
|
39
|
+
if l==?b
|
40
|
+
build
|
41
|
+
end
|
42
|
+
|
43
|
+
if (1..ALL.length-1).include? i
|
44
|
+
sub_task(i)
|
45
|
+
next
|
46
|
+
end
|
47
|
+
|
48
|
+
case i-(ALL.length-1)
|
49
|
+
when 1
|
50
|
+
puts "Write all your dependencies here, split by ENTER and"
|
51
|
+
puts "press ENTER twice when you're done:"
|
52
|
+
@dependencies = $stdin.gets($/*2).strip.split($/)
|
53
|
+
@dependencies = nil if @dependencies.empty?
|
54
|
+
@result = "Updated 'dependencies'"
|
55
|
+
next
|
56
|
+
when 2
|
57
|
+
save
|
58
|
+
next
|
59
|
+
when 3
|
60
|
+
@result = "Included files:#{$/}" + @all.join($/)
|
61
|
+
next
|
62
|
+
end
|
63
|
+
|
64
|
+
@result = "Can't find the task named '#{o}'"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def menu
|
69
|
+
clear
|
70
|
+
puts "Welcome to Gemify!"
|
71
|
+
puts
|
72
|
+
puts "Which task would you like to invoke?"
|
73
|
+
ALL.each do |m|
|
74
|
+
puts build_task(m)
|
75
|
+
end
|
76
|
+
puts "#{ALL.length+1}) Save"
|
77
|
+
puts "#{ALL.length+2}) Show included files"
|
78
|
+
puts
|
79
|
+
puts "b) Build gem"
|
80
|
+
puts "x) Exit"
|
81
|
+
puts
|
82
|
+
end
|
83
|
+
|
84
|
+
## Special tasks
|
85
|
+
|
86
|
+
def build
|
87
|
+
Gem::Builder.new(Gem::Specification.new do |s|
|
88
|
+
@settings.each { |key, value| s.send("#{key}=",value) }
|
89
|
+
s.platform = Gem::Platform::RUBY
|
90
|
+
s.files = @all
|
91
|
+
s.bindir = "bin"
|
92
|
+
s.require_path "lib"
|
93
|
+
|
94
|
+
unless @bin.empty?
|
95
|
+
s.executables << @bin.map{|x|x[4..-1]}
|
96
|
+
end
|
97
|
+
|
98
|
+
(@dependencies||[]).each do |dep|
|
99
|
+
s.add_dependency dep
|
100
|
+
end
|
101
|
+
end).build
|
102
|
+
raise Exit
|
103
|
+
end
|
104
|
+
|
105
|
+
def save
|
106
|
+
File.open(".gemified","w"){|f|f<<YAML.dump(@settings)}
|
107
|
+
@result = "Saved!"
|
108
|
+
end
|
109
|
+
|
110
|
+
def sub_task(i)
|
111
|
+
key = ALL[i-1]
|
112
|
+
menu
|
113
|
+
@settings[key] = gets(key)
|
114
|
+
@settings.delete(key) if @settings[key].empty?
|
115
|
+
@result = "Updated '#{show(key)}'"
|
116
|
+
end
|
117
|
+
|
118
|
+
# Helpers
|
119
|
+
private
|
120
|
+
def build_task(m)
|
121
|
+
index = (ALL.index(m)||0)+1
|
122
|
+
verb,now = if @settings.keys.include?(m)
|
123
|
+
["Change"," = " + inspect_setting(m)]
|
124
|
+
else
|
125
|
+
["Set",""]
|
126
|
+
end
|
127
|
+
req = REQUIRED.include?(m) ? " (required)" : ""
|
128
|
+
"#{index}) #{verb} #{show(m)}#{req}#{now}"
|
129
|
+
end
|
130
|
+
|
131
|
+
def clear
|
132
|
+
print "\e[H\e[2J"
|
133
|
+
end
|
134
|
+
|
135
|
+
def gets(m=nil)
|
136
|
+
print m ? "> #{show(m).capitalize}: " : "> "
|
137
|
+
$stdin.gets.strip
|
138
|
+
end
|
139
|
+
|
140
|
+
def show(m)
|
141
|
+
REPLACE[m]||m.to_s
|
142
|
+
end
|
143
|
+
|
144
|
+
def inspect_setting(m)
|
145
|
+
case i=@settings[m]
|
146
|
+
when Array
|
147
|
+
i.join(", ")
|
148
|
+
else
|
149
|
+
i.to_s
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gemify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.2"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus Holm
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-02-
|
12
|
+
date: 2008-02-09 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -23,8 +23,9 @@ extra_rdoc_files: []
|
|
23
23
|
|
24
24
|
files:
|
25
25
|
- bin/gemify
|
26
|
+
- lib/gemify.rb
|
26
27
|
has_rdoc: false
|
27
|
-
homepage:
|
28
|
+
homepage: http://dojo.rubyforge.org
|
28
29
|
post_install_message:
|
29
30
|
rdoc_options: []
|
30
31
|
|
@@ -44,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
45
|
version:
|
45
46
|
requirements: []
|
46
47
|
|
47
|
-
rubyforge_project:
|
48
|
+
rubyforge_project: dojo
|
48
49
|
rubygems_version: 1.0.1
|
49
50
|
signing_key:
|
50
51
|
specification_version: 2
|