gemify 0.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.4
2
+ * Gemify is now a gemspec generator!
3
+
1
4
  == 0.3
2
5
  * Gemify is now a gemspec editor!
3
6
 
@@ -35,4 +38,4 @@
35
38
  * Added a very fancy CLI
36
39
 
37
40
  == 0.1.0 - 2008-02-07
38
- * The first release. More like a POC-code
41
+ * The first release. More like a POC-code
data/README.md CHANGED
@@ -1,71 +1,54 @@
1
- Gemify, the lightweight gemspec editor
2
- ======================================
1
+ Gemify, the gemspec generator
2
+ =============================
3
3
 
4
4
  Overview
5
5
  --------
6
6
 
7
- Gemify is a simple tool which helps you create and manage your gemspecs.
8
- Instead of messing with Rakefiles and adding yet another development
9
- dependency (like Hoe, Echoe and Jeweler), Gemify takes a much less obtrusive
10
- approach.
11
-
12
- Gemify works directly on the .gemspec file. In fact, when you're using Gemify,
13
- you're only using it as an editor. If you want, you could just edit the file
14
- manually.
7
+ Gemify is a simple tool which helps you generate gemspecs (which are
8
+ used for building gems) and verify that your project follows the common
9
+ and proven way to structure your Ruby packages.
15
10
 
16
11
  Getting started
17
12
  ---------------
18
13
 
14
+ Generating gemspec:
15
+
19
16
  $ gem install gemify
20
- $ cd myproject (might already have a gemspec)
17
+ $ cd myproject (which doesn't have a gemspec yet)
21
18
  $ gemify
22
- Currently editing gemify.gemspec
23
-
24
- Which task would you like to invoke?
25
- 1) Change name (required) = gemify
26
- 2) Change summary (required) = The lightweight gemspec editor
27
- 3) Change version (required) = 0.3
28
- 4) Change author = Magnus Holm
29
- 5) Change email = judofyr@gmail.com
30
- 6) Change homepage = http://dojo.rubyforge.org/
31
- 7) Set dependencies
32
-
33
- s) Save
34
- r) Reload (discard unsaved changes)
35
- m) Rename
36
- l) List files
19
+ Gemify needs to know a bit about your project, but should be
20
+ able to guess most of the information. Type the value if you
21
+ need to correct it, or press ENTER to accept the suggestion by Gemify.
37
22
 
38
- x) Exit
23
+ Project name: gemify?
24
+ Namespace: Gemify?
25
+ Library: lib/gemify?
39
26
 
40
- >
27
+ *** Verifying the structure of lib/
28
+ [+] Please consider to define Gemify::VERSION in lib/gemify/version.rb
29
+ [.] Done
41
30
 
42
- ### Manifest
31
+ *** Verifying the structure of bin/
32
+ [.] Done
43
33
 
44
- Gemify helps you manage the manifest (files which will be included in the gem). It follows these rules:
34
+ *** Verifying the structure of ext/
35
+ [.] Done
45
36
 
46
- * If there's a file called **MANIFEST**, **Manifest.txt** or **.manifest**, it
47
- assumes this files contains a line-separated list of the manifest.
37
+ *** Generating a gemspec
38
+ [.] Done
48
39
 
49
- * If not, it checks if you're using Git, Mercurial, Darcs, Bazaar, Subversion
50
- or CVS and uses the commited files.
40
+ Please open gemify.gemspec in your text editor and fill out the details.
51
41
 
52
- * If not, it just includes all the files.
42
+ You should fix any warnings that was reported above. You won't need to
43
+ generate a new gemspec after you've fixed them.
53
44
 
54
- You can always run `gemify -m` to see the manifest, and if you don't like what
55
- you see you should maintain a manifest file yourself. Every time you open
56
- Gemify and save, it will update the manifest. You can also call `gemify -u`.
45
+ You must also define Gemify::VERSION in lib/gemify/version.rb.
46
+ Gemify has automatically created the file for you, so simply
47
+ open it in your text editor and fill in the current version.
48
+
49
+ Or if you just want to verify it:
57
50
 
