57 lines
2.0 KiB
Ruby
57 lines
2.0 KiB
Ruby
|
def delete_plugin(extention_file,plugin_name)
|
||
|
txt = File.read(extention_file) rescue nil
|
||
|
return if txt.nil?
|
||
|
txt_change = txt.gsub(/^[\n]*gem\s*["']#{plugin_name}["'].*\n/,'')
|
||
|
if txt_change != txt
|
||
|
File.open(extention_file,'w+') do |f|
|
||
|
f.write(txt_change)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def add_plugin(extention_file,plugin_name, git_url)
|
||
|
txt = File.read(extention_file) rescue nil
|
||
|
if txt.nil?
|
||
|
File.open(extention_file,'w+'){|f| f.write("")}
|
||
|
txt = ""
|
||
|
end
|
||
|
txt_scan = txt.scan(/^[\n]*gem\s*["']#{plugin_name}["'].*\n/)
|
||
|
if txt_scan.count != 1
|
||
|
delete_plugin(extention_file,plugin_name)
|
||
|
txt = File.read(extention_file) rescue ""
|
||
|
txt = txt + "\ngem \"#{plugin_name}\", git: \"#{git_url}\"\n"
|
||
|
File.open(extention_file,'w+') do |f|
|
||
|
f.write(txt)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
plugins = {"sync_fgu_personal_data" => "http://gitlab.tp.rulingcom.com/chiu/sync_personal_data_task_for_fgu.git",
|
||
|
"personal_activity" => "http://gitlab.tp.rulingcom.com/fgu/personal_activity.git",
|
||
|
"personal_project" => "http://gitlab.tp.rulingcom.com/fgu/personal_project.git",
|
||
|
"personal_patent" => "http://gitlab.tp.rulingcom.com/fgu/personal_patent.git",
|
||
|
"personal_honor" => "http://gitlab.tp.rulingcom.com/fgu/personal_honor.git",
|
||
|
"personal_certificate" => "http://gitlab.tp.rulingcom.com/fgu/personal_certificate.git"}
|
||
|
|
||
|
|
||
|
a = Dir.glob('../*/')
|
||
|
a.each do |d|
|
||
|
Dir.chdir(d) do
|
||
|
full_dir = Pathname.new(File.expand_path(Rails.root.to_s, d))
|
||
|
Rails.configuration.instance_variable_set(:@root, full_dir)
|
||
|
plugins.each do |plugin, git_url|
|
||
|
delete_plugin('built_in_extensions.rb', plugin)
|
||
|
add_plugin('downloaded_extensions.rb', plugin, git_url)
|
||
|
end
|
||
|
Bundler.with_clean_env { system("cd #{full_dir} && bundle update") }
|
||
|
templates = Dir.glob('app/templates/*/')
|
||
|
plugins.each do |plugin, git_url|
|
||
|
puts "copy modules: #{plugin}"
|
||
|
x = `bundle show #{plugin}`.strip
|
||
|
if x.present?
|
||
|
templates.each do |template|
|
||
|
`cp -rf #{x}/modules/* #{full_dir}/#{template}modules/.`
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|