Last active
June 15, 2017 00:38
-
-
Save sho-h/c0632f26a60b0cda2fd7d74d023a9d4f to your computer and use it in GitHub Desktop.
gemify redmine plugins.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins = [ | |
['redmine_audit'], | |
# ['foo', '>= 1.0.0'], | |
# ... | |
] | |
Gem.post_install do |installer| | |
require 'rubygems/user_interaction' | |
suffix = '.from_gemfile' | |
gem_name = installer.spec.name | |
# symlink plubins/<gemname> from bundle installed gem. | |
plugin_names = plugins.map {|pl| pl.first } | |
if plugin_names.include?(gem_name) | |
# TODO: use Redmine::Plugin.directory and branch by Redmine version. | |
path = File.join(Bundler.root, 'plugins', gem_name + suffix) | |
if !File.exists?(path) | |
ui = Gem::DefaultUserInteraction.ui | |
ui.say 'Creating symlink to plugins directory.' | |
File.symlink(installer.gem_dir, path) | |
end | |
end | |
# delete unused symlinks. | |
pattern = File.join(Bundler.root, 'plugins', "*#{suffix}") | |
Dir.glob(pattern) do |path| | |
orig_gem_name = File.basename(path).gsub(/#{Regexp.escape(suffix)}/, '') | |
if !plugin_names.include?(orig_gem_name) && File.symlink?(path) | |
File.unlink(path) | |
end | |
end | |
end | |
plugins.each do |args| | |
gem *args | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment