Class: Jets::Builders::GemReplacer
- Inherits:
-
Object
- Object
- Jets::Builders::GemReplacer
- Extended by:
- Memoist
- Includes:
- Util
- Defined in:
- lib/jets/builders/gem_replacer.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ GemReplacer
constructor
A new instance of GemReplacer.
- #rename_gem(gem_name) ⇒ Object
- #ruby_folder ⇒ Object
- #run ⇒ Object
-
#tidy ⇒ Object
remove unnecessary files to reduce package size.
-
#tidy_gem(path) ⇒ Object
Clean up some unneeded files to try to keep the package size down In a generated jets app this made a decent 9% difference: 175M test2 191M test3.
- #tidy_gems(gems_path) ⇒ Object
Constructor Details
#initialize(options) ⇒ GemReplacer
Returns a new instance of GemReplacer.
6 7 8 |
# File 'lib/jets/builders/gem_replacer.rb', line 6 def initialize() @options = end |
Instance Method Details
#rename_gem(gem_name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jets/builders/gem_replacer.rb', line 31 def rename_gem(gem_name) ruby_folder = "#{Jets.build_root}/stage/opt/ruby/gems/#{Jets::Gems.ruby_folder}" gems_folder = "#{ruby_folder}/gems" expr = "#{gems_folder}/#{gem_name}-x*-{darwin,linux}" src = Dir.glob(expr).first return unless src dest = src.sub("-darwin", "-linux") FileUtils.mv(src, dest) unless File.exist?(dest) # looks like rename_gem actually runs twice end |
#ruby_folder ⇒ Object
42 43 44 |
# File 'lib/jets/builders/gem_replacer.rb', line 42 def ruby_folder Jets::Gems.ruby_folder end |
#run ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jets/builders/gem_replacer.rb', line 10 def run # use_gemspec to resolve http-parser gem issue use_gemspec = !Jets::Turbo.afterburner? # gemspec approach breaks afterburner mode check = Jets::Gems::Check.new(use_gemspec: use_gemspec) if Jets.config.lambda.layers.empty? found_gems = check.run! # exits early if missing gems found else # assumes missing gems are in the provided custom layer by the user found_gems = check.run # does not exist early end # found gems will only have gems that were found found_gems.each do |gem_name| gem_extractor = Jets::Gems::Extract::Gem.new(gem_name, @options) gem_extractor.run rename_gem(gem_name) end tidy end |
#tidy ⇒ Object
remove unnecessary files to reduce package size
47 48 49 50 51 52 |
# File 'lib/jets/builders/gem_replacer.rb', line 47 def tidy # project_root: /tmp/jets/demo/stage/code/ # /tmp/jets/demo/stage/code/bundled tidy_gems("#{@options[:project_root]}/ruby/gems/#{ruby_folder}/*/gems/*") tidy_gems("#{@options[:project_root]}/ruby/gems/#{ruby_folder}/*/bundler/gems/*") end |
#tidy_gem(path) ⇒ Object
Clean up some unneeded files to try to keep the package size down In a generated jets app this made a decent 9% difference:
175M test2
191M test3
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/jets/builders/gem_replacer.rb', line 64 def tidy_gem(path) # remove top level tests and cache folders Dir.glob("#{path}/*").each do |path| next unless File.directory?(path) folder = File.basename(path) if %w[test tests spec features benchmark cache doc].include?(folder) FileUtils.rm_rf(path) end end Dir.glob("#{path}/**/*").each do |path| next unless File.file?(path) ext = File.extname(path) if %w[.rdoc .md .markdown].include?(ext) or path =~ /LICENSE|CHANGELOG|README/ FileUtils.rm_f(path) end end end |
#tidy_gems(gems_path) ⇒ Object
54 55 56 57 58 |
# File 'lib/jets/builders/gem_replacer.rb', line 54 def tidy_gems(gems_path) Dir.glob(gems_path).each do |gem_path| tidy_gem(gem_path) end end |