Skip to content

Commit

Permalink
add gem packaging tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Carver committed Jul 3, 2010
1 parent fe1dd72 commit 4c200f1
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
target
tmp
_site
pkg
115 changes: 103 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
require 'rubygems'
require 'rake'
require 'date'

#############################################################################
#
# Helper functions
#
#############################################################################

def name
@name ||= Dir['*.gemspec'].first.split('.').first
end

def version
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
end

def date
Date.today.to_s
end

def gemspec_file
"#{name}.gemspec"
end

def gem_file
"#{name}-#{version}.gem"
end

def replace_header(head, header_name)
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
end

#############################################################################
#
# Standard tasks
#
#############################################################################

desc "Open an irb session preloaded with this library"
task :console do
sh "irb -rubygems -r ./lib/#{name}.rb"
end

#############################################################################
#
# Custom tasks (add your own tasks here)
#
#############################################################################

require 'rake/clean'

$LOAD_PATH.unshift File.dirname(__FILE__) + "/lib"
Expand Down Expand Up @@ -123,25 +175,64 @@ task :gzipbytes => "target/webfont.js" do |t|
puts "#{bytes} bytes gzipped"
end


#############################################################################
#
# Release
# Packaging tasks
#
#############################################################################

def name
@name ||= "webfontloader"
task :release => :build do
unless `git branch` =~ /^\* master$/
puts "You must be on the master branch to release!"
exit!
end
sh "git commit --allow-empty -a -m 'Release #{version}'"
sh "git tag v#{version}"
sh "git push --tags origin master"
# sh "gem push pkg/#{name}-#{version}.gem"
end

def version
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
task :build => :gemspec do
sh "mkdir -p pkg"
sh "gem build #{gemspec_file}"
sh "mv #{gem_file} pkg"
end

task :release do
unless `git branch` =~ /^\* master$/
puts "You must be on the master branch to release!"
task :gemspec => :validate do
# read spec file and split out manifest section
spec = File.read(gemspec_file)
head, manifest, tail = spec.split(" # = MANIFEST =\n")

# replace name version and date
replace_header(head, :name)
replace_header(head, :version)
replace_header(head, :date)

# determine file list from git ls-files
files = `git ls-files`.
split("\n").
sort.
reject { |file| file =~ /^\./ }.
reject { |file| file =~ /^(rdoc|pkg)/ }.
map { |file| " #{file.gsub(/\s/, '\ ')}" }.
join("\n")

# piece file back together and write
manifest = " s.files = %w[\n#{files}\n ]\n"
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
File.open(gemspec_file, 'w') { |io| io.write(spec) }
puts "Updated #{gemspec_file}"
end

task :validate do
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
unless libfiles.empty?
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
exit!
end
unless Dir['VERSION*'].empty?
puts "A `VERSION` file at root level violates Gem best practices."
exit!
end
sh "git commit --allow-empty -a -m 'Release #{version}'"
sh "git tag -a v#{version}"
sh "git push origin master --tags"
end
141 changes: 141 additions & 0 deletions webfontloader.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
## This is the rakegem gemspec template. Make sure you read and understand
## all of the comments. Some sections require modification, and others can
## be deleted if you don't need them. Once you understand the contents of
## this file, feel free to delete any comments that begin with two hash marks.
## You can find comprehensive Gem::Specification documentation, at
## http://docs.rubygems.org/read/chapter/20
Gem::Specification.new do |s|
s.specification_version = 2 if s.respond_to? :specification_version=
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.rubygems_version = '1.3.5'

## Leave these as is they will be modified for you by the rake gemspec task.
## If your rubyforge_project name is different, then edit it and comment out
## the sub! line in the Rakefile
s.name = 'webfontloader'
s.version = '1.0.4'
s.date = '2010-06-14'

## Make sure your summary is short. The description may be as long
## as you like.
s.summary = "WebFont Loader gives you added control when using linked fonts via @font-face."
s.description = <<-DESC
WebFont Loader gives you added control when using linked fonts via
`@font-face`. It provides a common interface to loading fonts regardless of
the source, then adds a standard set of events you may use to control the
loading experience.
DESC

