Class: InertiaI18n::Cli
- Inherits:
-
Thor
- Object
- Thor
- InertiaI18n::Cli
- Defined in:
- lib/inertia_i18n/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #convert ⇒ Object
- #health ⇒ Object
- #init ⇒ Object
- #missing ⇒ Object
- #normalize ⇒ Object
- #scan ⇒ Object
- #unused ⇒ Object
- #version ⇒ Object
- #watch ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
10 11 12 |
# File 'lib/inertia_i18n/cli.rb', line 10 def self.exit_on_failure? true end |
Instance Method Details
#convert ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/inertia_i18n/cli.rb', line 17 def convert load_config([:config]) if [:locale] result = FileConverter.convert_locale([:locale].to_sym) print_convert_result(result) else results = FileConverter.convert_all results.each { |r| print_convert_result(r) } end end |
#health ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/inertia_i18n/cli.rb', line 120 def health load_config([:config]) checker = HealthChecker.new.check! if [:format] == "json" output = { healthy: checker.healthy?, summary: checker.summary, issues: checker.issues } puts JSON.pretty_generate(output) else print_health_results(checker, [:verbose]) end exit 1 unless checker.healthy? end |
#init ⇒ Object
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/inertia_i18n/cli.rb', line 155 def init format = [:format] path = [:path] || default_init_path(format) content = (format == "yaml") ? yaml_config_template : ruby_config_template FileUtils.mkdir_p(File.dirname(path)) File.write(path, content) puts "Created #{path}" end |
#missing ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/inertia_i18n/cli.rb', line 80 def missing load_config([:config]) checker = HealthChecker.new.check!(checks: [:missing]) if [:format] == "json" puts JSON.pretty_generate({issues: checker.issues[:missing], count: checker.issues[:missing].size}) else print_issues("Missing Keys (used in code, not translated)", checker.issues[:missing], [:verbose]) puts "#{checker.issues[:missing].size} missing key(s) found." if checker.issues[:missing].any? puts "No missing keys found." if checker.issues[:missing].empty? end exit 1 if checker.issues[:missing].any? end |
#normalize ⇒ Object
141 142 143 144 145 |
# File 'lib/inertia_i18n/cli.rb', line 141 def normalize load_config([:config]) Normalizer.new.normalize end |
#scan ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/inertia_i18n/cli.rb', line 60 def scan load_config([:config]) scanner = Scanner.new results = scanner.scan case [:format] when "json" puts JSON.pretty_generate(results.to_h) when "yaml" puts results.to_h.to_yaml else print_scan_results(results) end end |
#unused ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/inertia_i18n/cli.rb', line 100 def unused load_config([:config]) checker = HealthChecker.new.check!(checks: [:unused]) if [:format] == "json" puts JSON.pretty_generate({issues: checker.issues[:unused], count: checker.issues[:unused].size}) else print_issues("Unused Keys (translated, not used in code)", checker.issues[:unused], [:verbose]) puts "#{checker.issues[:unused].size} unused key(s) found." if checker.issues[:unused].any? puts "No unused keys found." if checker.issues[:unused].empty? end exit 1 if checker.issues[:unused].any? end |
#version ⇒ Object
148 149 150 |
# File 'lib/inertia_i18n/cli.rb', line 148 def version puts "InertiaI18n #{InertiaI18n::VERSION}" end |
#watch ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/inertia_i18n/cli.rb', line 31 def watch load_config([:config]) config = InertiaI18n.configuration paths = config.source_paths.map(&:to_s) puts "š Watching #{paths.join(", ")} for YAML changes..." listener = Listen.to(*paths, only: /\.(yml|yaml)$/) do |modified, added, removed| puts "š Detected locale file changes..." (modified + added + removed).each do |file| puts " #{file}" end puts "š Regenerating JSON files..." results = FileConverter.convert_all results.each { |r| print_convert_result(r) } puts "ā Done!" end listener.start sleep rescue Interrupt puts "\nš Stopping watch mode..." listener.stop end |