2021-07-27 08:31:45 +00:00
|
|
|
$:.push File.expand_path("lib", __dir__)
|
|
|
|
|
|
|
|
# Maintain your gem's version:
|
|
|
|
require "ruling_weather/version"
|
|
|
|
bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
|
|
|
|
if bundle_update_flag
|
|
|
|
env_pwd = ENV['PWD']
|
|
|
|
app_path = File.expand_path(__dir__)
|
|
|
|
template_path = env_pwd + '/app/templates'
|
|
|
|
all_template = Dir.glob(template_path+'/*/')
|
2021-12-08 10:21:08 +00:00
|
|
|
default_weather_widget_info = JSON.parse(File.read("#{app_path}/modules/ruling_weather/info.json"))["widgets"].sort_by{|h| h["filename"].to_i} rescue []
|
2021-07-27 08:31:45 +00:00
|
|
|
all_template.each do |folder|
|
|
|
|
if !folder.include?('mobile')
|
|
|
|
moudle_path = "#{folder}modules/ruling_weather/"
|
2021-12-08 10:21:08 +00:00
|
|
|
if Dir.exist?(File.dirname(moudle_path))
|
|
|
|
if !Dir.exist?(moudle_path)
|
|
|
|
Bundler.with_clean_env{system ('cp -r '+ app_path + '/modules/* ' + folder + '/modules/.')}
|
|
|
|
else
|
|
|
|
info_json_file = "#{moudle_path}info.json"
|
|
|
|
if File.exist?(info_json_file)
|
|
|
|
begin
|
|
|
|
file_text = File.read(info_json_file) rescue ""
|
|
|
|
encode_file_text = file_text.encode("UTF-8", "UTF-8", invalid: :replace, replace: "???")
|
|
|
|
next if (encode_file_text.include?("???") rescue true)
|
|
|
|
info = JSON.parse(encode_file_text) rescue {}
|
|
|
|
flag = (info.count != 0 rescue false)
|
|
|
|
if flag
|
|
|
|
puts "Checking RulingWeather widgets"
|
|
|
|
widget_info = info["widgets"].sort_by{|h| h["filename"].to_i} rescue []
|
|
|
|
update_flag = false
|
|
|
|
last_index = widget_info[-1]["filename"].match(/\d+/)[0].to_i rescue nil
|
|
|
|
if !last_index.nil?
|
|
|
|
idx_regex = /^(\d+[\. \t]*)|[ \t]+$/
|
|
|
|
default_weather_widget_info.each do |h|
|
|
|
|
name_without_index = h["name"]["zh_tw"].gsub(idx_regex,'')
|
|
|
|
widget_info_index = (widget_info.index{|hh| hh["name"]["zh_tw"].gsub(idx_regex,'') == name_without_index}||-1 rescue -1)
|
|
|
|
if (widget_info_index == -1 || widget_info_index.nil?)
|
|
|
|
update_flag = true
|
|
|
|
copy_h = h.dup
|
|
|
|
h.delete("force_cover")
|
|
|
|
last_index = last_index + 1
|
|
|
|
copy_h["filename"] = copy_h["filename"].sub(/\d+/){|ff| last_index.to_s}
|
|
|
|
copy_h["name"].keys.each do |locale|
|
|
|
|
copy_h["name"][locale] = copy_h["name"][locale].sub(/\d+/){|ff| last_index.to_s}
|
|
|
|
end
|
|
|
|
widget_info << copy_h
|
|
|
|
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/ruling_weather/_#{h["filename"]}.html.erb #{folder}modules/ruling_weather/_#{copy_h["filename"]}.html.erb]}
|
|
|
|
elsif h["force_cover"] == "true"
|
|
|
|
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/ruling_weather/_#{h["filename"]}.html.erb #{folder}modules/ruling_weather/_#{widget_info[widget_info_index]["filename"]}.html.erb]}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if update_flag
|
|
|
|
info["widgets"] = widget_info
|
|
|
|
puts "Writing json #{info["widgets"].count} in #{info_json_file}"
|
|
|
|
begin
|
|
|
|
info_json = JSON.pretty_generate(info).gsub(":[",":[\n").gsub(":{",":{\n")
|
|
|
|
rescue
|
|
|
|
info_json = info.to_s.gsub("=>",": \n")
|
|
|
|
end
|
|
|
|
File.open(info_json_file,"w+"){|f| f.write(info_json)}
|
|
|
|
end
|
|
|
|
Bundler.with_clean_env{%x[cp -rn #{app_path}/modules/ruling_weather/thumbs/* #{folder}modules/ruling_weather/thumbs/.]}
|
|
|
|
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/ruling_weather/thumbs/weather1_thumbs.png #{folder}modules/ruling_weather/thumbs/.]}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue => e
|
|
|
|
puts e
|
|
|
|
puts "There has some error when checking RulingWeather widgets"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-07-27 08:31:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# Describe your gem and declare its dependencies:
|
|
|
|
Gem::Specification.new do |spec|
|
|
|
|
spec.name = "ruling_weather"
|
|
|
|
spec.version = RulingWeather::VERSION
|
|
|
|
spec.authors = ["Bohung Chiu"]
|
|
|
|
spec.email = ["bohung@rulingcom.com"]
|
|
|
|
spec.homepage = "https://w3.rulingcom.com/"
|
|
|
|
spec.summary = "Ruling Weather"
|
|
|
|
spec.description = "Ruling Weather"
|
|
|
|
spec.license = "MIT"
|
|
|
|
spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
|
|
|
|
end
|