Have Javascript locales generate (or clean) as part of other expected tasks and commands
This commit is contained in:
parent
ce4940fde8
commit
e2b868f6de
4 changed files with 75 additions and 12 deletions
|
@ -30,7 +30,6 @@ AllCops:
|
|||
- 'lib/tasks/settings.rake'
|
||||
- 'lib/tasks/civicrm.rake'
|
||||
- 'lib/tasks/scheduler.rake'
|
||||
- 'lib/tasks/i18n_js.rake'
|
||||
- 'lib/tasks/seed.rake'
|
||||
- 'lib/tasks/health_report.rake'
|
||||
- 'lib/tasks/notice.rake'
|
||||
|
|
|
@ -11,6 +11,7 @@ require "bundler/setup"
|
|||
|
||||
require "webpacker"
|
||||
require "webpacker/webpack_runner"
|
||||
|
||||
def system!(*args)
|
||||
system(*args) || abort("\n== Command #{args} failed ==")
|
||||
end
|
||||
|
|
|
@ -3,37 +3,41 @@
|
|||
# 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
|
||||
|
||||
|
||||
def enhance_assets_precompile
|
||||
# yarn:install was added in Rails 5.1
|
||||
Rake::Task["assets:precompile"].enhance(['i18n:js:export'])
|
||||
# yarn:install was added in Rails 5.1
|
||||
Rake::Task['assets:precompile'].enhance(['i18n:js:export'])
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def enhance_assets_clean_and_clobber
|
||||
Rake::Task["assets:clean"].enhance(['i18n:js:clean'])
|
||||
Rake::Task["assets:clobber"].enhance(['i18n:js:clean'])
|
||||
Rake::Task['assets:clean'].enhance(['i18n:js:clean'])
|
||||
Rake::Task['assets:clobber'].enhance(['i18n:js:clean'])
|
||||
end
|
||||
|
||||
desc 'For generating the i18n-js exports at runtime. Overrides the built in i18n-js task'
|
||||
namespace :i18n do
|
||||
namespace :js do
|
||||
desc 'Export locales to Typescript'
|
||||
task export: :environment do
|
||||
GenerateLocales.generate
|
||||
end
|
||||
|
||||
desc 'Delete all of the generated Javascript locales files'
|
||||
task clean: :environment do
|
||||
locales_dir = Rails.root.join('app', 'javascript', 'i18n', 'locales')
|
||||
FileUtils.remove_dir(locales_dir) if Dir.exists? locales_dir
|
||||
locales_dir = Rails.root.join('app/javascript/i18n/locales')
|
||||
FileUtils.remove_dir(locales_dir) if Dir.exist? locales_dir
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
enhance_assets_precompile
|
||||
enhance_webpacker_compile
|
||||
enhance_webpacker_clean
|
||||
enhance_assets_clean_and_clobber
|
59
spec/tasks/i18n_js_spec.rb
Normal file
59
spec/tasks/i18n_js_spec.rb
Normal 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
|
Loading…
Reference in a new issue