fastlane-plugin-flutter_versioner 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 35af839b7b1ec389092f33854ca32c634cd8321be82b187a2e26fc50e0b670d0
4
+ data.tar.gz: faf2a30fab6e9e5eb57f0be5e6023af38356cee9c99b1c6e2b9498cb9a9201a5
5
+ SHA512:
6
+ metadata.gz: d3df3a6c5893dc86c2acc421ba23bacbe2b046a36dba7e1ec180829985048660433901eda8bdb4d613bed5ae465369c1e4fd1701c9a6f728be495bbbc51be9a5
7
+ data.tar.gz: 4e42e6a3e2c8399dbcb2c57fbe0a85282e4ac6355952b2c0b3252f13f977211623627c3d422b74fbd52f354419b6a77a65ef120c1c16b314d7c7f720e4a9db00
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Abhijith K <iamabhijith.k@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # flutter_versioner plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-flutter_versioner)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-flutter_versioner`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin flutter_versioner
11
+ ```
12
+
13
+ ## About flutter_versioner
14
+
15
+ 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.
16
+ ## Syntax
17
+ ```
18
+ flutter_versioner(pubspec_file_path:"../pubspec.yaml",
19
+ version_component:"major"
20
+ )
21
+ ```
22
+
23
+ ### Options
24
+ 1. pubspec_file_path - relative path to the pubspec file where the version is maintained
25
+ 2. version_component - the component of version that need to be modified - **major.minor.patch+version_code**
26
+
27
+ Values
28
+ - major
29
+ - minor
30
+ - patch
31
+ - version_code (default value)
32
+ 3. value - the value given will be used to set the given version component. If `value` is not given the version compenent will be incremented by `1`
33
+
34
+ ## Example
35
+
36
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins`.
37
+
38
+ ### 1. VERSION CODE/BUILD NUMBER
39
+ #### a. Update the flutter version code by 1
40
+
41
+ eg 1.1.1+1 -> 1.1.1+2
42
+
43
+ ```
44
+ flutter_versioner(pubspec_file_path:"./example/pubspec.yaml",
45
+ version_component:"version_code")
46
+ ```
47
+ if you dont specify `version_component` version_code will the default value
48
+
49
+ ```
50
+ flutter_versioner(pubspec_file_path:"./example/pubspec.yaml",
51
+ value:"9")
52
+ ```
53
+
54
+ #### b. Set the flutter version - patch to `value` given
55
+
56
+ eg 1.1.1+1 -> 1.1.1+100
57
+ ```
58
+ flutter_versioner(pubspec_file_path:"./example/pubspec.yaml",
59
+ value:"100",
60
+ version_component:"version_code")
61
+ ```
62
+ ### 2. VERSION - PATCH
63
+ #### a. Update the flutter version - patch by 1
64
+
65
+ eg 1.1.1 -> 1.1.2
66
+
67
+ ```
68
+ flutter_versioner(pubspec_file_path:"./example/pubspec.yaml",
69
+ version_component:"patch")
70
+ ```
71
+ #### b. Set the flutter version - patch to `value` given
72
+
73
+ eg 1.1.1 -> 1.1.100
74
+
75
+ ```
76
+ flutter_versioner(pubspec_file_path:"./example/pubspec.yaml",
77
+ value:"100",
78
+ version_component:"patch")
79
+ ```
80
+
81
+ ### 3. VERSION - MINOR
82
+ #### a. Update the flutter version - minor by 1 (also reset patch to 0)
83
+
84
+ eg 1.1.1 -> 1.2.0
85
+ ```
86
+ flutter_versioner(pubspec_file_path:"./example/pubspec.yaml",
87
+ version_component:"minor")
88
+ ```
89
+
90
+ #### b. Set the flutter version - major to `value` given (also reset patch to 0)
91
+
92
+ eg 1.1.1 -> 1.100.0
93
+ ```
94
+ flutter_versioner(pubspec_file_path:"./example/pubspec.yaml",
95
+ value:"100",
96
+ version_component:"minor")
97
+ ```
98
+
99
+ ### 4. VERSION - MAJOR
100
+ #### a. Update the flutter version - major by 1 (also reset minor and patch)
101
+
102
+ eg 1.1.1 -> 2.0.0
103
+
104
+ ```
105
+ flutter_versioner(pubspec_file_path:"./example/pubspec.yaml",
106
+ version_component:"major")
107
+ ```
108
+
109
+ #### b. Set the flutter version - major to `value` given (also reset minor and patch)
110
+
111
+ eg 1.1.1 -> 100.0.0
112
+
113
+ ```
114
+ flutter_versioner(pubspec_file_path:"./example/pubspec.yaml",
115
+ value:"100",
116
+ version_component:"major")
117
+ ```
118
+
119
+
120
+ ## Run tests for this plugin
121
+
122
+ To run both the tests, and code style validation, run
123
+
124
+ ```
125
+ rake
126
+ ```
127
+
128
+ To automatically fix many of the styling issues, use
129
+ ```
130
+ rubocop -a
131
+ ```
132
+
133
+ ## Issues and Feedback
134
+
135
+ For any other issues and feedback about this plugin, please submit it to this repository.
136
+
137
+ ## Troubleshooting
138
+
139
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
140
+
141
+ ## Using _fastlane_ Plugins
142
+
143
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
144
+
145
+ ## About _fastlane_
146
+
147
+ _fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
148
+
149
+ ## Meet the Team
150
+
151
+ <b>Abhijith Konnayil</b><br>
152
+ GitHub: [abhijithkonnayil](https://github.com/abhijithkonnayil)<br>
153
+ LinkedIn: [abhijithkonnayil](https://www.linkedin.com/in/abhijithkonnayil)<br>
154
+ Website: [abhijith.web.app](https://abhijith.web.app/)
@@ -0,0 +1,179 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/flutter_versioner_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class FlutterVersionerAction < Action
7
+ def self.run(params)
8
+ new_value ||= params[:value]
9
+ constant_name ||= params[:ext_constant_name]
10
+ pubspec_file_path ||= params[:pubspec_file_path]
11
+ version_component ||= params[:version_component]
12
+ version_list = []
13
+
14
+ if pubspec_file_path.nil?
15
+ UI.user_error!("The pubspec file path given. Pass the `pubspec_file_path` to the action")
16
+ else
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)
19
+ end
20
+
21
+ if version_list.length == 2
22
+ # Store the version name in the shared hash
23
+ Actions.lane_context["VERSION_CODE"] = new_value
24
+ UI.message("Previous Version : #{version_list[0]}")
25
+ UI.success("Version has been changed to #{version_list[1]}")
26
+ else
27
+ UI.user_error!("Updating the version failed !!")
28
+ end
29
+
30
+ return new_value
31
+ end
32
+
33
+ def self.incrementVersion(path, new_value, constant_name, version_comp = 'version_code')
34
+ unless File.file?(path)
35
+ UI.user_error!("No file exist at path: (#{path})!")
36
+ return -1
37
+ end
38
+ begin
39
+ found_version_code = "false"
40
+ new_version = nil
41
+ old_verison = nil
42
+ temp_file = Tempfile.new('fastlaneIncrementVersionCode')
43
+ File.open(path, 'r') do |file|
44
+ file.each_line do |line|
45
+ if line.include?("#{constant_name}:") and found_version_code == "false"
46
+
47
+ UI.message(" -> line: (#{line})!")
48
+ old_version_name = get_version_name(line)
49
+ old_version_code = get_version_code(line)
50
+ new_version_code = old_version_code
51
+ new_version_name = old_version_name
52
+
53
+ if version_comp == 'version_code'
54
+ new_version_code = increment_version_code(old_version_code, new_value)
55
+
56
+ elsif ['patch', 'major', 'minor'].include?(version_comp)
57
+ new_version_name = increment_version_name(old_version_name, version_comp, new_value)
58
+ else
59
+ UI.user_error!("Invalid version component.\nVersion Component must be any one of these -> version_code, patch, minor,major")
60
+ end
61
+ new_version = "#{new_version_name}+#{new_version_code}"
62
+ old_verison = "#{old_version_name}+#{old_version_code}"
63
+
64
+ if !!(new_version_code =~ /\A[-+]?[0-9]+\z/)
65
+ line.replace(line.sub(old_verison, new_version))
66
+ found_version_code = "true"
67
+ end
68
+ temp_file.puts(line)
69
+ else
70
+ temp_file.puts(line)
71
+ end
72
+ end
73
+ file.close
74
+ end
75
+ temp_file.rewind
76
+ temp_file.close
77
+ FileUtils.mv(temp_file.path, path)
78
+ temp_file.unlink
79
+ end
80
+ if found_version_code == "true"
81
+ return [old_verison, new_version]
82
+ end
83
+
84
+ return -1
85
+ end
86
+
87
+ def self.get_version_code(line)
88
+ version_components = line.strip.split('+')
89
+ return version_components[version_components.length - 1].tr("\"", "")
90
+ end
91
+
92
+ def self.increment_version_code(version, new_version_code = -1)
93
+ if new_version_code <= 0
94
+ new_version_code = version.to_i + 1
95
+ end
96
+ return new_version_code.to_s
97
+ end
98
+
99
+ def self.get_version_name(line)
100
+ version_components_ver_string__build_no_list = line.strip.split('+')
101
+ version_components_ver_key__maj_min_pat = version_components_ver_string__build_no_list[0].split(":")
102
+ version_name = version_components_ver_key__maj_min_pat[version_components_ver_key__maj_min_pat.length - 1].strip
103
+ return version_name
104
+ end
105
+
106
+ 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(".")
111
+ if version_component == 'major'
112
+ major = new_value || (major.to_i + 1)
113
+ minor = 0
114
+ patch = 0
115
+ elsif version_component == 'minor'
116
+ minor = new_value || (minor.to_i + 1)
117
+ patch = 0
118
+ elsif version_component == "patch"
119
+ patch = new_value || (patch.to_i + 1)
120
+ end
121
+ return "#{major}.#{minor}.#{patch}"
122
+ end
123
+
124
+ def self.description
125
+ "Effortlessly manage and update your flutter project version."
126
+ end
127
+
128
+ def self.authors
129
+ ["Abhijith K"]
130
+ end
131
+
132
+ def self.return_value
133
+ # If your method provides a return value, you can describe here what it does
134
+ end
135
+
136
+ def self.details
137
+ # Optional:
138
+ "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
+ end
140
+
141
+ def self.available_options
142
+ [
143
+ FastlaneCore::ConfigItem.new(key: :version_component,
144
+ env_name: "FLUTTERVERSIONER_VERSION_COMPONENT",
145
+ description: "The component of the version to be updated, version format : major.minor.patch+version_code. (default : version_code)",
146
+ optional: true,
147
+ type: String,
148
+ default_value: "version_code"),
149
+ FastlaneCore::ConfigItem.new(key: :pubspec_file_path,
150
+ 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,
153
+ type: String,
154
+ default_value: nil),
155
+ FastlaneCore::ConfigItem.new(key: :value,
156
+ env_name: "FLUTTERVERSIONER_VALUE",
157
+ description: "Change to a specific version (optional)",
158
+ optional: true,
159
+ type: Integer,
160
+ default_value: -1),
161
+ FastlaneCore::ConfigItem.new(key: :ext_constant_name,
162
+ env_name: "FLUTTERVERSIONER_EXT_CONSTANT_NAME",
163
+ description: "If the version code is set in an ext constant, specify the constant name (optional)",
164
+ optional: true,
165
+ type: String,
166
+ default_value: "version")
167
+ ]
168
+ end
169
+
170
+ def self.is_supported?(platform)
171
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
172
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
173
+ #
174
+ # [:ios, :mac, :android].include?(platform)
175
+ true
176
+ end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,16 @@
1
+ require 'fastlane_core/ui/ui'
2
+
3
+ module Fastlane
4
+ UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI)
5
+
6
+ module Helper
7
+ class FlutterVersionerHelper
8
+ # class methods that you define here become available in your action
9
+ # as `Helper::FlutterVersionerHelper.your_method`
10
+ #
11
+ def self.show_message
12
+ UI.message("Hello from the flutter_versioner plugin helper!")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module FlutterVersioner
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/flutter_versioner/version'
2
+
3
+ module Fastlane
4
+ module FlutterVersioner
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::FlutterVersioner.all_classes.each do |current|
15
+ require current
16
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-flutter_versioner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Abhijith K
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-06-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: iamabhijith.k@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - README.md
21
+ - lib/fastlane/plugin/flutter_versioner.rb
22
+ - lib/fastlane/plugin/flutter_versioner/actions/flutter_versioner_action.rb
23
+ - lib/fastlane/plugin/flutter_versioner/helper/flutter_versioner_helper.rb
24
+ - lib/fastlane/plugin/flutter_versioner/version.rb
25
+ homepage: https://github.com/abhijithkonnayil/fastlane-plugin-flutter_versioner
26
+ licenses:
27
+ - MIT
28
+ metadata:
29
+ rubygems_mfa_required: 'true'
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '2.6'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubygems_version: 3.4.20
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Effortlessly manage and update your flutter project version.
49
+ test_files: []