fastlane-plugin-flutter 0.1.12 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a5c9b9a28e41593a86173cdbaf70d207af1ab6e
4
- data.tar.gz: d1856be81db8b2ee23d1256a5f66a192d5ffec48
3
+ metadata.gz: c316ef1b82023c187f64f845756d3b2587fe820f
4
+ data.tar.gz: f312e47178083ab7a7170d0fe315450a4e973756
5
5
  SHA512:
6
- metadata.gz: 1bf04d9031d6be50a97208d83b12fbf6c381a9add3399c470ba0d436070bfea728451b38de8ca7675d707b40e6e5ffdec732e5c3ac325f9848bae06fd3d1dc86
7
- data.tar.gz: 31f77407265132eef039c6b91ee104d2e5ef5d6569aef1422834dade4221e7dae202b9c9b1b8250c0c690cb0ed72f6efbcdb6312ba15f2a8800ab1ba1ae4200d
6
+ metadata.gz: 81d218b9b3b9540cc1813d7e33c5a535967438ac425f0b0000f0d44e85cda337d507a5b11eecf272d5307ccc8be9e4170e3a7bd29e615927487167b8d42e12f7
7
+ data.tar.gz: 13ed10d618b0f6494d96a5e299ab157bb5c5eb92aba21852209b961a36f5b6fe18c14e0417cdb8d04ee416a61b8008da45dbb597c7cb76524214119c81bc4137
@@ -67,63 +67,81 @@ module Fastlane
67
67
  when 'format'
68
68
  sh *%w(flutter format .)
69
69
  when 'l10n'
70
- unless params[:l10n_strings_file]
71
- UI.user_error!('l10n_strings_file is a required parameter for ' \
72
- 'l10n action')
73
- end
70
+ run_l10n(params)
71
+ end
72
+ end
74
73
 
75
- output_dir = 'lib/l10n'
76
- l10n_messages_file = File.join(output_dir, 'intl_messages.arb')
77
- # This file will not exist before it's generated for the first time.
78
- if File.exist?(l10n_messages_file)
79
- l10n_messages_was = File.read(l10n_messages_file)
80
- end
74
+ def self.run_l10n(params)
75
+ unless params[:l10n_strings_file]
76
+ UI.user_error!('l10n_strings_file is a required parameter for ' \
77
+ 'l10n action')
78
+ end
81
79
 
82
- extract_to_arb_options = ["--output-dir=#{output_dir}"]
83
- if params[:l10n_strings_locale]
84
- extract_to_arb_options.push(
85
- "--locale=#{params[:l10n_strings_locale]}"
86
- )
87
- end
80
+ output_dir = 'lib/l10n'
81
+ l10n_messages_file = File.join(output_dir, 'intl_messages.arb')
82
+ # This file will not exist before it's generated for the first time.
83
+ if File.exist?(l10n_messages_file)
84
+ l10n_messages_was = File.read(l10n_messages_file)
85
+ end
88
86
 
89
- sh *%w(flutter pub pub run intl_translation:extract_to_arb),
90
- *extract_to_arb_options, params[:l10n_strings_file]
87
+ extract_to_arb_options = ["--output-dir=#{output_dir}"]
88
+ if params[:l10n_strings_locale]
89
+ extract_to_arb_options.push(
90
+ "--locale=#{params[:l10n_strings_locale]}"
91
+ )
92
+ end
91
93
 
