2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-10 06:10:14 +08:00
|
|
|
module PluginGem
|
|
|
|
def self.load(path, name, version, opts = nil)
|
|
|
|
opts ||= {}
|
|
|
|
|
|
|
|
gems_path = File.dirname(path) + "/gems/#{RUBY_VERSION}"
|
2021-04-16 16:21:39 +08:00
|
|
|
|
2017-01-10 06:10:14 +08:00
|
|
|
spec_path = gems_path + "/specifications"
|
2021-04-16 16:21:39 +08:00
|
|
|
|
|
|
|
spec_file = spec_path + "/#{name}-#{version}"
|
2020-08-31 10:36:04 +08:00
|
|
|
spec_file += "-#{opts[:platform]}" if opts[:platform]
|
|
|
|
spec_file += ".gemspec"
|
2021-04-16 16:21:39 +08:00
|
|
|
|
2022-01-06 01:45:08 +08:00
|
|
|
unless File.exist? spec_file
|
2021-04-16 16:21:39 +08:00
|
|
|
command = "gem install #{name} -v #{version} -i #{gems_path} --no-document --ignore-dependencies --no-user-install"
|
|
|
|
command += " --source #{opts[:source]}" if opts[:source]
|
2017-01-10 06:10:14 +08:00
|
|
|
puts command
|
2022-03-07 13:20:43 +08:00
|
|
|
|
|
|
|
Bundler.with_unbundled_env do
|
|
|
|
puts `#{command}`
|
|
|
|
end
|
2017-01-10 06:10:14 +08:00
|
|
|
end
|
2021-04-16 16:21:39 +08:00
|
|
|
|
2022-01-06 01:45:08 +08:00
|
|
|
if File.exist? spec_file
|
2021-04-16 16:21:39 +08:00
|
|
|
Gem.path << gems_path
|
|
|
|
Gem::Specification.load(spec_file).activate
|
|
|
|
|
2017-01-10 06:10:14 +08:00
|
|
|
unless opts[:require] == false
|
|
|
|
require opts[:require_name] ? opts[:require_name] : name
|
|
|
|
end
|
|
|
|
else
|
|
|
|
puts "You are specifying the gem #{name} in #{path}, however it does not exist!"
|
2017-08-03 02:00:18 +08:00
|
|
|
puts "Looked for: #{spec_file}"
|
2017-01-10 06:10:14 +08:00
|
|
|
exit(-1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|