fastlane-plugin-flutter_versioner 0.1.0 → 0.1.2

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
  SHA256:
3
- metadata.gz: 35af839b7b1ec389092f33854ca32c634cd8321be82b187a2e26fc50e0b670d0
4
- data.tar.gz: faf2a30fab6e9e5eb57f0be5e6023af38356cee9c99b1c6e2b9498cb9a9201a5
3
+ metadata.gz: db5ae03b487912dd8c620536eead7514a6ee60c5d9b35170ae988651683210a4
4
+ data.tar.gz: 6b18ef196803ab1eab1618d6f48540df0d1161a857c1d8fe3c000e11d042e814
5
5
  SHA512:
6
- metadata.gz: d3df3a6c5893dc86c2acc421ba23bacbe2b046a36dba7e1ec180829985048660433901eda8bdb4d613bed5ae465369c1e4fd1701c9a6f728be495bbbc51be9a5
7
- data.tar.gz: 4e42e6a3e2c8399dbcb2c57fbe0a85282e4ac6355952b2c0b3252f13f977211623627c3d422b74fbd52f354419b6a77a65ef120c1c16b314d7c7f720e4a9db00
6
+ metadata.gz: a6adc987c072ed36442c0ea057eaf6a3772a0a713f26b6a2dfcfa8d4f9337c36ee3a1d2a54aea3ca874bdc700a1edee6c864b84e849f0f7030f7d222d5afdda6
7
+ data.tar.gz: afe51053d95a50b79e32456ae22f5c5067467ba803a408e650566231b3a4f5aee90d91000550c9bf4d76692e69412308bbe40b4fc6d9c6eaa9978950550547e6
data/README.md CHANGED
@@ -116,6 +116,28 @@ flutter_versioner(pubspec_file_path:"./example/pubspec.yaml",
116
116
  version_component:"major")
