Skip to content

Commit 6dd27e2

Browse files
committed
feat: enable file list in gemspec to work without git
1 parent 6a745d4 commit 6dd27e2

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.DS_Store
12
*.gem
23
*.rbc
34
.bundle
@@ -6,6 +7,7 @@ coverage
67
InstalledFiles
78
lib/bundler/man
89
log
10+
*.log
911
pkg
1012
rdoc
1113
spec/reports
@@ -30,6 +32,7 @@ Gemfile.lock
3032

3133
bethtest/
3234
*bethtest*
35+
*bethtemp*
3336
*dogfood*
3437
bin/
3538
db/test/change_migration_strategy/pact_broker_database.sqlite3

pact_broker.gemspec

+23-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@ lib = File.expand_path('../lib', __FILE__)
33
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
44
require 'pact_broker/version'
55

6+
def gem_files
7+
if Dir.exist?(".git")
8+
`git ls-files`.split($/)
9+
else
10+
root_path = File.dirname(__FILE__)
11+
all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
12+
all_files.reject! { |file| [".", ".."].include?(File.basename(file)) || File.directory?(file)}
13+
gitignore_path = File.join(root_path, ".gitignore")
14+
gitignore = File.readlines(gitignore_path)
15+
gitignore.map! { |line| line.chomp.strip }
16+
gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
17+
18+
all_files.reject do |file|
19+
gitignore.any? do |ignore|
20+
file.start_with?(ignore) ||
21+
File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
22+
File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
23+
end
24+
end
25+
end
26+
end
27+
628
Gem::Specification.new do |gem|
729
gem.name = "pact_broker"
830
gem.version = PactBroker::VERSION
@@ -14,7 +36,7 @@ Gem::Specification.new do |gem|
1436

1537
gem.required_ruby_version = '>= 2.2.0'
1638

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

0 commit comments

Comments
 (0)