2020-12-04 18:18:54 +00:00
|
|
|
require "pathname"
|
|
|
|
|
2020-12-20 05:02:06 +00:00
|
|
|
BUILD_DIR = Pathname("build")
|
|
|
|
LOCALE_DIR = Pathname("trans")
|
|
|
|
TRANS_DIR = Pathname("translate")
|
2023-02-23 12:46:22 +00:00
|
|
|
PSEUDO_LANG = "ach-UG"
|
2020-12-04 18:18:54 +00:00
|
|
|
|
2020-12-20 05:02:06 +00:00
|
|
|
CROWDIN_SNIPPET = <<EOS
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
var _jipt = [];
|
|
|
|
_jipt.push(['project', 'plume-docs']);
|
|
|
|
_jipt.push(['escape', function() {
|
|
|
|
window.location.href = 'https://joinplu.me';
|
|
|
|
}]);
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript" src="//cdn.crowdin.com/jipt/jipt.js"></script>
|
|
|
|
EOS
|
|
|
|
|
|
|
|
class Pathname
|
|
|
|
alias to_str to_s
|
|
|
|
end
|
2020-12-04 18:18:54 +00:00
|
|
|
|
2021-02-14 22:17:52 +00:00
|
|
|
desc "Run all tasks"
|
|
|
|
task :all => ["crowdin:upload", :wait_trans_updated, :deploy, :deploy_trans]
|
|
|
|
|
|
|
|
task :wait_trans_updated do
|
|
|
|
sleep 30
|
|
|
|
end
|
|
|
|
|
2020-12-04 18:18:54 +00:00
|
|
|
desc "Build site"
|
2020-12-20 05:02:06 +00:00
|
|
|
task :build_site => [:build_base, "crowdin:download"] do
|
|
|
|
LOCALE_DIR.glob("**/*.html").each do |html|
|
2020-12-20 05:50:06 +00:00
|
|
|
dest = Pathname(html.to_path.sub(%r|#{LOCALE_DIR}/([^/]+)/trans|, "#{BUILD_DIR}/\\1"))
|
|
|
|
next if dest.file?
|
2020-12-04 18:18:54 +00:00
|
|
|
dest.parent.mkpath
|
2020-12-20 05:02:06 +00:00
|
|
|
copy html, dest
|
2020-12-04 18:18:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
task :build_base do
|
2020-12-27 15:51:03 +00:00
|
|
|
sh "bundle", "exec", "middleman", "build"
|
2020-12-04 18:18:54 +00:00
|
|
|
end
|
|
|
|
|
2020-12-20 05:02:06 +00:00
|
|
|
desc "Build site for translate.docs.joinplu.me"
|
2020-12-20 06:05:48 +00:00
|
|
|
task :build_trans => "crowdin:download" do
|
2020-12-27 15:51:03 +00:00
|
|
|
sh "bundle", "exec", "middleman", "build", "--build-dir", TRANS_DIR
|
2020-12-20 05:02:06 +00:00
|
|
|
|
|
|
|
(LOCALE_DIR/PSEUDO_LANG/"trans").glob("**/*.html").each do |html|
|
|
|
|
doc = html.read
|
|
|
|
doc.sub! "<head>", "<head>" + CROWDIN_SNIPPET
|
|
|
|
dest = Pathname(html.to_path.sub(LOCALE_DIR/PSEUDO_LANG/"trans", TRANS_DIR))
|
|
|
|
$stderr.puts "#{html} -> #{dest}"
|
|
|
|
dest.write doc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
task :build_trans_src do
|
2020-12-27 15:51:03 +00:00
|
|
|
sh "bundle", "exec", "middleman", "build", "--build-dir", LOCALE_DIR
|
2020-12-04 18:18:54 +00:00
|
|
|
end
|
|
|
|
|
2020-12-20 05:15:52 +00:00
|
|
|
desc "Deploy docs.joinplue.me"
|
|
|
|
task :deploy => :build_site do
|
|
|
|
sh "netlify", "deploy", "--site", "40419055-f669-42be-8d07-0c1dcc0dc24b", "--dir", BUILD_DIR, "--prod"
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Deploy translate.docs.joinplue.me"
|
|
|
|
task :deploy_trans => :build_trans do
|
|
|
|
sh "netlify", "deploy", "--site", "2b1e232b-ac98-4680-9ab4-6d4eee0d84cb", "--dir", TRANS_DIR, "--prod"
|
|
|
|
end
|
|
|
|
|
2020-12-04 18:18:54 +00:00
|
|
|
namespace :crowdin do
|
|
|
|
desc "Download translations"
|
2020-12-20 05:02:06 +00:00
|
|
|
task :download => :build_trans_src do
|
2020-12-04 18:18:54 +00:00
|
|
|
sh "crowdin", "download"
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Upload translation sources"
|
2020-12-20 06:02:17 +00:00
|
|
|
task :upload => :build_trans_src do
|
2020-12-04 18:25:05 +00:00
|
|
|
sh "crowdin", "upload", "sources"
|
2020-12-04 18:18:54 +00:00
|
|
|
end
|
2020-12-20 05:02:06 +00:00
|
|
|
|
|
|
|
task :download_pseudo do
|
|
|
|
sh "crowdin", "download", "--pseudo"
|
|
|
|
end
|
2020-12-04 18:18:54 +00:00
|
|
|
end
|