Created
March 27, 2014 18:43
-
-
Save renier/9815009 to your computer and use it in GitHub Desktop.
Is there a better way to pick up included files for 'rake package'?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rake/packagetask' | |
require 'bundler/gem_tasks' | |
require 'rubocop/rake_task' | |
require 'find' | |
require 'pathname' | |
ROOT_DIR = File.dirname(__FILE__) | |
spec = Gem::Specification::load("#{Dir.glob(ROOT_DIR + '/*.gemspec')[0]}") | |
task :rubocop do | |
Rubocop::RakeTask.new | |
end | |
ignored = File.open("#{ROOT_DIR}/.gitignore").readlines.map { |f| f.chomp } | |
ignored += ['.git', '.gitignore' ] | |
Rake::PackageTask.new(spec.name, spec.version.to_s) do |p| | |
p.need_tar_bz2 = p.need_zip = true | |
included = [] | |
Find.find(ROOT_DIR) do |path| | |
path = Pathname.new(path).relative_path_from(Pathname.new(ROOT_DIR)).to_s | |
ok = true | |
ignored.each do |ignore| | |
if File.fnmatch(ignore, path) | |
Find.prune if FileTest.directory?(path) | |
ok = false | |
break | |
end | |
end | |
included << path if ok | |
end | |
p.package_files = included | |
end | |
task default: 'rubocop' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, there is a much better way. Asked on IRC, and someone pointed to
git ls-files
used by bundler. Since I'm already loading my gemspec, and it uses the same method to fill in the files, I can just use this: