lib/rake_ext/project.rb in ruby_ext-0.4.13 vs lib/rake_ext/project.rb in ruby_ext-0.4.14

- old
+ new

@@ -56,48 +56,76 @@ # require 'rake/clean' require 'rake/gempackagetask' require 'tmpdir' -namespace :gem do - spec = Gem::Specification.new do |s| - gems, fake_gems = parse_project_gemfile - gems = gems + fake_gems +class GemHelper + class << self + def next_version gem_name + %x(gem list --remote #{gem_name}).scan /#{gem_name} \((\d+\.\d+\.\d+)\)/ do |s| + v = s.first.split('.').collect{|d| d.to_i} + v[-1] = v[-1] + 1 + return v.join('.') + end + return '0.0.1' + end - gems.each{|name_version| s.add_dependency *name_version} + def prepare_gem_metadata + spec = Gem::Specification.new do |s| + gems, fake_gems = parse_project_gemfile + gems = gems + fake_gems - options = project.clone + gems.each{|name_version| s.add_dependency *name_version} - options.delete(:name) - s.name = options.delete(:official_name) - s.platform = options.delete(:platform) || Gem::Platform::RUBY - s.has_rdoc = options.delete(:has_rdoc) == nil ? false : true - s.require_path = options.delete(:lib) || "lib" - s.files = options.delete(:files) || (%w{Rakefile readme.md} + Dir.glob("{lib,spec}/**/*")) - s.bindir = options.delete(:bin) if options.include? :bin + options = project.clone - # s.name = options[:name) - # s.author = options[:author) - # s.homepage = options[:homepage) + options.delete(:name) + options.delete(:gem) || raise("this project isn't a gem!") + name = options.delete(:official_name) - options.each{|k, v| s.send "#{k}=", v} - end + s.name = name + s.platform = options.delete(:platform) || Gem::Platform::RUBY + s.has_rdoc = options.delete(:has_rdoc) == nil ? false : true + s.require_path = options.delete(:lib) || "lib" + s.files = options.delete(:files) || (%w{Rakefile readme.md} + Dir.glob("{lib,spec}/**/*")) + s.bindir = options.delete(:bin) if options.include? :bin - package_dir = Dir.tmpdir + "/#{project[:official_name]}_tmp" - Rake::GemPackageTask.new(spec) do |p| - p.need_tar = true if RUBY_PLATFORM !~ /mswin/ - p.need_zip = true - p.package_dir = package_dir + s.version = options.delete(:version) || GemHelper.next_version(name) + + # s.name = options[:name) + # s.author = options[:author) + # s.homepage = options[:homepage) + + options.each{|k, v| s.send "#{k}=", v} + end + + Rake::GemPackageTask.new(spec) do |p| + p.need_tar = true if RUBY_PLATFORM !~ /mswin/ + p.need_zip = true + p.package_dir = package_dir + end + end + + def package_dir + Dir.tmpdir + "/#{project[:official_name]}_tmp" + end end +end - task :push do - gem_file = Dir.glob("#{package_dir}/#{project[:official_name]}*.gem").first +namespace :gem do + task :ensure_gem do + GemHelper.prepare_gem_metadata + end + + task push: :ensure_gem do + gem_file = Dir.glob("#{GemHelper.package_dir}/#{project[:official_name]}*.gem").first system "gem push #{gem_file}" end - task :clean do - system "rm -r #{package_dir}" + task clean: :ensure_gem do + GemHelper.prepare_gem_metadata + system "rm -r #{GemHelper.package_dir}" end - desc "Build and publish project as gem" - task release: [:gem, :push, :clean] + desc "Build and publish project as gem" + task release: [:ensure_gem, :gem, :push, :clean] end \ No newline at end of file