58
- ### Dependencies
59
-
60
- When you set dependencies, you can separate the version requirement by a
61
- comma:
62
-
63
- $ gemify
64
- ...
65
- > 7
66
- Split by ENTER and press ENTER twice when you're done
67
- > nokogiri
68
- > rack, >= 1.0
51
+ $ gemify -v
69
52
 
70
53
  ### Build and share a gem
71
54
 
@@ -78,8 +61,8 @@ Let's not reinvent the wheel, shall we?
78
61
  Acknowledgements
79
62
  ----------------
80
63
 
81
- Thanks to [Pat Nakajima](http://patnakajima.com/) for reminding me that Gemify
82
- still has its uses.
64
+ Thanks to [Pat Nakajima](http://patnakajima.com/) for reminding me that
65
+ Gemify still has its uses.
83
66
 
84
67
 
85
68
  Contributors
@@ -0,0 +1,3 @@
1
+ task :test do
2
+ sh "ruby -Ilib test/test_gemify.rb"
3
+ end
data/bin/gemify CHANGED
@@ -1,57 +1,265 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- $:.unshift File.dirname(__FILE__) + '/../lib'
4
2
  require 'gemify'
5
- require 'trollop'
6
-
7
- gemspec = nil
8
- actions = [:new, :update, :manifest]
9
-
10
- opts = Trollop.options do
11
- version "gemify 0.3"
12
- banner <<-EOS
13
- Usage: #{$0} [OPTION]... [FILE]
14
- A simple gemspec editor
15
-
16
- EOS
17
-
18
- opt :new, "Create a new gemspec"
19
- opt :update, "Update the manifest"
20
- opt :manifest, "Dump the manifest"
21
- end
22
-
23
- action = opts.detect { |opt, val| actions.include?(opt) && val }
24
- action = action[0] unless action.nil?
25
-
26
- if action == :new
27
- # do nothing
28
- elsif (arg = ARGV.shift).nil?
29
- gemspecs = Dir['*.gemspec']
30
- gemspec = case gemspecs.length
31
- when 0
32
- nil
33
- when 1
34
- gemspecs.first
35
- else
36
- gemspecs
37
- end
38
- elsif File.exists?(arg)
39
- gemspec = arg
40
- else
41
- Trollop.die "No such file: #{arg}"
42
- end
43
-
44
- Trollop.die "Extra operand: #{ARGV[0]}" unless ARGV.empty?
45
-
46
- cli = Gemify::CLI.load(gemspec)
47
-
48
- case action
49
- when :update
50
- cli.update_manifest
51
- cli.save
52
- puts "Updated manifest (to #{cli.base.files.length} files)"
53
- when :manifest
54
- puts cli.base.inspect_files
55
- else
56
- cli.main
3
+ require 'gemify/version'
4
+ require 'fileutils'
5
+ include Gemify
6
+ include FileUtils
7
+
8
+ options, args = ARGV.partition { |a| a[0] == ?- }
9
+ verify_only = options.include?('-v')
10
+ force = options.include?('-f')
11
+
12
+ if options.grep(/^--?(h|\?)/).first
13
+ puts <<-EOF
14
+ Gemify v#{Gemify::VERSION}
15
+
16
+ Verify project and generate gemspec:
17
+ #$0
18
+
19
+ Only verify project:
20
+ #$0 -v
21
+
22
+ Show help:
23
+ #$0 -h
24
+ EOF
25
+ exit
26
+ end
27
+
28
+ puts <<-EOF
29
+ Gemify needs to know a bit about your project, but should be
30
+ able to guess most of the information. Type the value if you
31
+ need to correct it, or press ENTER to accept the suggestion by Gemify.
32
+
33
+ EOF
34
+
35
+ name = clean_name(args.shift || File.basename(Dir.pwd))
36
+ name = ask "Project name", name
37
+
38
+ namespace = name_to_namespace(name)
39
+ namespace = ask "Namespace", namespace
40
+
41
+ library = namespace_to_library(namespace)
42
+ library = ask "Library", 'lib/' + library
43
+ library = 'lib/' + library unless library =~ /^lib\//
44
+ puts
45
+
46
+ gemspec = "#{name}.gemspec"
47
+
48
+ if !force && !verify_only && File.exists?(gemspec)
49
+ puts <<-EOF
50
+ *** Gemspec already exists!
51
+ Either remove the gemspec:
52
+ mv #{gemspec} #{gemspec}.old
53
+
54
+ Or run the verifier only:
55
+ #{$0} -v #{ARGV.join(' ')}
56
+
57
+ Or force an overwrite:
58
+ #{$0} -f #{ARGV.join(' ')}
59
+ EOF
60
+ exit
61
+ end
62
+
63
+
64
+ ## Verify files
65
+
66
+ puts "*** Verifying the structure of lib/"
67
+
68
+ Dir["lib/**/*"].each do |file|
69
+ next if File.directory?(file)
70
+ next if file =~ /^lib\/tasks/
71
+
72
+ if File.extname(file) != ".rb"
73
+ w :lib_rb, "Non-Ruby library: #{file}"
74
+ end
75
+
76
+ if file !~ /^#{Regexp.escape(library)}(\.rb|\/)/
77
+ w :lib_leaky, "Library pollution: #{file}"
78
+ end
79
+
80
+ mode = File.stat(file).mode.to_s(8)[-4..-1]
81
+ if mode != "0644"
82
+ w :bin_mode, "Wrong permission (#{mode}): #{file}"
83
+ end
84
+ end
85
+
86
+ if w? :lib_rb
87
+ n "Please consider moving any library non-Ruby files to the data/ directory"
88
+ end
89
+
90
+ if w? :lib_leaky
91
+ n "Please consider moving all your library files to the #{library}/ directory"
92
+ end
93
+
94
+ if w? :lib_perm
95
+ n "Please consider to chmod all your library files to 0644"
96
+ if yes " Should Gemify do this for you?"
97
+ Dir["lib/**/*"].each do |file|
98
+ next if File.directory?(file)
99
+ chmod(0644, file)
100
+ end
101
+ end
102
+ end
103
+
104
+ version_require = library[4..-1] + '/version'
105
+ version_file = library + '/version.rb'
106
+ version = File.exists?(version_file)
107
+
108
+ unless version
109
+ n "Please consider to define #{namespace}::VERSION in #{version_file}"
110
+ end
111
+
112
+ puts "[.] Done"
113
+
114
+ puts
115
+ puts "*** Verifying the structure of bin/"
116
+
117
+ shebang = "#!/usr/bin/env ruby"
118
+
119
+ Dir["bin/*"].each do |file|
120
+ next if File.directory?(file)
121
+
122
+ File.open(file) do |f|
123
+ if f.read(shebang.length) != shebang
124
+ w :shebang, "Missing shebang: #{file}"
125
+ end
126
+ end
127
+
128
+ if File.extname(file) == ".rb"
129
+ w :bin_rb, ".rb extension: #{file}"
130
+ end
131
+
132
+ mode = File.stat(file).mode.to_s(8)[-4..-1]
133
+ if mode != "0755"
134
+ w :bin_mode, "Wrong permission (#{mode}): #{file}"
135
+ end
136
+ end
137
+
138
+ if w? :shebang
139
+ n "Please consider to add '#{shebang}' to all binaries"
140
+ end
141
+
142
+ if w? :bin_rb
143
+ n "Please consider that binaries should NOT end in .rb"
144
+ end
145
+
146
+ if w? :bin_mode
147
+ n "Please consider to chmod all your binary files to 0755"
148
+ if yes " Should Gemify do this for you?"
149
+ Dir["bin/*"].each do |file|
150
+ next if File.directory?(file)
151
+ chmod(0755, file)
152
+ end
153
+ end
154
+ end
155
+
156
+ puts "[.] Done"
157
+
158
+ puts
159
+ puts "*** Verifying the structure of ext/"
160
+
161
+ Dir["ext/*"].each do |ext|
162
+ unless File.exists?(ext + '/extconf.rb')
163
+ w :ext_conf, "Missing extconf.rb: #{ext}"
164
+ end
165
+ end
166
+
167
+ if w? :ext_conf
168
+ n "All extensions MUST have a extconf.rb"
169
+ end
170
+
171
+ puts "[.] Done"
172
+
173
+ exit if options.include?('-v')
174
+
175
+ puts
176
+ puts "*** Generating a gemspec"
177
+
178
+ require 'erb'
179
+ require 'time'
180
+
181
+ now = Time.now.strftime('%Y-%m-%d')
182
+ content = ERB.new(DATA.read).result(binding)
183
+ File.open(gemspec, "w") do |f|
184
+ f << content
185
+ end
186
+
187
+ puts "[.] Done"
188
+ puts
189
+ puts <<EOF
190
+ Please open #{gemspec} in your text editor and fill out the details.
191
+
192
+ You should fix any warnings that was reported above. You won't need to
193
+ generate a new gemspec after you've fixed them.
194
+ EOF
195
+
196
+ unless version
197
+ mkdir_p(File.dirname(version_file))
198
+
199
+ File.open(version_file, "w") do |f|
200
+ i = 0
201
+ mods = namespace.split("::")
202
+ mods.each do |mod|
203
+ f.puts("#{' '*i}module #{mod}")
204
+ i += 1
205
+ end
206
+
207
+ f.puts("#{' '*i}VERSION = '0.0.1'")
208
+
209
+ mods.each do
210
+ i -= 1
211
+ f.puts("#{' '*i}end")
212
+ end
213
+ end
214
+
215
+ puts
216
+ puts <<-EOF
217
+ You must also define #{namespace}::VERSION in #{version_file}.
218
+ Gemify has automatically created the file for you, so simply
219
+ open it in your text editor and fill in the current version.
220
+ EOF
221
+ end
222
+
223
+ __END__
224
+ # -*- encoding: utf-8 -*-
225
+ $:.push('lib')
226
+ require <%= version_require.inspect %>
227
+
228
+ Gem::Specification.new do |s|
229
+ s.name = <%= name.inspect %>
230
+ s.version = <%= namespace %>::VERSION.dup
231
+ s.date = <%= now.inspect %>
232
+ s.summary = "TODO: Summary of project"
233
+ s.email = "todo@project.com"
234
+ s.homepage = "http://todo.project.com/"
235
+ s.authors = ['Me Todo']
236
+
237
+ s.description = <<-EOF
238
+ TODO: Long description
239
+ EOF
240
+
241
+ dependencies = [
242
+ # Examples:
243
+ # [:runtime, "rack", "~> 1.1"],
244
+ # [:development, "rspec", "~> 2.1"],
245
+ ]
246
+
247
+ s.files = Dir['**/*']
248
+ s.test_files = Dir['test/**/*'] + Dir['spec/**/*']
249
+ s.executables = Dir['bin/*'].map { |f| File.basename(f) }
250
+ s.require_paths = ["lib"]
251
+
252
+
253
+ ## Make sure you can build the gem on older versions of RubyGems too:
254
+ s.rubygems_version = <%= Gem::VERSION.inspect %>
255
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
256
+ s.specification_version = 3 if s.respond_to? :specification_version
257
+
258
+ dependencies.each do |type, name, version|
259
+ if s.respond_to?("add_#{type}_dependency")
260
+ s.send("add_#{type}_dependency", name, version)
261
+ else
262
+ s.add_dependency(name, version)
263
+ end
264
+ end
57
265
  end