This repository has been archived by the owner on Jan 23, 2018. It is now read-only.
/
gemify.rb
48 lines (39 loc) · 1.53 KB
/
gemify.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'harker'
require 'fileutils'
module Harker
def self.gemify(rails_root)
project_name = File.basename(rails_root)
if File.writable?(rails_root + "/bin/#{project_name}") or
File.writable?(rails_root + "/lib/#{project_name}.rb")
abort "Can't write gem files without overwriting existing ones.
Try manually gemifying."
end
# TODO: Hoe's test tasks stomp on Rails'
# TODO: can we specify the version better?
hoe = "require 'hoe'
Hoe.new('#{project_name}', '1.0.0') do |p|
p.extra_deps << ['rails', '~> 2.3.2']
p.extra_deps << ['harker', '~> #{Harker::VERSION}']
p.developer('Your Name', 'you@example.com') # FIXME!
end"
bin = "#!/usr/bin/env ruby
require 'rubygems'
require 'harker'
Harker.launch(File.basename($0), ARGV)"
lib = "# Allow rubygems to load this app
require File.dirname(__FILE__) + '/../config/environment'"
unless File.exist?(rails_root + '/Manifest.txt')
abort "Create a Manifest.txt with a list of the files from your Rails app that you'd like to package"
end
File.open(rails_root + '/Rakefile', 'a') { |fp| fp.puts hoe }
puts "Added hoe block to Rakefile."
FileUtils.mkdir_p(rails_root + '/bin')
File.open(rails_root + "/bin/#{project_name}", 'w') {|fp| fp.puts bin }
puts "Wrote bin launcher."
File.open(rails_root + "/lib/#{project_name}.rb", 'w') {|fp| fp.puts lib }
puts "Wrote lib file."
system "cd #{rails_root}; rake check_manifest | patch"
puts "Wrote manifest."
puts "Done! Try running rake install_gem."
end
end