Have Javascript locales generate (or clean) as part of other expected tasks and commands

This commit is contained in:
Eric Schultz 2021-03-13 17:34:49 -06:00 committed by Eric Schultz
parent ce4940fde8
commit e2b868f6de
4 changed files with 75 additions and 12 deletions

View file

@ -30,7 +30,6 @@ AllCops:
- 'lib/tasks/settings.rake' - 'lib/tasks/settings.rake'
- 'lib/tasks/civicrm.rake' - 'lib/tasks/civicrm.rake'
- 'lib/tasks/scheduler.rake' - 'lib/tasks/scheduler.rake'
- 'lib/tasks/i18n_js.rake'
- 'lib/tasks/seed.rake' - 'lib/tasks/seed.rake'
- 'lib/tasks/health_report.rake' - 'lib/tasks/health_report.rake'
- 'lib/tasks/notice.rake' - 'lib/tasks/notice.rake'

View file

@ -11,6 +11,7 @@ require "bundler/setup"
require "webpacker" require "webpacker"
require "webpacker/webpack_runner" require "webpacker/webpack_runner"
def system!(*args) def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==") system(*args) || abort("\n== Command #{args} failed ==")
end end

View file

@ -3,37 +3,41 @@
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later # License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE # Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
def enhance_assets_precompile def enhance_assets_precompile
# yarn:install was added in Rails 5.1 # yarn:install was added in Rails 5.1
Rake::Task["assets:precompile"].enhance(['i18n:js:export']) Rake::Task['assets:precompile'].enhance(['i18n:js:export'])
end end
def enhance_webpacker_compile def enhance_webpacker_compile
# yarn:install was added in Rails 5.1 Rake::Task['webpacker:compile'].enhance(['i18n:js:export'])
Rake::Task["webpacker:compile"].enhance(['i18n:js:export']) end
def enhance_webpacker_clean
Rake::Task['webpacker:clean'].enhance(['i18n:js:clean'])
end end
def enhance_assets_clean_and_clobber def enhance_assets_clean_and_clobber
Rake::Task["assets:clean"].enhance(['i18n:js:clean']) Rake::Task['assets:clean'].enhance(['i18n:js:clean'])
Rake::Task["assets:clobber"].enhance(['i18n:js:clean']) Rake::Task['assets:clobber'].enhance(['i18n:js:clean'])
end end
desc 'For generating the i18n-js exports at runtime. Overrides the built in i18n-js task' desc 'For generating the i18n-js exports at runtime. Overrides the built in i18n-js task'
namespace :i18n do namespace :i18n do
namespace :js do namespace :js do
desc 'Export locales to Typescript'
task export: :environment do task export: :environment do
GenerateLocales.generate GenerateLocales.generate
end end
desc 'Delete all of the generated Javascript locales files' desc 'Delete all of the generated Javascript locales files'
task clean: :environment do task clean: :environment do
locales_dir = Rails.root.join('app', 'javascript', 'i18n', 'locales') locales_dir = Rails.root.join('app/javascript/i18n/locales')
FileUtils.remove_dir(locales_dir) if Dir.exists? locales_dir FileUtils.remove_dir(locales_dir) if Dir.exist? locales_dir
end end
end end
end end
enhance_assets_precompile enhance_assets_precompile
enhance_webpacker_compile enhance_webpacker_compile
enhance_webpacker_clean
enhance_assets_clean_and_clobber enhance_assets_clean_and_clobber

View file

@ -0,0 +1,59 @@
# frozen_string_literal: true
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
require 'rails_helper'
Rails.application.load_tasks
describe 'i18n_js.rake' do # rubocop:disable RSpec/DescribeClass
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
let(:locales_dir) { Rails.root.join('app/javascript/i18n/locales') }
def wrap_task(rake_taskname)
task = Rake::Task[rake_taskname]
Rake.application.tasks.each(&:reenable)
task.invoke
yield
Rake.application.tasks.each(&:reenable)
end
def verify_cleaned(rake_taskname)
wrap_task(rake_taskname) do
expect(!Dir.exist?(locales_dir) || Dir[locales_dir].none?).to(
eq(true),
"#{locales_dir} wasn't cleaned by rake #{rake_taskname}"
)
end
end
def verify_task_generate(rake_taskname)
wrap_task(rake_taskname) do
expect(Dir.exist?(locales_dir) && Dir[locales_dir].any?).to(
eq(true),
"#{locales_dir} wasn't generated by rake #{rake_taskname}"
)
end
end
def verify_generate(command_line)
system!(command_line)
expect(Dir.exist?(locales_dir) && Dir[locales_dir].any?).to(
eq(true),
"#{locales_dir} wasn't generated by #{command_line}"
)
end
it 'export and clean' do
verify_task_generate('i18n:js:export')
verify_cleaned('webpacker:clean')
verify_task_generate('webpacker:compile')
verify_cleaned('assets:clobber')
verify_task_generate('i18n:js:export')
verify_cleaned('i18n:js:clean')
verify_generate('bin/webpack')
end
end