gemify 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/gemify +38 -5
- data/bin/gemify-manifest +12 -0
- data/lib/gemify.rb +127 -67
- data/lib/gemify/vcs.rb +58 -0
- metadata +7 -3
data/bin/gemify
CHANGED
@@ -1,12 +1,45 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.dirname(__FILE__)+"/../lib"
|
4
|
+
|
5
|
+
require 'gemify'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
options = {}
|
9
|
+
options[:interactive] = true # Interactive by default
|
10
|
+
|
11
|
+
parser = OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: #{opts.program_name} [options]"
|
13
|
+
opts.separator ""
|
14
|
+
opts.separator "Options:"
|
15
|
+
opts.on("-h", "--help", "Shows this message") do |val|
|
16
|
+
$stdout.puts opts
|
17
|
+
exit(0)
|
18
|
+
end
|
19
|
+
opts.on("-I", "--no-interactive", "Automaticically builds the gem") do |val|
|
20
|
+
options[:interactive] = false
|
21
|
+
end
|
22
|
+
opts.on("-c", "--from-vcs", "Use files from version control system" ) do |val|
|
23
|
+
options[:vcs] = true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
2
27
|
begin
|
3
|
-
|
4
|
-
rescue
|
5
|
-
|
28
|
+
parser.parse!(ARGV)
|
29
|
+
rescue => e
|
30
|
+
$stderr.puts "Error: #{e.message}"
|
31
|
+
$stdout.puts parser
|
32
|
+
exit -1
|
6
33
|
end
|
7
34
|
|
8
35
|
begin
|
9
|
-
Gemify.new
|
36
|
+
gemify = Gemify.new
|
37
|
+
gemify.from_vcs = !!options[:vcs]
|
38
|
+
if not options[:interactive] and File.exist?(Gemify::SETTINGS)
|
39
|
+
gemify.build!
|
40
|
+
else
|
41
|
+
gemify.main
|
42
|
+
end
|
10
43
|
rescue Gemify::Exit
|
11
44
|
exit
|
12
|
-
end
|
45
|
+
end
|
data/bin/gemify-manifest
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.dirname(__FILE__)+"/../lib"
|
4
|
+
|
5
|
+
require 'gemify'
|
6
|
+
|
7
|
+
manifest = (ARGV.first || ".manifest")
|
8
|
+
|
9
|
+
$stdout.puts "=> Generating #{manifest}"
|
10
|
+
File.open(manifest, "w") do |file|
|
11
|
+
file << Gemify::VCS.files.join("\n")
|
12
|
+
end
|
data/lib/gemify.rb
CHANGED
@@ -2,37 +2,53 @@ require 'rubygems'
|
|
2
2
|
require 'rubygems/builder'
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
+
require 'gemify/vcs'
|
6
|
+
|
5
7
|
class Gemify
|
8
|
+
attr_accessor :from_vcs
|
9
|
+
|
6
10
|
class Exit < StandardError;end
|
11
|
+
SETTINGS = ".gemified"
|
7
12
|
MANIFEST = ["MANIFEST", "Manifest.txt", ".manifest"]
|
8
13
|
REQUIRED = [:name, :summary, :version]
|
9
|
-
OPTIONAL = [:author, :email, :homepage, :rubyforge_project, :dependencies]
|
14
|
+
OPTIONAL = [:author, :email, :homepage, :rubyforge_project, :has_rdoc, :dependencies]
|
10
15
|
ALL = REQUIRED+OPTIONAL
|
11
|
-
REPLACE = {
|
16
|
+
REPLACE = {
|
17
|
+
:rubyforge_project => "RubyForge project",
|
18
|
+
:has_rdoc => "documentation",
|
19
|
+
}
|
20
|
+
TYPE = {
|
21
|
+
:has_rdoc => :boolean,
|
22
|
+
:dependencies => :array,
|
23
|
+
}
|
24
|
+
|
12
25
|
def initialize
|
13
26
|
@settings = {}
|
14
|
-
@
|
15
|
-
|
16
|
-
if
|
17
|
-
|
18
|
-
raise Exit
|
19
|
-
end
|
20
|
-
|
21
|
-
if File.exists? ".gemified"
|
22
|
-
@settings = YAML.load(open(".gemified"))
|
27
|
+
@from_vcs = false
|
28
|
+
|
29
|
+
if File.exists? SETTINGS
|
30
|
+
load!
|
23
31
|
end
|
24
|
-
rescue Errno::EACCES
|
25
|
-
@result = "Can't read .gemified"
|
26
32
|
end
|
27
33
|
|
28
34
|
def files
|
29
|
-
@files ||= if
|
35
|
+
@files ||= if @from_vcs
|
36
|
+
VCS.files
|
37
|
+
elsif m=MANIFEST.detect{|x|File.exist?(x)}
|
30
38
|
File.read(m).split(/\r?\n/)
|
31
39
|
else
|
32
|
-
|
40
|
+
VCS.files(:unknown)
|
33
41
|
end
|
34
42
|
end
|
35
43
|
|
44
|
+
def bin
|
45
|
+
files.select { |file| file =~ /^bin\// }
|
46
|
+
end
|
47
|
+
|
48
|
+
def extensions
|
49
|
+
files.select { |file| file =~ /extconf\.rb$/ }
|
50
|
+
end
|
51
|
+
|
36
52
|
def main
|
37
53
|
loop do
|
38
54
|
menu
|
@@ -41,34 +57,22 @@ class Gemify
|
|
41
57
|
l=(o=gets).downcase[0]
|
42
58
|
i=o.to_i
|
43
59
|
|
44
|
-
|
45
|
-
|
60
|
+
case l
|
61
|
+
when ?x
|
46
62
|
raise Exit
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
if (1..ALL.length-1).include? i
|
54
|
-
sub_task(i)
|
55
|
-
next
|
56
|
-
end
|
57
|
-
|
58
|
-
case i-(ALL.length-1)
|
59
|
-
when 1
|
60
|
-
puts "Write all your dependencies here, split by ENTER and"
|
61
|
-
puts "press ENTER twice when you're done:"
|
62
|
-
@settings[:dependencies] = $stdin.gets($/*2).strip.split($/)
|
63
|
-
@settings.delete(:dependencies) if @settings[:dependencies].empty?
|
64
|
-
@result = "Updated 'dependencies'"
|
65
|
-
next
|
66
|
-
when 2
|
67
|
-
save
|
63
|
+
when ?b
|
64
|
+
build!
|
65
|
+
when ?s
|
66
|
+
save!
|
68
67
|
next
|
69
|
-
when
|
68
|
+
when ?i
|
70
69
|
@result = "Included files:#{$/}" + files.join($/)
|
71
70
|
next
|
71
|
+
end
|
72
|
+
|
73
|
+
if (1..ALL.length).include? i
|
74
|
+
set(ALL[i-1])
|
75
|
+
next
|
72
76
|
end
|
73
77
|
|
74
78
|
@result = "Can't find the task named '#{o}'"
|
@@ -76,6 +80,7 @@ class Gemify
|
|
76
80
|
end
|
77
81
|
|
78
82
|
def menu
|
83
|
+
require_files!
|
79
84
|
clear
|
80
85
|
puts "Welcome to Gemify!"
|
81
86
|
puts
|
@@ -83,8 +88,9 @@ class Gemify
|
|
83
88
|
ALL.each do |m|
|
84
89
|
puts build_task(m)
|
85
90
|
end
|
86
|
-
puts
|
87
|
-
puts "
|
91
|
+
puts
|
92
|
+
puts "s) Save"
|
93
|
+
puts "i) Show included files"
|
88
94
|
puts
|
89
95
|
puts "b) Build gem"
|
90
96
|
puts "x) Exit"
|
@@ -93,7 +99,8 @@ class Gemify
|
|
93
99
|
|
94
100
|
## Special tasks
|
95
101
|
|
96
|
-
def build
|
102
|
+
def build!
|
103
|
+
require_files!
|
97
104
|
Gem::Builder.new(Gem::Specification.new do |s|
|
98
105
|
(@settings.delete(:dependencies)||[]).each do |dep|
|
99
106
|
s.add_dependency dep
|
@@ -105,47 +112,73 @@ class Gemify
|
|
105
112
|
s.bindir = "bin"
|
106
113
|
s.require_path = "lib"
|
107
114
|
|
108
|
-
unless
|
109
|
-
s.executables =
|
115
|
+
unless bin.empty?
|
116
|
+
s.executables = bin.map{|x|x[4..-1]}
|
110
117
|
end
|
118
|
+
|
119
|
+
unless extensions.empty?
|
120
|
+
s.extensions = extensions
|
121
|
+
end
|
122
|
+
|
111
123
|
end).build
|
112
124
|
raise Exit
|
113
125
|
end
|
114
126
|
|
115
|
-
def
|
116
|
-
|
127
|
+
def load!
|
128
|
+
@settings = YAML.load(File.read(SETTINGS))
|
129
|
+
@settings.keys.each do |key|
|
130
|
+
@settings[key] = value(key)
|
131
|
+
end
|
132
|
+
rescue Errno::EACCES
|
133
|
+
@result = "Can't read #{SETTINGS}"
|
134
|
+
end
|
135
|
+
|
136
|
+
def save!
|
137
|
+
File.open(SETTINGS,"w"){|f|f << YAML.dump(@settings)}
|
117
138
|
@result = "Saved!"
|
118
139
|
rescue Errno::EACCES
|
119
|
-
@result = "Can't write to
|
140
|
+
@result = "Can't write to #{SETTINGS}"
|
120
141
|
end
|
121
142
|
|
122
|
-
def sub_task(i)
|
123
|
-
key = ALL[i-1]
|
124
|
-
menu
|
125
|
-
@settings[key] = gets(key)
|
126
|
-
@settings.delete(key) if @settings[key].empty?
|
127
|
-
@result = "Updated '#{show(key)}'"
|
128
|
-
end
|
129
|
-
|
130
|
-
# Helpers
|
131
|
-
private
|
132
143
|
def build_task(m)
|
133
144
|
index = (ALL.index(m)||0)+1
|
134
|
-
|
135
|
-
|
145
|
+
unless type(m) == :boolean
|
146
|
+
verb,now = if @settings.keys.include?(m)
|
147
|
+
["Change"," = " + inspect_setting(m)]
|
148
|
+
else
|
149
|
+
["Set",""]
|
150
|
+
end
|
136
151
|
else
|
137
|
-
["
|
152
|
+
verb, now = ["Toogle"," = " + inspect_setting(m)]
|
138
153
|
end
|
139
154
|
req = REQUIRED.include?(m) ? " (required)" : ""
|
140
155
|
"#{index}) #{verb} #{show(m)}#{req}#{now}"
|
141
156
|
end
|
142
157
|
|
143
158
|
def clear
|
144
|
-
print
|
159
|
+
system("cls") || print("\e[H\e[2J")
|
160
|
+
end
|
161
|
+
|
162
|
+
def set(m)
|
163
|
+
menu
|
164
|
+
case type(m)
|
165
|
+
when :array
|
166
|
+
puts "Split by ENTER and press ENTER twice when you're done"
|
167
|
+
puts "> #{show(m).capitalize}: "
|
168
|
+
@settings[m] = $stdin.gets($/*2).strip.split($/)
|
169
|
+
@settings.delete(m) if @settings[m].empty?
|
170
|
+
when :boolean
|
171
|
+
@settings[m] = !@settings[m]
|
172
|
+
when :string
|
173
|
+
print "> #{show(m).capitalize}: "
|
174
|
+
@settings[m] = $stdin.gets.strip
|
175
|
+
@settings.delete(m) if @settings[m].empty?
|
176
|
+
end
|
177
|
+
@result = "Updated '#{m}'"
|
145
178
|
end
|
146
179
|
|
147
|
-
def gets
|
148
|
-
print
|
180
|
+
def gets
|
181
|
+
print("> ")
|
149
182
|
$stdin.gets.strip
|
150
183
|
end
|
151
184
|
|
@@ -153,12 +186,39 @@ class Gemify
|
|
153
186
|
REPLACE[m]||m.to_s
|
154
187
|
end
|
155
188
|
|
189
|
+
def type(m)
|
190
|
+
TYPE[m]||:string
|
191
|
+
end
|
192
|
+
|
193
|
+
def value(m)
|
194
|
+
i=@settings[m]
|
195
|
+
case type(m)
|
196
|
+
when :array
|
197
|
+
i.to_a
|
198
|
+
when :boolean
|
199
|
+
!!i
|
200
|
+
when :string
|
201
|
+
i.to_s
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
156
205
|
def inspect_setting(m)
|
157
|
-
|
158
|
-
|
206
|
+
i=@settings[m]
|
207
|
+
case type(m)
|
208
|
+
when :array
|
159
209
|
i.join(", ")
|
160
|
-
|
210
|
+
when :boolean
|
211
|
+
(i||false).to_s
|
212
|
+
when :string
|
161
213
|
i.to_s
|
162
214
|
end
|
163
215
|
end
|
164
|
-
|
216
|
+
|
217
|
+
protected
|
218
|
+
def require_files!
|
219
|
+
if files.empty?
|
220
|
+
puts "Can't find anything to make a gem out of..."
|
221
|
+
raise Exit
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
data/lib/gemify/vcs.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
class Gemify
|
5
|
+
|
6
|
+
class VCS
|
7
|
+
def self.determine_vcs
|
8
|
+
vcs = :unknown
|
9
|
+
if File.exist?(".git")
|
10
|
+
vcs = :git
|
11
|
+
elsif File.exist?("_darcs")
|
12
|
+
vcs = :darcs
|
13
|
+
elsif File.exist?(".hg")
|
14
|
+
vcs = :hg
|
15
|
+
elsif File.exist?(".bzr")
|
16
|
+
vcs = :bzr
|
17
|
+
elsif File.exist?(".svn")
|
18
|
+
vcs = :svn
|
19
|
+
elsif File.exist?("CVSROOT")
|
20
|
+
vcs = :cvs
|
21
|
+
end
|
22
|
+
|
23
|
+
vcs
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.get_files_from_command(command)
|
27
|
+
files = []
|
28
|
+
|
29
|
+
Open3.popen3(command) do |stdin, stdout, stderr|
|
30
|
+
stdout.each { |line|
|
31
|
+
file = line.strip
|
32
|
+
files << file if File.exist?(file)
|
33
|
+
}
|
34
|
+
end
|
35
|
+
files
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.files(forced_vcs = false)
|
39
|
+
case (forced_vcs || determine_vcs)
|
40
|
+
when :git
|
41
|
+
get_files_from_command("git-ls-files").delete_if { |w| w == ".gitignore" or w == ".gitattributes" }
|
42
|
+
when :darcs
|
43
|
+
get_files_from_command("darcs query manifest")
|
44
|
+
when :bzr
|
45
|
+
get_files_from_command("bzr ls").delete_if { |w| w == ".bzrignore" }
|
46
|
+
when :hg
|
47
|
+
get_files_from_command("hg manifest")
|
48
|
+
when :svn
|
49
|
+
get_files_from_command("svn ls")
|
50
|
+
when :cvs
|
51
|
+
get_files_from_command("cvs ls")
|
52
|
+
when :unknown
|
53
|
+
Dir['bin/*'] + Dir['lib/**/**']
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
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.2.
|
4
|
+
version: 0.2.4
|
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-
|
12
|
+
date: 2008-04-06 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -17,12 +17,16 @@ description:
|
|
17
17
|
email: judofyr@gmail.com
|
18
18
|
executables:
|
19
19
|
- gemify
|
20
|
+
- gemify-manifest
|
20
21
|
extensions: []
|
21
22
|
|
22
23
|
extra_rdoc_files: []
|
23
24
|
|
24
25
|
files:
|
25
26
|
- bin/gemify
|
27
|
+
- bin/gemify-manifest
|
28
|
+
- lib/gemify
|
29
|
+
- lib/gemify/vcs.rb
|
26
30
|
- lib/gemify.rb
|
27
31
|
has_rdoc: false
|
28
32
|
homepage: http://dojo.rubyforge.org
|
@@ -46,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
50
|
requirements: []
|
47
51
|
|
48
52
|
rubyforge_project: dojo
|
49
|
-
rubygems_version: 1.0
|
53
|
+
rubygems_version: 1.1.0
|
50
54
|
signing_key:
|
51
55
|
specification_version: 2
|
52
56
|
summary: An extremely simple way to create a RubyGem
|