announcement-test/announcement.gemspec

176 lines
7.9 KiB
Ruby
Raw Permalink Normal View History

2020-04-05 14:38:26 +00:00
# encoding: UTF-8
2014-04-01 07:12:43 +00:00
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "announcement/version"
2020-02-17 13:50:15 +00:00
env_pwd = ENV['PWD']
2020-02-14 14:31:52 +00:00
app_path = File.expand_path(__dir__)
2020-02-17 13:50:15 +00:00
template_path = env_pwd + '/app/templates'
2020-02-14 14:31:52 +00:00
all_template = Dir.glob(template_path+'/*/')
puts 'editing files for sassc'
new_gemfile_text = File.read(app_path+'/temp_file/Gemfile')
2020-02-17 13:50:15 +00:00
old_gemfile_text = File.read(env_pwd+'/Gemfile')
2020-02-27 07:11:46 +00:00
check_texts = ['@import "../../bootstrap/variables";',".response-content {\n justify-self: auto;\n}\n"]
2020-04-14 08:54:23 +00:00
git_url = Bundler.with_clean_env{%x[cd '#{env_pwd}' && git config --get remote.origin.url].split("\n")[0]}
git_remote = Bundler.with_clean_env{%x[cd '#{env_pwd}' && git remote].split("\n")[0]}
if git_url != 'http://ruling.digital/git'
2020-02-16 03:17:52 +00:00
puts 'changing remote url'
Bundler.with_clean_env{system("cd #{env_pwd} && git remote set-url #{git_remote} http://ruling.digital/git")}
2020-02-16 03:17:52 +00:00
end
2020-02-14 14:31:52 +00:00
all_template.each do |folder|
if !folder.include?('mobile')
begin
if folder.split('/')[-1] != 'mobile'
2020-02-26 02:43:06 +00:00
unity_text = File.open(folder+'assets/stylesheets/template/base/_unity.scss','r:UTF-8') do |f|
f.read
end rescue ''
2020-02-25 13:08:08 +00:00
if unity_text.split(/\n/).join.strip.empty?
File.open(folder+'assets/stylesheets/template/base/_unity.scss', 'a') do |file|
file.puts "@charset \"utf-8\";\n\n@import \"variables\";\n\n// Title\n.unity-title {\n margin: 0.5em 0;\n line-height: 1.5;\n font-family: $main-font;\n font-size: $font-h1;\n\n .layout-footer & {\n margin-bottom: 10px;\n border-bottom: none;\n\n span {\n display: inline;\n margin-bottom: 0;\n border-bottom: none;\n }\n }\n}\n\n.status {\n font-family: $main-font;\n font-size: 0.75rem;\n}\n\n.status-top {\n background-color: $theme-color-second;\n}\n\n.status-hot {\n background-color: $theme-color-third;\n}\n\n.status-source {\n background-color: $theme-color-main;\n\n a {\n color: $theme-white;\n }\n}\n"
end
end
2020-02-17 13:50:15 +00:00
filename = folder+'assets/stylesheets/template/base/_variables.scss'
2020-02-26 02:43:06 +00:00
texts = File.open(filename,'r:UTF-8') do |f|
f.read
2020-04-05 14:38:26 +00:00
end.force_encoding('UTF-8')
2020-02-26 11:46:51 +00:00
s1 = texts.scan(/{|}/)
if s1.count % 2 != 0
i = texts.rindex(s1[-1])
2020-02-26 14:36:50 +00:00
texts[i] = ""
2020-02-26 11:46:51 +00:00
end
2020-05-06 05:54:09 +00:00
regex_pattern = /.response-content {\n justify-self: auto;\n}|.response-content {\n position: static;\n}|.response-content {\n position: relative;\n}/m #|.response-content[^{]*{[^}]*@media[^{]*{[^{]*}[^{]*@media[^{]*{[^{]*}[^}]*}[^}]*}
2020-02-25 13:08:08 +00:00
if !texts.include? "$font-h1:"
2020-02-25 15:53:33 +00:00
texts = "$font-h1: 1.5rem;\n$font-h2: 1.35rem;\n$font-h3: 1.2rem;\n$font-h4: 1.1rem;\n$font-h5: 1rem;\n$font-h6: 0.9rem;\n\n" + texts
2020-02-25 13:08:08 +00:00
end
if !texts.include? "$main-font:"
2020-02-25 15:53:33 +00:00
texts = "$main-font: Arial, \"微軟正黑體\", \"Helvetica Neue\", Helvetica, sans-serif;\n" + texts
2020-02-25 13:08:08 +00:00
end
if !texts.include? "$theme-white"
texts = "$theme-white: #fff;\n" + texts
end
2020-02-25 15:35:34 +00:00
File.open(filename,'w') do |f|
f.write texts
end
2020-04-05 14:38:26 +00:00
tp_text = File.read(folder+'assets/stylesheets/template/template.scss').force_encoding('UTF-8') rescue ''
2020-02-25 13:08:08 +00:00
tp_last_text = tp_text
tp_text.scan(/@import.*http.*;/).each do |pat|
if pat.scan(/@import\W+url/).count==0
pat1 = pat.sub(/@import\W/,"@import url(")
pat1 = pat1.sub(/;/,");")
tp_last_text = tp_last_text.sub(pat,pat1)
end
end
if tp_last_text != tp_text
File.open(folder+'assets/stylesheets/template/template.scss','w') do |f|
f.write tp_last_text
end
end
2020-02-26 14:42:59 +00:00
if texts.split(regex_pattern).count >= 1
2020-02-25 13:08:08 +00:00
auto_save_text = texts.scan(regex_pattern).join('')
File.open(folder+'assets/stylesheets/template/base/_autobackup.bak', 'a') do |file|
file.puts auto_save_text
end
File.open(filename, 'w') do |file|
2020-02-26 14:46:29 +00:00
file.write (texts.split(regex_pattern).join('') + check_texts[1])
2020-02-25 13:08:08 +00:00
end
else
check_texts.each do |check_text|
if !texts.include?(check_text)
puts "editing #{folder}assets/stylesheets/template/base/_variables.scss"
2020-05-06 05:54:09 +00:00
texts = texts + check_text
File.open(filename, 'w') do |file|
2020-05-06 05:54:09 +00:00
file.write(texts)
2020-02-25 13:08:08 +00:00
end
2020-02-14 14:31:52 +00:00
end
end
end
end
rescue => e
puts "not found #{folder}assets/stylesheets/template/base/_variables.scss"
end
end
end
if old_gemfile_text != new_gemfile_text
2020-02-14 15:19:35 +00:00
unicorn_rails = %x[which unicorn_rails].sub("\n",'')
2020-02-14 14:31:52 +00:00
puts 'updating gemfile'
2020-02-17 13:50:15 +00:00
Bundler.with_clean_env{%x[cp -f '#{env_pwd}'/Gemfile '#{env_pwd}'/Gemfile.bak123]}
Bundler.with_clean_env{%x[cp -f '#{app_path}'/temp_file/Gemfile '#{env_pwd}'/Gemfile]}
2020-02-17 14:29:39 +00:00
command4 = "cp -rf #{app_path}/temp_file/app #{env_pwd}"
2020-02-17 13:50:15 +00:00
log_development = File.mtime(env_pwd+'/log/development.log').strftime('%Y%m%d%H%M').to_i rescue 0
log_production = File.mtime(env_pwd+'/log/production.log').strftime('%Y%m%d%H%M').to_i rescue 0
2020-02-14 14:31:52 +00:00
if log_development > log_production
mode = 'development'
else
mode = 'production'
end
2020-02-17 13:50:15 +00:00
files = Dir[env_pwd+'/Gemfile.lock']
dir_name = env_pwd.split('/')[-1]
watch_dog = %x[screen -ls auto_reopen_#{dir_name}]
if watch_dog.scan("auto_reopen_#{dir_name}").count != 0
Bundler.with_clean_env{%x[screen -ls | grep auto_reopen_#{dir_name} | cut -d. -f1 | awk '{print $1}' | xargs kill]}
end
if %x[ruby -v].scan(/\d\.\d\.\d/)[0] == '2.1.3'
2020-02-26 01:22:55 +00:00
install_cmd = 'rvm install 2.1.10 && rvm use default 2.1.10;'
use_cmd = 'source ~/.rvm/scripts/rvm && rvm use 2.1.10 --default;'
else
install_cmd = ''
use_cmd = ''
end
2020-02-26 02:22:45 +00:00
#if files.count ==0
# command1 = "gem install bundler -v 1.17.3 ; bundle update --all"
#else
command1 = "gem install bundler -v 1.17.3 ; bundle update --all"
#end
filedata = File.read(env_pwd+"/built_in_extensions.rb")
exist_str = "gem 'patchfile', git: 'http://gitlab.tp.rulingcom.com/chiu/patch_file.git'"
if filedata.include? exist_str
puts "patchfile exist"
else
file = env_pwd+"/built_in_extensions.rb"
open(file, 'a') { |f|
f.puts exist_str
}
end
2020-02-26 02:43:06 +00:00
all_command = "#{install_cmd} #{command1} ; #{command4} "
2020-02-26 10:24:22 +00:00
watch_dog_cmd = "watch -n 30 \'unset UNICORN_FD && bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode}\'"
#file = File.new(File.join(env_pwd,'bundle_update_background.sh'),"w")
#file.write(all_command)
#file.chmod(0755)
#file.close
2020-02-14 14:31:52 +00:00
a = Thread.start do
Bundler.with_clean_env do
2020-02-17 13:50:15 +00:00
puts env_pwd
2020-02-14 14:31:52 +00:00
puts mode
exec("cd #{env_pwd} && env -i HOME=\"$HOME\" bash -l -c \"#{all_command}\" ;screen -d -m -S auto_reopen_#{dir_name} bash -c \"#{use_cmd} kill -s TERM `cat tmp/pids/unicorn.pid` ; unset UNICORN_FD ; bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode};#{watch_dog_cmd}\" ")
2020-02-14 14:31:52 +00:00
end
end
2020-02-15 02:22:57 +00:00
now_priority = Thread.current.priority.to_i
system('sleep 2')
a.priority = now_priority + 2
2020-02-14 14:31:52 +00:00
a.run
#Thread.exit
2020-02-26 02:43:06 +00:00
else
dir_name = env_pwd.split('/')[-1]
watch_dog = %x[screen -ls auto_reopen_#{dir_name}]
if watch_dog.scan("auto_reopen_#{dir_name}").count != 0
Bundler.with_clean_env{%x[screen -ls | grep auto_reopen_#{dir_name} | cut -d. -f1 | awk '{print $1}' | xargs kill]}
end
2020-02-26 02:43:06 +00:00
system("cp -rf #{app_path}/temp_file/app #{env_pwd}")
2020-02-14 14:31:52 +00:00
end
2014-04-01 07:12:43 +00:00
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "announcement"
s.version = Announcement::VERSION
s.authors = ["RulingDigital"]
s.email = ["orbit@rulingcom.com"]
s.homepage = "http://www.rulingcom.com"
s.summary = "Announcements for Orbit"
s.description = "Announcements for Orbit"
s.license = "MIT"
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
s.add_dependency "rufus-scheduler", "~> 3.6.0"
2014-04-01 07:12:43 +00:00
end