2017-12-30 05:57:06 +08:00
|
|
|
if ARGV.empty?
|
|
|
|
puts 'Usage: ', ''
|
|
|
|
puts ' ruby plugin-translations.rb <plugins_base_dir>'
|
|
|
|
puts ' ruby plugin-translations.rb <plugins_base_dir> push (to git push)'
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
require 'bundler'
|
|
|
|
|
|
|
|
class PluginTxUpdater
|
|
|
|
|
|
|
|
attr_reader :failed
|
|
|
|
|
|
|
|
PLUGINS = [
|
|
|
|
'discourse-adplugin',
|
|
|
|
'discourse-akismet',
|
|
|
|
'discourse-assign',
|
|
|
|
'discourse-cakeday',
|
|
|
|
'discourse-canned-replies',
|
2018-01-05 21:34:58 +08:00
|
|
|
'discourse-characters-required',
|
2017-12-30 05:57:06 +08:00
|
|
|
'discourse-chat-integration',
|
2018-04-06 04:41:29 +08:00
|
|
|
'discourse-chronos',
|
2017-12-30 05:57:06 +08:00
|
|
|
'discourse-data-explorer',
|
|
|
|
'discourse-math',
|
|
|
|
'discourse-oauth2-basic',
|
|
|
|
'discourse-patreon',
|
2018-02-01 00:19:08 +08:00
|
|
|
'discourse-saved-searches',
|
2017-12-30 05:57:06 +08:00
|
|
|
'discourse-solved',
|
|
|
|
'discourse-staff-notes',
|
|
|
|
'discourse-voting'
|
|
|
|
]
|
|
|
|
|
|
|
|
def initialize(base_dir, push)
|
|
|
|
@push = !!push
|
|
|
|
@base_dir = base_dir
|
|
|
|
@failed = []
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform
|
|
|
|
PLUGINS.each do |plugin_name|
|
|
|
|
plugin_dir = File.join(@base_dir, plugin_name)
|
|
|
|
Bundler.with_clean_env do
|
|
|
|
Dir.chdir(plugin_dir) do
|
|
|
|
puts '', plugin_dir, '-' * 80, ''
|
|
|
|
|
|
|
|
begin
|
|
|
|
system_cmd('git pull')
|
|
|
|
system_cmd('bundle update translations-manager')
|
|
|
|
system_cmd('bundle exec bin/pull_translations.rb')
|
|
|
|
system_cmd('git add config/locales/*')
|
|
|
|
system_cmd('git add Gemfile.lock') rescue true # might be gitignored
|
|
|
|
system_cmd('git commit -m "Update translations"')
|
|
|
|
system_cmd('git push origin master') if @push
|
|
|
|
rescue => e
|
|
|
|
puts "Failed for #{plugin_name}. Skipping...", ''
|
|
|
|
@failed << plugin_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def system_cmd(s)
|
|
|
|
rc = system(s)
|
|
|
|
raise RuntimeError.new($?) if rc != true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
base_dir = File.expand_path(ARGV[0])
|
|
|
|
|
|
|
|
unless File.exists?(base_dir)
|
|
|
|
puts '', "Dir '#{base_dir}' doesn't exist."
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
updates = PluginTxUpdater.new(base_dir, ARGV[1]&.downcase == 'push')
|
|
|
|
updates.perform
|
|
|
|
|
|
|
|
if updates.failed.empty?
|
|
|
|
puts '', "All plugins updated successfully!", ''
|
|
|
|
else
|
|
|
|
if updates.failed.size < PluginTxUpdater::PLUGINS.size
|
|
|
|
puts '', "These plugins updated successfully: ", ''
|
|
|
|
puts PluginTxUpdater::PLUGINS - updates.failed
|
|
|
|
end
|
|
|
|
puts '', "Errors were encountered while updating these plugins:", ''
|
|
|
|
puts updates.failed
|
|
|
|
end
|