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'.freeze
DEFAULT_BASE_LANG =
'en'.freeze
CONFIG_FILE_NAME =
'swiftgen-stringtypes.yml'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of L10nLinterHelper.

Parameters:

  • install_path (String)

    The path to install SwiftGen to. Usually something like “$PROJECT_DIR/vendor/swiftgen/#SWIFTGEN_VERSION”. It’s recommended to provide an absolute path here rather than a relative one, to ensure it’s not dependant on where the action is run from.

  • version (String) (defaults to: SWIFTGEN_VERSION)

    The version of SwiftGen to use. This will be used both:

    • to check if the current version located in ‘install_path`, if it already exists, is the expected one

    • to know which version to download if there is not one installed in ‘install_path` yet



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

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.



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

def install_path
  @install_path
end

#versionObject (readonly)

Returns the value of attribute version.



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

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`



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

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`



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

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) ⇒ 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

Parameters:

  • input_dir (String)

    The path (ideally absolute) to the directory containing the ‘.lproj` folders to parse

  • base_lang (String) (defaults to: DEFAULT_BASE_LANG)

    The code name (i.e the basename of one of the ‘.lproj` folders) of the locale to use as the baseline

Returns:

  • (Hash<String, Array<String>>)

    A hash of violations, keyed by language code, whose values are the list of violation messages for that language



63
64
65
66
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_linter_helper.rb', line 63

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