2017-12-29 15:57:06 -06: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 07:34:58 -06:00
|
|
|
'discourse-characters-required',
|
2017-12-29 15:57:06 -06:00
|
|
|
'discourse-chat-integration',
|
2018-08-23 09:00:27 -05:00
|
|
|
'discourse-checklist',
|
2017-12-29 15:57:06 -06:00
|
|
|
'discourse-data-explorer',
|
|
|
|
'discourse-math',
|
|
|
|
'discourse-oauth2-basic',
|
|
|
|
'discourse-patreon',
|
2018-01-31 10:19:08 -06:00
|
|
|
'discourse-saved-searches',
|
2017-12-29 15:57:06 -06: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
|
2018-09-10 13:22:45 -05:00
|
|
|
system_cmd('git add .tx/config') rescue true
|
2017-12-29 15:57:06 -06:00
|
|
|
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
|