Add install_sync_fgu.rb

This commit is contained in:
邱博亞 2024-01-25 08:19:28 +08:00
parent abb87a6952
commit 8d42afd6f0
1 changed files with 57 additions and 0 deletions

57
install_sync_fgu.rb Normal file
View File

@ -0,0 +1,57 @@
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