2017-09-08 04:45:41 -04:00
|
|
|
# frozen_string_literal: true
|
2017-11-01 19:29:38 -04:00
|
|
|
|
2017-09-08 04:45:41 -04:00
|
|
|
module Bundler
|
|
|
|
class CLI::Init
|
|
|
|
attr_reader :options
|
|
|
|
def initialize(options)
|
|
|
|
@options = options
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
2017-11-01 19:29:38 -04:00
|
|
|
if File.exist?(gemfile)
|
|
|
|
Bundler.ui.error "#{gemfile} already exists at #{File.expand_path(gemfile)}"
|
2017-09-08 04:45:41 -04:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if options[:gemspec]
|
|
|
|
gemspec = File.expand_path(options[:gemspec])
|
|
|
|
unless File.exist?(gemspec)
|
|
|
|
Bundler.ui.error "Gem specification #{gemspec} doesn't exist"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
spec = Bundler.load_gemspec_uncached(gemspec)
|
|
|
|
|
2017-11-01 19:29:38 -04:00
|
|
|
File.open(gemfile, "wb") do |file|
|
2017-09-08 04:45:41 -04:00
|
|
|
file << "# Generated from #{gemspec}\n"
|
|
|
|
file << spec.to_gemfile
|
|
|
|
end
|
|
|
|
else
|
2017-11-01 19:29:38 -04:00
|
|
|
FileUtils.cp(File.expand_path("../../templates/#{gemfile}", __FILE__), gemfile)
|
|
|
|
end
|
|
|
|
|
|
|
|
puts "Writing new #{gemfile} to #{SharedHelpers.pwd}/#{gemfile}"
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def gemfile
|
2017-12-12 01:15:44 -05:00
|
|
|
@gemfile ||= Bundler.feature_flag.init_gems_rb? ? "gems.rb" : "Gemfile"
|
2017-09-08 04:45:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|