Class: Fastlane::Actions::FlutterGenerateAction

Inherits:
Action
  • Object
show all
Extended by:
FlutterActionBase
Defined in:
lib/fastlane/plugin/flutter/actions/flutter_generate_action.rb

Class Method Summary collapse

Methods included from FlutterActionBase

authors, is_supported?

Class Method Details

.available_optionsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fastlane/plugin/flutter/actions/flutter_generate_action.rb', line 42

def self.available_options
  # https://docs.fastlane.tools/advanced/actions/#configuration-files
  [
    FastlaneCore::ConfigItem.new(
      key: :intl_strings_file,
      env_name: 'FL_FLUTTER_INTL_STRINGS_FILE',
      description: 'Path to source .dart file with Intl.message calls',
      verify_block: proc do |value|
        if generate_translation?
          unless File.exist?(value)
            UI.user_error!("File `#{value}' does not exist")
          end
        end
      end,
      default_value: 'lib/intl/intl.dart',
    ),
    FastlaneCore::ConfigItem.new(
      key: :intl_strings_locale,
      env_name: 'FL_FLUTTER_INTL_STRINGS_LOCALE',
      description: 'Locale of the default data in the strings_file',
      optional: true,
    ),
  ]
end

.descriptionObject



35
36
37
38
39
40
# File 'lib/fastlane/plugin/flutter/actions/flutter_generate_action.rb', line 35

def self.description
  'According to package:intl, take $strings_file and generate ' \
  '${strings_file.dirname}/arb/intl_messages.arb, then take all files ' \
  'matching ${strings_file.dirname}/intl_*.arb, fix them and generate ' \
  '.dart files from them'
end

.generate_translation?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/fastlane/plugin/flutter/actions/flutter_generate_action.rb', line 31

def self.generate_translation?
  Helper::FlutterHelper.dev_dependency?('intl_translation')
end

.run(params) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fastlane/plugin/flutter/actions/flutter_generate_action.rb', line 12

def self.run(params)
  Helper::FlutterHelper.flutter(*%w(packages get)) {}

  # In an ideal world, this should be a part of build_runner:
  # https://github.com/dart-lang/intl_translation/issues/32
  # Generate Intl messages before others, since these are static and
  # others may be not.
  if generate_translation?
    Helper::FlutterGenerateIntlHelper.generate(
      params[:intl_strings_file], params[:intl_strings_locale]
    )
  end

  if Helper::FlutterHelper.dev_dependency?('build_runner')
    UI.message('Found build_runner dependency, running build...')
    Helper::FlutterGenerateBuildRunnerHelper.build
  end
end