117
117
  ```
118
118
 
119
+ ### 5. VERSION NAME
120
+
121
+ #### a. Set the flutter version name to `value` given
122
+ eg 1.1.1+1 -> 2.3.4+1
123
+
124
+ ```
125
+ flutter_versioner(pubspec_file_path:"./example/pubspec.yaml",
126
+ value:"2.3.4",
127
+ version_component:"version_name")
128
+ ```
129
+
130
+ ### 6. VERSION
131
+
132
+ #### a. Set the flutter version name to `value` given
133
+ eg 1.1.1+1 -> 2.3.4+5
134
+
135
+ ```
136
+ flutter_versioner(pubspec_file_path:"./example/pubspec.yaml",
137
+ value:"2.3.4+5",
138
+ version_component:"version")
139
+ ```
140
+
119
141
 
120
142
  ## Run tests for this plugin
121
143
 
@@ -15,22 +15,21 @@ module Fastlane
15
15
  UI.user_error!("The pubspec file path given. Pass the `pubspec_file_path` to the action")
16
16
  else
17
17
  UI.message("The flutter_versioner plugin will use pubspec file at (#{pubspec_file_path})!")
18
- version_list = incrementVersion(pubspec_file_path, new_value, constant_name, version_component)
18
+ version_list = increment_version(pubspec_file_path, new_value, constant_name, version_component)
19
19
  end
20
20
 
21
21
  if version_list.length == 2
22
22
  # Store the version name in the shared hash
23
- Actions.lane_context["VERSION_CODE"] = new_value
24
23
  UI.message("Previous Version : #{version_list[0]}")
25
24
  UI.success("Version has been changed to #{version_list[1]}")
26
25
  else
27
26
  UI.user_error!("Updating the version failed !!")
28
27
  end
29
28
 
30
- return new_value
29
+ return version_list[1]
31
30
  end
32
31
 
33
- def self.incrementVersion(path, new_value, constant_name, version_comp = 'version_code')
32
+ def self.increment_version(path, new_value, constant_name, version_comp = 'version_code')
34
33
  unless File.file?(path)
35
34
  UI.user_error!("No file exist at path: (#{path})!")
36
35
  return -1
@@ -42,7 +41,7 @@ module Fastlane
42
41
  temp_file = Tempfile.new('fastlaneIncrementVersionCode')
43
42
  File.open(path, 'r') do |file|
44
43
  file.each_line do |line|
45
- if line.include?("#{constant_name}:") and found_version_code == "false"
44
+ if line.include?("#{constant_name}:") && found_version_code == "false"
46
45
 
47
46
  UI.message(" -> line: (#{line})!")
48
47
  old_version_name = get_version_name(line)
@@ -51,10 +50,38 @@ module Fastlane
51
50
  new_version_name = old_version_name
52
51
 
53
52
  if version_comp == 'version_code'
54
- new_version_code = increment_version_code(old_version_code, new_value)
53
+ if new_value.instance_of?(Integer)
54
+ new_value = new_value.to_s
55
+ end
56
+ if new_value.nil? || (is_int(new_value) && new_value.to_i > 0)
57
+ new_version_code = increment_version_code(old_version_code, new_value)
58
+ else
59
+ UI.user_error!("Invalid version code.\nVersion code should be a positve integer")
60
+ end
55
61
 
56
62
  elsif ['patch', 'major', 'minor'].include?(version_comp)
57
- new_version_name = increment_version_name(old_version_name, version_comp, new_value)
63
+ if new_value.instance_of?(Integer)
64
+ new_value = new_value.to_s
65
+ end
66
+ if new_value.nil? || (is_int(new_value) && new_value.to_i >= 0)
67
+ new_version_name = increment_version_name(old_version_name, version_comp, new_value)
68
+ else
69
+ UI.user_error!("Invalid value.\nPatch, Minor, Major values should be a positve integer or 0")
70
+ end
71
+
72
+ elsif version_comp == 'version_name'
73
+ if matches_version_name_pattern?(new_value)
74
+ new_version_name = new_value
75
+ else
76
+ UI.user_error!("Invalid version name.\n Version name mustbe in the from major.minor.patch (eg 1.2.3)")
77
+ end
78
+ elsif version_comp == 'version'
79
+ if matches_version_pattern?(new_value)
80
+ new_version_name = get_version_name(new_value)
81
+ new_version_code = get_version_code(new_value)
82
+ else
83
+ UI.user_error!("Invalid version.\n Version mustbe in the from major.minor.patch+build_number (eg 1.2.3+1021)")
84
+ end
58
85
  else
59
86
  UI.user_error!("Invalid version component.\nVersion Component must be any one of these -> version_code, patch, minor,major")
60
87
  end
@@ -64,8 +91,9 @@ module Fastlane
64
91
  if !!(new_version_code =~ /\A[-+]?[0-9]+\z/)
65
92
  line.replace(line.sub(old_verison, new_version))
66
93
  found_version_code = "true"
94
+ update_lane_context(new_version)
95
+ temp_file.puts(line)
67
96
  end
68
- temp_file.puts(line)
69
97
  else
70
98
  temp_file.puts(line)
71
99
  end
@@ -84,13 +112,38 @@ module Fastlane
84
112
  return -1
85
113
  end
86
114
 
115
+ def self.update_lane_context(new_version)
116
+ version_name = get_version_name(new_version)
117
+ major, minor, patch = get_patch_minor_major(version_name)
118
+ Actions.lane_context["VERSION"] = new_version
119
+ Actions.lane_context["VERSION_NAME"] = version_name
120
+ Actions.lane_context["VERSION_CODE"] = get_version_code(new_version)
121
+ Actions.lane_context["PATCH"] = patch
122
+ Actions.lane_context["MINOR"] = minor
123
+ Actions.lane_context["MAJOR"] = major
124
+ end
125
+
126
+ def self.matches_version_pattern?(version)
127
+ pattern = /^\d+\.\d+\.\d+\+\d+$/
128
+ pattern.match?(version.to_s)
129
+ end
130
+
131
+ def self.matches_version_name_pattern?(version)
132
+ pattern = /^\d+\.\d+\.\d+$/
133
+ pattern.match?(version.to_s)
134
+ end
135
+
87
136
  def self.get_version_code(line)
88
137
  version_components = line.strip.split('+')
89
138
  return version_components[version_components.length - 1].tr("\"", "")
90
139
  end
91
140
 
92
- def self.increment_version_code(version, new_version_code = -1)
93
- if new_version_code <= 0
141
+ def self.get_patch_minor_major(version_name)
142
+ return version_name.split(".")
143
+ end
144
+
145
+ def self.increment_version_code(version, new_version_code = nil)
146
+ if new_version_code.nil?
94
147
  new_version_code = version.to_i + 1
95
148
  end
96
149
  return new_version_code.to_s
@@ -104,10 +157,7 @@ module Fastlane
104
157
  end
105
158
 
106
159
  def self.increment_version_name(version_name, version_component = 'patch', new_value)
107
- if new_value < 0
108
- new_value = nil
109
- end
110
- major, minor, patch = version_name.split(".")
160
+ major, minor, patch = get_patch_minor_major(version_name)
111
161
  if version_component == 'major'
112
162
  major = new_value || (major.to_i + 1)
113
163
  minor = 0
@@ -121,6 +171,10 @@ module Fastlane
121
171
  return "#{major}.#{minor}.#{patch}"
122
172
  end
123
173
 
174
+ def self.is_int(value)
175
+ return value.to_i.to_s == value
176
+ end
177
+
124
178
  def self.description
125
179
  "Effortlessly manage and update your flutter project version."
126
180
  end
@@ -134,7 +188,6 @@ module Fastlane
134
188
  end
135
189
 
136
190
  def self.details
137
- # Optional:
138
191
  "Flutter versioner is a powerful fastlane plugin designed to simplify the management of flutter project version. With this you can easily update project version to any specified major,minor,or patch level as well as adjust the version code/build number."
139
192
  end
140
193
 
@@ -143,21 +196,21 @@ module Fastlane
143
196
  FastlaneCore::ConfigItem.new(key: :version_component,
144
197
  env_name: "FLUTTERVERSIONER_VERSION_COMPONENT",
145
198
  description: "The component of the version to be updated, version format : major.minor.patch+version_code. (default : version_code)",
146
- optional: true,
199
+ optional: false,
147
200
  type: String,
148
201
  default_value: "version_code"),
149
202
  FastlaneCore::ConfigItem.new(key: :pubspec_file_path,
150
203
  env_name: "FLUTTERVERSIONER_PUBSPEC_FILE_PATH",
151
- description: "The relative path to the pubspec file containing the version parameter (default:app/build.gradle)",
152
- optional: true,
204
+ description: "The relative path to the pubspec file containing the version parameter (default:../pubspec.yaml)",
205
+ optional: false,
153
206
  type: String,
154
- default_value: nil),
207
+ default_value: "../pubspec.yaml"),
155
208
  FastlaneCore::ConfigItem.new(key: :value,
156
209
  env_name: "FLUTTERVERSIONER_VALUE",
157
210
  description: "Change to a specific version (optional)",
158
211
  optional: true,
159
- type: Integer,
160
- default_value: -1),
212
+ type: String,
213
+ default_value: nil),
161
214
  FastlaneCore::ConfigItem.new(key: :ext_constant_name,
162
215
  env_name: "FLUTTERVERSIONER_EXT_CONSTANT_NAME",
163
216
  description: "If the version code is set in an ext constant, specify the constant name (optional)",
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module FlutterVersioner
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-flutter_versioner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abhijith K
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-09 00:00:00.000000000 Z
11
+ date: 2024-06-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: iamabhijith.k@gmail.com