bundler-squash 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fcb506ace12af922452039bb6a5b1cadd8208975
4
+ data.tar.gz: f7f3a91c00935e287659ef302c8dedc8f6b822cf
5
+ SHA512:
6
+ metadata.gz: 92a03d143a91e0f0976059c899f181e56bbbce3a30dc2f214099572a42fc40bbb6453eafe0a3f8c3acd0a28612d579d88548121b4c314fc6040d41f4f4ed2bd9
7
+ data.tar.gz: 090bd46a2b62bb0130d3f2ad821e0c9cef02d4d4a97b1059f66e94bcc10743e2a93e1aa720333150533c714c489d8d6c6a561ce6911ae58f3e99e5d690ee5287
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bundler-squash.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Akira Matsuda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ # bundler-squash
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bundler-squash`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+
8
+ ## Installation
9
+
10
+ % gem install bundler-squash
11
+
12
+
13
+ ## Usage
14
+
15
+ % bundle squash
16
+
17
+
18
+ ## Contributing
19
+
20
+ Pull requests are welcome on GitHub at https://github.com/amatsuda/bundler-squash.
21
+
22
+
23
+ ## License
24
+
25
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bundler-squash"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bundler-squash/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bundler-squash"
8
+ spec.version = Bundler::Squash::VERSION
9
+ spec.authors = ["Akira Matsuda"]
10
+ spec.email = ["ronnie@dio.jp"]
11
+
12
+ spec.summary = 'bundle squash'
13
+ spec.description = 'bundle squash'
14
+ spec.homepage = 'https://github.com/amatsuda/bundle_squash'
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler-squash'
4
+ Bundler::Squash.run
@@ -0,0 +1,176 @@
1
+ require "bundler-squash/version"
2
+ require 'fileutils'
3
+ require 'find'
4
+ require 'bundler'
5
+
6
+ module Bundler; class Squash
7
+ DEST = './vendor/bundler-squash'
8
+ SKIP_GEMS = ['rake',
9
+ 'sqlite3', 'pg', 'mysql2', # AR calls `gem` method for them
10
+ 'haml', 'sass' # they read files outside of lib directory
11
+ ]
12
+
13
+ def self.run
14
+ b = self.new
15
+ b.bundler_dependencies_to_specs
16
+ b.cleanup
17
+ b.cp_r
18
+ b.write_gemspecs
19
+ b.write_require_files
20
+ b.generate_gemfile
21
+ b.install
22
+ end
23
+
24
+ def initialize
25
+ @skipped_gems = []
26
+ bundler = Bundler.setup
27
+ bundler.require
28
+ @definition = bundler.instance_variable_get(:@definition)
29
+ @definition.resolve
30
+ @copied_specs = {}
31
+ end
32
+
33
+ def bundler_dependencies_to_specs
34
+ @specs = {}
35
+ @specs[:default] = @definition.specs_for([:default])
36
+ @definition.groups.each do |group|
37
+ @specs[group] = Bundler::SpecSet.new(@definition.specs_for([group]).to_a - @specs[:default].to_a) unless group == :default
38
+ end
39
+ end
40
+
41
+ def cleanup
42
+ FileUtils.rm_r DEST if File.exists? DEST
43
+ FileUtils.mkdir_p DEST
44
+ end
45
+
46
+ def cp_r
47
+ $LOAD_PATH.grep(%r{/lib$}).sort.select {|lp| FileTest.directory? lp}.select do |lp|
48
+ gem = gemname(lp)
49
+ if SKIP_GEMS.include?(gem) || File.exists?("#{lp}/../VERSION") # gems that have VERSION file would possibly load this file in .rb
50
+ puts "skipping #{gem} ..."
51
+ @skipped_gems << gem
52
+ next
53
+ end
54
+ puts "copying #{lp} ..."
55
+
56
+ @specs.each_pair do |group, specs|
57
+ FileUtils.mkdir_p "#{DEST}/#{group}/lib"
58
+ if (spec = specs.detect {|d| d.name == gem})
59
+ if (overlaps = (files_in(lp) & bundled_files_for(group))).any?
60
+ if (same_filenames = overlaps.select {|f| !FileUtils.cmp "#{lp}#{f}", "#{DEST}/#{group}/lib#{f}"}).any?
61
+ puts "skipping #{lp}: these files already exist!\n #{same_filenames.inspect}"
62
+ @skipped_gems << gem
63
+ next
64
+ end
65
+ end
66
+ `rsync -a --exclude=.git #{lp} #{DEST}/#{group}`
67
+ #TODO overwrite check?
68
+ %w(data vendor frameworks ui).each do |dir|
69
+ FileUtils.cp_r "#{lp}/../#{dir}", "#{DEST}/#{group}" if File.exists?("#{lp}/../#{dir}")
70
+ end
71
+ (@copied_specs[group] ||= []) << spec
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ def write_gemspecs
78
+ @copied_specs.keys.each do |group|
79
+ File.open("#{DEST}/#{group}/bundler-squash-#{group}.gemspec", 'w') {|f| f.write <<-GEMSPEC }
80
+ # frozen_string_literal: true
81
+ lib = File.expand_path('../lib', __FILE__)
82
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
83
+
84
+ Gem::Specification.new do |gem|
85
+ gem.name = 'bundler-squash-#{group}'
86
+ gem.version = '0'
87
+ gem.summary = gem.authors = ''
88
+ gem.require_paths = ['lib']
89
+ end
90
+ GEMSPEC
91
+ end
92
+ end
93
+
94
+ def write_require_files
95
+ @specs.each_pair do |group, specs|
96
+ requires = specs.map {|s| require_string(s).map {|r| "require '#{r}'"}}.flatten.join("\n")
97
+ File.open("#{DEST}/#{group}/lib/bundler-squash-#{group}.rb", 'w') {|f| f.write requires + "\n"}
98
+ end
99
+ end
100
+
101
+ def require_string(spec)
102
+ ret = Array(spec.respond_to?(:autorequire) ? spec.autorequire : [])
103
+ return ret if ret.any?
104
+
105
+ begin
106
+ Kernel.require spec.name
107
+ ret << spec.name
108
+ rescue LoadError
109
+ if spec.name.include?('-')
110
+ namespaced_file = spec.name.gsub('-', '/')
111
+ begin
112
+ Kernel.require namespaced_file
113
+ ret << namespaced_file
114
+ rescue LoadError
115
+ end
116
+ end
117
+ end
118
+ ret
119
+ end
120
+
121
+ def generate_gemfile
122
+ puts; puts 'writing Gemfile.squash...'
123
+ original_gemfile = File.read('Gemfile').lines
124
+ File.open('Gemfile.squash', 'w') do |gemfile|
125
+ gemfile.write *original_gemfile.grep(/^\s*source\s+/)
126
+ @copied_specs.keys.each do |group|
127
+ gemfile.write "gem 'bundler-squash-#{group}', path: '#{DEST}/#{group}'"
128
+ gemfile.write ", group: :#{group}" unless group == [:default]
129
+ gemfile.write "\n"
130
+ end
131
+ original_gemfile.grep(/^\s*gem\s*['"]rails['"]/).each do |line|
132
+ gemfile.write line.sub('rails', 'railties')
133
+ end
134
+
135
+ gemfile.write "\n" if @skipped_gems.any?
136
+ @skipped_gems.each do |gem|
137
+ if (orig = original_gemfile.grep(/^\s*gem\s*['"]#{gem}['"]/)).any?
138
+ orig.each do |line|
139
+ groups_string = groups_string_for gem
140
+ gemfile.write "#{line.gsub(/^ */, '').chomp}#{", group: #{groups_string}" if groups_string}\n"
141
+ end
142
+ else
143
+ groups_string = groups_string_for gem
144
+ gemfile.write "gem '#{gem}'#{", group: #{groups_string}" if groups_string}\n"
145
+ end
146
+ end
147
+ end
148
+ end
149
+
150
+ def install
151
+ puts; puts `export BUNDLE_GEMFILE=Gemfile.squash && bundle`
152
+ end
153
+
154
+ private
155
+ def files_in(dir)
156
+ Find.find(dir).select {|e| FileTest.file? e}.reject {|f| f.include?('/.git/')}.map {|f| f.sub(%r{^#{dir}}, '')}
157
+ end
158
+
159
+ def bundled_files_for(group)
160
+ files_in "#{DEST}/#{group}/lib"
161
+ end
162
+
163
+ def gemname(filename)
164
+ filename.match(%r{.*/(.*)-.*/lib}) { $1 }
165
+ end
166
+
167
+ def groups_string_for(gemname)
168
+ return if @specs[:default][gemname].any?
169
+ groups = @specs.keys.select {|k| @specs[k][gemname].any?}
170
+ if groups.one?
171
+ groups.first.inspect
172
+ elsif groups.any?
173
+ groups.inspect
174
+ end
175
+ end
176
+ end; end
@@ -0,0 +1,5 @@
1
+ module Bundler
2
+ class Squash
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bundler-squash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Akira Matsuda
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: bundle squash
56
+ email:
57
+ - ronnie@dio.jp
58
+ executables:
59
+ - bundler-squash
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - bundler-squash.gemspec
72
+ - exe/bundler-squash
73
+ - lib/bundler-squash.rb
74
+ - lib/bundler-squash/version.rb
75
+ homepage: https://github.com/amatsuda/bundle_squash
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.6.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: bundle squash
99
+ test_files: []