92
- if l10n_messages_was
93
- # intl will update @@last_modified even if there are no updates;
94
- # this leaves Git directory unnecessary dirty. If that's the only
95
- # change, just restore the previous contents.
96
- if Helper::FlutterHelper.restore_l10n_timestamp(
97
- l10n_messages_file, l10n_messages_was
94
+ sh *%w(flutter pub pub run intl_translation:extract_to_arb),
95
+ *extract_to_arb_options, params[:l10n_strings_file]
96
+
97
+ if l10n_messages_was
98
+ # intl will update @@last_modified even if there are no updates;
99
+ # this leaves Git directory unnecessary dirty. If that's the only
100
+ # change, just restore the previous contents.
101
+ if Helper::FlutterHelper.restore_l10n_timestamp(
102
+ l10n_messages_file, l10n_messages_was
103
+ )
104
+ UI.message(
105
+ "@@last_modified has been restored in #{l10n_messages_file}"
98
106
  )
99
- UI.message(
100
- "@@last_modified has been restored in #{l10n_messages_file}"
101
- )
102
- end
103
- end
104
-
105
- # Sort files for consistency, because messages_all.dart will have
106
- # imports ordered as in the command line below.
107
- arb_files = Dir.glob(File.join(output_dir, 'intl_*.arb')).sort
108
-
109
- unless params[:l10n_strings_locale]
110
- # Don't generate .dart for the original ARB unless it has its own
111
- # locale.
112
- arb_files.delete(l10n_messages_file)
113
107
  end
108
+ end
114
109
 
115
- if params[:l10n_reformat_arb]
116
- arb_files.each do |arb_file|
117
- UI.message("Reformatting file #{arb_file}...")
118
- Helper::FlutterHelper.reformat_arb(arb_file)
110
+ # Sort files for consistency, because messages_all.dart will have
111
+ # imports ordered as in the command line below.
112
+ arb_files = Dir.glob(File.join(output_dir, 'intl_*.arb')).sort
113
+
114
+ if params[:l10n_verify_arb]
115
+ errors_found = arb_files.any? do |arb_file|
116
+ unless arb_file == l10n_messages_file
117
+ UI.message("Verifying #{arb_file}...")
118
+ errors = Helper::FlutterHelper.compare_arb(l10n_messages_file,
119
+ arb_file)
120
+ if errors.any?
121
+ errors.each(&UI.method(:error))
122
+ end
119
123
  end
120
124
  end
125
+ UI.user_error!('Found inconsistencies in ARB files') if errors_found
126
+ end
127
+
128
+ unless params[:l10n_strings_locale]
129
+ # Don't generate .dart for the original ARB unless it has its own
130
+ # locale.
131
+ arb_files.delete(l10n_messages_file)
132
+ end
121
133
 
122
- sh *%W(flutter pub pub run intl_translation:generate_from_arb
123
- --output-dir=#{output_dir}
124
- --no-use-deferred-loading
125
- #{params[:l10n_strings_file]}) + arb_files
134
+ if params[:l10n_reformat_arb]
135
+ arb_files.each do |arb_file|
136
+ UI.message("Reformatting file #{arb_file}...")
137
+ Helper::FlutterHelper.reformat_arb(arb_file)
138
+ end
126
139
  end
140
+
141
+ sh *%W(flutter pub pub run intl_translation:generate_from_arb
142
+ --output-dir=#{output_dir}
143
+ --no-use-deferred-loading
144
+ #{params[:l10n_strings_file]}) + arb_files
127
145
  end
128
146
 
129
147
  def self.description
@@ -189,6 +207,14 @@ module Fastlane
189
207
  is_string: false,
190
208
  default_value: false,
191
209
  ),
210
+ FastlaneCore::ConfigItem.new(
211
+ key: :l10n_verify_arb,
212
+ env_name: 'FL_FLUTTER_L10N_VERIFY_ARB',
213
+ description: 'Verify that each .arb file includes all strings',
214
+ optional: true,
215
+ is_string: false,
216
+ default_value: true,
217
+ ),
192
218
  ]
193
219
  end
194
220
 
@@ -1,5 +1,6 @@
1
1
  require 'fastlane_core/ui/ui'
2
2
  require 'json'
3
+ require 'set'
3
4
 
4
5
  module Fastlane
5
6
  # UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
@@ -29,6 +30,33 @@ module Fastlane
29
30
 
30
31
  File.write(file_name, pretty_content + "\n")
31
32
  end
33
+
34
+ def self.compare_arb(origin, sample)
35
+ is_significant_key = ->(key) { !key.start_with?('@') }
36
+
37
+ origin_keys = Set.new(JSON.parse(File.read(origin))
38
+ .keys
39
+ .select(&is_significant_key))
40
+ sample_keys = Set.new(JSON.parse(File.read(sample))
41
+ .keys
42
+ .select(&is_significant_key))
43
+
44
+ keys_not_in_sample = origin_keys - sample_keys
45
+ keys_not_in_origin = sample_keys - origin_keys
46
+
47
+ differencies = []
48
+ if keys_not_in_sample.any?
49
+ differencies.push("Translation string(s): " \
50
+ "#{keys_not_in_sample.to_a.join(', ')}; " \
51
+ "are missing")
52
+ end
53
+ if keys_not_in_origin.any?
54
+ differencies.push("Translation string(s): " \
55
+ "#{keys_not_in_origin.to_a.join(', ')}; " \
56
+ "are unused")
57
+ end
58
+ differencies
59
+ end
32
60
  end
33
61
  end
34
62
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Flutter
3
- VERSION = "0.1.12"
3
+ VERSION = "0.1.13"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-flutter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Sheremet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-02 00:00:00.000000000 Z
11
+ date: 2018-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry