Skip to content

Commit

Permalink
feat: enable file list in gemspec to work without git
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jan 14, 2019
1 parent 6a745d4 commit 6dd27e2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
*.gem
*.rbc
.bundle
Expand All @@ -6,6 +7,7 @@ coverage
InstalledFiles
lib/bundler/man
log
*.log
pkg
rdoc
spec/reports
Expand All @@ -30,6 +32,7 @@ Gemfile.lock

bethtest/
*bethtest*
*bethtemp*
*dogfood*
bin/
db/test/change_migration_strategy/pact_broker_database.sqlite3
Expand Down
24 changes: 23 additions & 1 deletion pact_broker.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'pact_broker/version'

def gem_files
if Dir.exist?(".git")
`git ls-files`.split($/)
else
root_path = File.dirname(__FILE__)
all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
all_files.reject! { |file| [".", ".."].include?(File.basename(file)) || File.directory?(file)}
gitignore_path = File.join(root_path, ".gitignore")
gitignore = File.readlines(gitignore_path)
gitignore.map! { |line| line.chomp.strip }
gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }

all_files.reject do |file|
gitignore.any? do |ignore|
file.start_with?(ignore) ||
File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
end
end
end
end

Gem::Specification.new do |gem|
gem.name = "pact_broker"
gem.version = PactBroker::VERSION
Expand All @@ -14,7 +36,7 @@ Gem::Specification.new do |gem|

gem.required_ruby_version = '>= 2.2.0'

gem.files = `git ls-files`.split($/)
gem.files = gem_files
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
Expand Down

0 comments on commit 6dd27e2

Please sign in to comment.