Method: Bundler::Installer#generate_standalone_bundler_executable_stubs

Defined in:
lib/bundler/installer.rb

#generate_standalone_bundler_executable_stubs(spec, options = {}) ⇒ Object


158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/bundler/installer.rb', line 158

def generate_standalone_bundler_executable_stubs(spec, options = {})
  # double-assignment to avoid warnings about variables that will be used by ERB
  bin_path = Bundler.bin_path
  unless path = Bundler.settings[:path]
    raise "Can't standalone without an explicit path set"
  end
  standalone_path = Bundler.root.join(path).relative_path_from(bin_path)
  standalone_path = standalone_path
  template = File.read(File.expand_path("templates/Executable.standalone", __dir__))
  ruby_command = Thor::Util.ruby_command
  ruby_command = ruby_command

  spec.executables.each do |executable|
    next if executable == "bundle"
    executable_path = Pathname(spec.full_gem_path).join(spec.bindir, executable).relative_path_from(bin_path)
    executable_path = executable_path

    mode = Gem.win_platform? ? "wb:UTF-8" : "w"
    require "erb"
    content = ERB.new(template, trim_mode: "-").result(binding)

    File.write("#{bin_path}/#{executable}", content, mode: mode, perm: 0o755)
    if Gem.win_platform? || options[:all_platforms]
      prefix = "@ruby -x \"%~f0\" %*\n@exit /b %ERRORLEVEL%\n\n"
      File.write("#{bin_path}/#{executable}.cmd", prefix + content, mode: mode)
    end
  end
end