## List the primary authors. If there are a bunch of authors, it's probably
## better to set the email to an email list or something. If you don't have
## a custom homepage, consider using your GitHub URL or the like.
s.authors = ["Ryan Carver", "Jeremie Lenfant-engelmann"]
s.email = 'ryan@typekit.com'
s.homepage = 'http://github.com/typekit/webfontloader'

## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
s.require_paths = %w[lib]

## This sections is only necessary if you have C extensions.
# s.require_paths << 'ext'
# s.extensions = %w[ext/extconf.rb]

## If your gem includes any executables, list them here.
# s.executables = []
# s.default_executable = 'name'

## Specify any RDoc options here. You'll want to add your README and
## LICENSE files to the extra_rdoc_files list.
s.rdoc_options = ["--charset=UTF-8"]
s.extra_rdoc_files = %w[README.md]

## List your runtime dependencies here. Runtime dependencies are those
## that are needed for an end user to actually USE your code.
# s.add_dependency('DEPNAME', [">= 1.1.0", "< 2.0.0"])

## List your development dependencies here. Development dependencies are
## those that are only needed during development
# s.add_development_dependency('thin', ["~>1.2.7"])

## Leave this section as-is. It will be automatically generated from the
## contents of your Git repository via the gemspec task. DO NOT REMOVE
## THE MANIFEST COMMENTS, they are used as delimiters by the task.
# = MANIFEST =
s.files = %w[
Gemfile
LICENSE
README.md
Rakefile
bin/webfontloader-demos
docs/EVENTS.md
docs/MODULES.md
docs/TRANSITIONS.md
lib/webfontloader.rb
lib/webfontloader/demo/public/ascender.html
lib/webfontloader/demo/public/basic.css
lib/webfontloader/demo/public/custom.html
lib/webfontloader/demo/public/event-css-active-multiple.html
lib/webfontloader/demo/public/event-css-active.html
lib/webfontloader/demo/public/event-css-inactive.html
lib/webfontloader/demo/public/event-css-loading.html
lib/webfontloader/demo/public/event-js-active.html
lib/webfontloader/demo/public/event-js-font-active.html
lib/webfontloader/demo/public/event-js-loading.html
lib/webfontloader/demo/public/events-variations.html
lib/webfontloader/demo/public/events.html
lib/webfontloader/demo/public/google-css.html
lib/webfontloader/demo/public/google.html
lib/webfontloader/demo/public/ie-fast-js.html
lib/webfontloader/demo/public/ie-slow-js.html
lib/webfontloader/demo/public/ie-slow-link.html
lib/webfontloader/demo/public/index.html
lib/webfontloader/demo/public/typekit-variations.html
lib/webfontloader/demo/public/typekit.html
lib/webfontloader/demo/server.rb
lib/webfontloader/modules.rb
src-test/ascender/ascender_script_test.js
src-test/core/cssclassnametest.js
src-test/core/cssfontfamilynametest.js
src-test/core/domhelpertest.js
src-test/core/eventdispatchertest.js
src-test/core/fontmoduleloadertest.js
src-test/core/fonttest.js
src-test/core/fontvariationdescriptiontest.js
src-test/core/fontwatchertest.js
src-test/core/useragenttest.js
src-test/custom/customcsstest.js
src-test/google/fontapiparsertest.js
src-test/google/fontapiurlbuildertest.js
src-test/google/googlefontapitest.js
src-test/typekit/typekit_script_test.js
src/ascender/ascender_script.js
src/async_load.js
src/closure.js
src/core/cssclassname.js
src/core/cssfontfamilyname.js
src/core/domhelper.js
src/core/eventdispatcher.js
src/core/font.js
src/core/fontmoduleloader.js
src/core/fontvariationdescription.js
src/core/fontwatcher.js
src/core/initialize.js
src/core/namespace.js
src/core/useragent.js
src/core/useragentparser.js
src/custom/customcss.js
src/google/fontapiparser.js
src/google/fontapiurlbuilder.js
src/google/googlefontapi.js
src/modules.yml
src/typekit/typekit_script.js
tools/compiler/compiler.jar
tools/jstestdriver/JsTestDriver-1.2.1.jar
]
# = MANIFEST =

## Test files will be grabbed from the file list. Make sure the path glob
## matches what you actually use.
s.test_files = s.files.select { |path| path =~ /^spec\/.*_spec\.rb/ }
end

0 comments on commit 4c200f1

Please sign in to comment.