source: chunker/Rakefile @ 62a5ac525ce8

Revision 62a5ac525ce8, 3.7 KB checked in by Mahlon E. Smith <mahlon@…>, 16 months ago (diff)

Update copyright, make description shorter so it'll look nicer when
formatted on rubygems.org.

Line 
1#!/usr/bin/env rake
2#
3
4require 'rubygems'
5require 'pathname'
6
7require 'rake'
8require 'rspec'
9require 'rspec/core/rake_task'
10require 'rake/packagetask'
11require 'rake/gempackagetask'
12require 'rubygems/installer'
13require 'rubygems/uninstaller'
14
15
16######################################################################
17### P A T H S  A N D  F I L E S
18######################################################################
19
20BASEDIR = Pathname.new( __FILE__ ).expand_path.dirname.relative_path_from( Pathname.getwd )
21
22TEXT_FILES = %w{ Rakefile README LICENSE }.collect {|f| BASEDIR + f }
23
24SPECDIR    = BASEDIR + 'spec'
25SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' )
26
27LIBDIR    = BASEDIR + 'lib'
28LIB_FILES = Pathname.glob( LIBDIR + '**/*.rb')
29
30RELEASE_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###
40def 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'
48end
49
50
51######################################################################
52### P A C K A G E   C O N S T A N T S
53######################################################################
54
55PKG_NAME      = 'chunker'
56PKG_VERSION   = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](.+)['"]/ )
57PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
58
59
60######################################################################
61### T A S K S
62######################################################################
63
64task :test    => 'test:spec'
65task :default => :test
66# task :default => [ :test, :package ]
67
68
69### Tasks: testing via rspec
70###
71namespace :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
83end
84
85
86### Task: generate ctags
87### This assumes exuberant ctags, since ctags 'native' doesn't support ruby anyway.
88###
89desc "Generate a ctags 'tags' file from Chunker source"
90task :ctags do
91    sh "ctags -R #{LIBDIR}"
92end
93
94
95### Task: Create gem from source
96###
97gem = 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."
115end
116
117Rake::GemPackageTask.new( gem ) do |pkg|
118    pkg.need_zip     = true
119    pkg.need_tar     = true
120    pkg.need_tar_bz2 = true
121end
122
123
124### Task: install
125###
126task :install_gem => [ :package ] do
127    $stderr.puts
128    installer = Gem::Installer.new( "pkg/#{PKG_FILE_NAME}.gem" )
129    installer.install
130end
131task :install => [ :install_gem ]
132
133
134### Task: uninstall
135###
136task :uninstall_gem do
137    uninstaller = Gem::Uninstaller.new( PKG_NAME )
138    uninstaller.uninstall
139end
140task :uninstall => [ :uninstall_gem ]
141
Note: See TracBrowser for help on using the repository browser.