Class: Fastlane::Helper::Ios::L10nLinterHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb

Constant Summary collapse

SWIFTGEN_VERSION =
'6.6.2'
DEFAULT_BASE_LANG =
'en'
CONFIG_FILE_NAME =
'swiftgen-stringtypes.yml'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(install_path:, version: SWIFTGEN_VERSION) ⇒ L10nLinterHelper



22
23
24
25
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb', line 22

def initialize(install_path:, version: SWIFTGEN_VERSION)
  @install_path = install_path
  @version = version || SWIFTGEN_VERSION
end

Instance Attribute Details

#install_pathObject (readonly)

Returns the value of attribute install_path.



14
15
16
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb', line 14

def install_path
  @install_path
end

#versionObject (readonly)

Returns the value of attribute version.



14
15
16
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb', line 14

def version
  @version
end

Instance Method Details

#check_swiftgen_installedObject

Check if SwiftGen is installed in the provided ‘install_path` and if so if the installed version matches the expected `version`



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb', line 29

def check_swiftgen_installed
  return false unless File.exist?(swiftgen_bin)

  vers_string = `#{swiftgen_bin} --version`
  # The SwiftGen version string has this format:
  #
  # SwiftGen v6.4.0 (Stencil v0.13.1, StencilSwiftKit v2.7.2, SwiftGenKit v6.4.0)
  vers_string.include?("SwiftGen v#{version}")
rescue StandardError
  false
end

#install_swiftgen!Object

Note:

This action nukes anything at ‘install_path` – if something already exists – prior to install SwiftGen there

Download the ZIP of SwiftGen for the requested ‘version` and install it in the `install_path`



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb', line 45

def install_swiftgen!
  UI.message "Installing SwiftGen #{version} into #{install_path}"
  Dir.mktmpdir do |tmpdir|
    zipfile = File.join(tmpdir, "swiftgen-#{version}.zip")
    Action.sh('curl', '--fail', '--location', '-o', zipfile, "https://github.com/SwiftGen/SwiftGen/releases/download/#{version}/swiftgen-#{version}.zip")
    extracted_dir = File.join(tmpdir, "swiftgen-#{version}")
    Action.sh('unzip', zipfile, '-d', extracted_dir)

    FileUtils.rm_rf(install_path)
    FileUtils.mkdir_p(install_path)
    FileUtils.cp_r("#{extracted_dir}/.", install_path)
  end
end

#run(input_dir:, base_lang: DEFAULT_BASE_LANG, only_langs: nil, fail_on_strings_not_in_base_language: true) ⇒ Hash<String, Array<String>>

Install SwiftGen if necessary (if not installed yet with the expected version), then run the checks and returns the violations found, if any



66
67
68
69
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb', line 66

def run(input_dir:, base_lang: DEFAULT_BASE_LANG, only_langs: nil, fail_on_strings_not_in_base_language: true)
  check_swiftgen_installed || install_swiftgen!
  find_diffs(input_dir: input_dir, base_lang: base_lang, only_langs: only_langs, fail_on_strings_not_in_base_language: fail_on_strings_not_in_base_language)
end