task/gemgem.rb in rack-handlers-0.7.2 vs task/gemgem.rb in rack-handlers-0.7.3
- old
+ new
@@ -32,14 +32,116 @@
s.files = gem_files
s.test_files = test_files
s.executables = bin_files
end
spec_create.call(spec)
- spec.homepage = "https://github.com/godfat/#{spec.name}"
+ spec.homepage ||= "https://github.com/godfat/#{spec.name}"
self.spec = spec
end
+ def gem_install
+ require 'rubygems/commands/install_command'
+ # read ~/.gemrc
+ Gem.use_paths(Gem.configuration[:gemhome], Gem.configuration[:gempath])
+ Gem::Command.extra_args = Gem.configuration[:gem]
+
+ # setup install options
+ cmd = Gem::Commands::InstallCommand.new
+ cmd.handle_options([])
+
+ # install
+ install = Gem::Installer.new(gem_path, cmd.options)
+ install.install
+ puts "\e[35mGem installed: \e[33m#{strip_path(install.gem_dir)}\e[0m"
+ end
+
+ def gem_spec
+ create
+ write
+ end
+
+ def gem_build
+ require 'fileutils'
+ require 'rubygems/package'
+ gem = nil
+ Dir.chdir(dir) do
+ gem = Gem::Package.build(Gem::Specification.load(spec_path))
+ FileUtils.mkdir_p(pkg_dir)
+ FileUtils.mv(gem, pkg_dir) # gem is relative path, but might be ok
+ end
+ puts "\e[35mGem built: \e[33m#{strip_path("#{pkg_dir}/#{gem}")}\e[0m"
+ end
+
+ def gem_release
+ sh_git('tag', gem_tag)
+ sh_git('push')
+ sh_git('push', '--tags')
+ sh_gem('push', gem_path)
+ end
+
+ def gem_check
+ unless git('status', '--porcelain').empty?
+ puts("\e[35mWorking copy is not clean.\e[0m")
+ exit(3)
+ end
+
+ ver = spec.version.to_s
+
+ if ENV['VERSION'].nil?
+ puts("\e[35mExpected " \
+ "\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
+ exit(1)
+
+ elsif ENV['VERSION'] != ver
+ puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
+ "\e[35mbut got\n " \
+ "\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
+ exit(2)
+ end
+ end
+
+ def test
+ return if test_files.empty?
+
+ if ENV['COV'] || ENV['CI']
+ require 'simplecov'
+ if ENV['CI']
+ begin
+ require 'coveralls'
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
+ rescue LoadError => e
+ puts "Cannot load coveralls, skip: #{e}"
+ end
+ end
+ SimpleCov.start do
+ add_filter('test/')
+ add_filter('test.rb')
+ end
+ end
+
+ test_files.each{ |file| require "#{dir}/#{file[0..-4]}" }
+ end
+
+ def clean
+ return if ignored_files.empty?
+
+ require 'fileutils'
+ trash = File.expand_path("~/.Trash/#{spec.name}")
+ puts "Move the following files into: \e[35m#{strip_path(trash)}\e[33m"
+
+ ignored_files.each do |file|
+ from = "#{dir}/#{file}"
+ to = "#{trash}/#{File.dirname(file)}"
+ puts strip_path(from)
+
+ FileUtils.mkdir_p(to)
+ FileUtils.mv(from, to)
+ end
+
+ print "\e[0m"
+ end
+
def write
File.open(spec_path, 'w'){ |f| f << split_lines(spec.to_ruby) }
end
def split_lines ruby
@@ -142,24 +244,22 @@
def ignored_files
@ignored_files ||= all_files.grep(ignored_pattern)
end
def ignored_pattern
- @ignored_pattern ||= Regexp.new(expand_patterns(gitignore).join('|'))
+ @ignored_pattern ||= if gitignore.empty?
+ /^$/
+ else
+ Regexp.new(expand_patterns(gitignore).join('|'))
+ end
end
def expand_patterns pathes
# http://git-scm.com/docs/gitignore
pathes.flat_map{ |path|
- case path
- when %r{\*}
- Regexp.escape(path).gsub(/\\\*/, '[^/]*')
- when %r{^/}
- "^#{Regexp.escape(path[1..-1])}"
- else # we didn't implement negative pattern for now
- Regexp.escape(path)
- end
+ # we didn't implement negative pattern for now
+ Regexp.escape(path).sub(%r{^/}, '^').gsub(/\\\*/, '[^/]*')
}
end
def gitignore
@gitignore ||= if File.exist?(path = "#{dir}/.gitignore")
@@ -173,89 +273,41 @@
namespace :gem do
desc 'Install gem'
task :install => [:build] do
- Gemgem.sh_gem('install', Gemgem.gem_path)
+ Gemgem.gem_install
end
desc 'Build gem'
task :build => [:spec] do
- require 'fileutils'
- require 'rubygems/package'
- gem = nil
- Dir.chdir(Gemgem.dir) do
- gem = Gem::Package.build(Gem::Specification.load(Gemgem.spec_path))
- FileUtils.mkdir_p(Gemgem.pkg_dir)
- FileUtils.mv(gem, Gemgem.pkg_dir) # gem is relative path, but might be ok
- end
- puts "\e[35mGem built: \e[33m" \
- "#{Gemgem.strip_path("#{Gemgem.pkg_dir}/#{gem}")}\e[0m"
+ Gemgem.gem_build
end
desc 'Generate gemspec'
task :spec do
- Gemgem.create
- Gemgem.write
+ Gemgem.gem_spec
end
desc 'Release gem'
task :release => [:spec, :check, :build] do
- Gemgem.module_eval do
- sh_git('tag', Gemgem.gem_tag)
- sh_git('push')
- sh_git('push', '--tags')
- sh_gem('push', Gemgem.gem_path)
- end
+ Gemgem.gem_release
end
task :check do
- ver = Gemgem.spec.version.to_s
-
- if ENV['VERSION'].nil?
- puts("\e[35mExpected " \
- "\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
- exit(1)
-
- elsif ENV['VERSION'] != ver
- puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
- "\e[35mbut got\n " \
- "\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
- exit(2)
- end
+ Gemgem.gem_check
end
end # of gem namespace
-desc 'Run tests in memory'
+desc 'Run tests'
task :test do
- next if Gemgem.test_files.empty?
-
- require 'bacon'
- Bacon.extend(Bacon::TestUnitOutput)
- Bacon.summary_on_exit
- Gemgem.test_files.each{ |file| require "#{Gemgem.dir}/#{file[0..-4]}" }
+ Gemgem.test
end
-desc 'Remove ignored files'
+desc 'Trash ignored files'
task :clean => ['gem:spec'] do
- next if Gemgem.ignored_files.empty?
-
- require 'fileutils'
- trash = File.expand_path("~/.Trash/#{Gemgem.spec.name}")
- puts "Move the following files into:" \
- " \e[35m#{Gemgem.strip_path(trash)}\e[33m"
-
- Gemgem.ignored_files.each do |file|
- from = "#{Gemgem.dir}/#{file}"
- to = "#{trash}/#{File.dirname(file)}"
- puts Gemgem.strip_path(from)
-
- FileUtils.mkdir_p(to)
- FileUtils.mv(from, to)
- end
-
- print "\e[0m"
+ Gemgem.clean
end
task :default do
# Is there a reliable way to do this in the current process?
# It failed miserably before between Rake versions...