Rakefile
branchruby-modules
changeset 9 bab54dae339a
parent 6 62a5ac525ce8
equal deleted inserted replaced
8:fe38422c10a4 9:bab54dae339a
       
     1 #!/usr/bin/env rake
       
     2 #
       
     3 
       
     4 require 'rubygems'
       
     5 require 'pathname'
       
     6 
       
     7 require 'rake'
       
     8 require 'rspec'
       
     9 require 'rspec/core/rake_task'
       
    10 require 'rake/packagetask'
       
    11 require 'rake/gempackagetask'
       
    12 require 'rubygems/installer'
       
    13 require 'rubygems/uninstaller'
       
    14 
       
    15 
       
    16 ######################################################################
       
    17 ### P A T H S  A N D  F I L E S
       
    18 ######################################################################
       
    19 
       
    20 BASEDIR = Pathname.new( __FILE__ ).expand_path.dirname.relative_path_from( Pathname.getwd )
       
    21 
       
    22 TEXT_FILES = %w{ Rakefile README LICENSE }.collect {|f| BASEDIR + f }
       
    23 
       
    24 SPECDIR    = BASEDIR + 'spec'
       
    25 SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' )
       
    26 
       
    27 LIBDIR    = BASEDIR + 'lib'
       
    28 LIB_FILES = Pathname.glob( LIBDIR + '**/*.rb')
       
    29 
       
    30 RELEASE_FILES = TEXT_FILES + LIB_FILES + SPEC_FILES
       
    31 
       
    32 
       
    33 ######################################################################
       
    34 ### H E L P E R S
       
    35 ######################################################################
       
    36 
       
    37 ### Given a +file+ path, find the first captured match of +pattern+,
       
    38 ### or the string 'UNKNOWN' if not found. (easy to notice something is wrong.)
       
    39 ###
       
    40 def find_pattern( file, pattern )
       
    41 	ver = nil
       
    42 	File.open( file ) do |f|
       
    43 		ver = f.each do |line|
       
    44 			break $1 if line =~ pattern
       
    45 		end
       
    46 	end
       
    47 	return ver.is_a?( String ) ? ver : 'UNKNOWN'
       
    48 end
       
    49 
       
    50 
       
    51 ######################################################################
       
    52 ### P A C K A G E   C O N S T A N T S
       
    53 ######################################################################
       
    54 
       
    55 PKG_NAME      = 'chunker'
       
    56 PKG_VERSION   = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](.+)['"]/ )
       
    57 PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
       
    58 
       
    59 
       
    60 ######################################################################
       
    61 ### T A S K S
       
    62 ######################################################################
       
    63 
       
    64 task :test    => 'test:spec'
       
    65 task :default => :test
       
    66 # task :default => [ :test, :package ]
       
    67 
       
    68 
       
    69 ### Tasks: testing via rspec
       
    70 ###
       
    71 namespace :test do
       
    72 	desc 'Generate verbose and pretty output'
       
    73 	RSpec::Core::RakeTask.new( :spec ) do |task|
       
    74 		task.pattern = SPEC_FILES
       
    75 		task.rspec_opts  = ['-b', '-fd', '-c']
       
    76 	end
       
    77 
       
    78 	desc 'Generate quiet non-colored plain-text output'
       
    79 	RSpec::Core::RakeTask.new( :quiet ) do |task|
       
    80 		task.pattern = SPEC_FILES
       
    81 		task.rspec_opts  = ['-f', 'p']
       
    82 	end
       
    83 end
       
    84 
       
    85 
       
    86 ### Task: generate ctags
       
    87 ### This assumes exuberant ctags, since ctags 'native' doesn't support ruby anyway.
       
    88 ###
       
    89 desc "Generate a ctags 'tags' file from Chunker source"
       
    90 task :ctags do
       
    91 	sh "ctags -R #{LIBDIR}"
       
    92 end
       
    93 
       
    94 
       
    95 ### Task: Create gem from source
       
    96 ###
       
    97 gem = Gem::Specification.new do |gem|
       
    98 	gem.summary           = "A convenience library for parsing __END__ tokens consistently."
       
    99 	gem.name              = PKG_NAME
       
   100 	gem.version           = PKG_VERSION
       
   101 	gem.author            = 'Mahlon E. Smith'
       
   102 	gem.email             = 'mahlon@martini.nu'
       
   103 	gem.homepage          = 'http://projects.martini.nu/ruby-modules/wiki/Chunker'
       
   104 	gem.has_rdoc          = true
       
   105 	gem.extra_rdoc_files  = ['README']
       
   106 	gem.rdoc_options      << '--main' << 'README'
       
   107 
       
   108 
       
   109 	gem.files = RELEASE_FILES.
       
   110 		collect {|f| f.relative_path_from(BASEDIR).to_s }
       
   111 	gem.test_files	= SPEC_FILES.
       
   112 		collect {|f| f.relative_path_from(BASEDIR).to_s }
       
   113 
       
   114 	gem.description = "Embed arbitrary data and multiple, distinct documents within ruby files."
       
   115 end
       
   116 
       
   117 Rake::GemPackageTask.new( gem ) do |pkg|
       
   118 	pkg.need_zip     = true
       
   119 	pkg.need_tar     = true
       
   120 	pkg.need_tar_bz2 = true
       
   121 end
       
   122 
       
   123 
       
   124 ### Task: install
       
   125 ###
       
   126 task :install_gem => [ :package ] do
       
   127 	$stderr.puts
       
   128 	installer = Gem::Installer.new( "pkg/#{PKG_FILE_NAME}.gem" )
       
   129 	installer.install
       
   130 end
       
   131 task :install => [ :install_gem ]
       
   132 
       
   133 
       
   134 ### Task: uninstall
       
   135 ###
       
   136 task :uninstall_gem do
       
   137 	uninstaller = Gem::Uninstaller.new( PKG_NAME )
       
   138 	uninstaller.uninstall
       
   139 end
       
   140 task :uninstall => [ :uninstall_gem ]
       
   141