flutter_version_tool 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/fvt +48 -0
  3. data/lib/flutter_version_tool.rb +140 -79
  4. metadata +7 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbad9eef2f7d73d4b77b3e7fa7ae33285be8b677c9e81dde913fe69eceaf041a
4
- data.tar.gz: 64df2ffc684d9115e6672181d2d18fd4b0ce2ccf3790593782b7b5fb8c6cacde
3
+ metadata.gz: a1782e84416b5417e0f7906fd83283e00353631e6533afc629e4eddbe73bce69
4
+ data.tar.gz: 8b85c7cd81d7f7889ecf1e07b1764c2de6dc019792985f06357292a2c158bfdf
5
5
  SHA512:
6
- metadata.gz: c94f632a80b9787e6cc4596961c68ba48d906a9493f9ae41d59e629a26af2f9febf8490d633bc98e2a6e47acff7d32e43c114145f84ecc889a82e7b08a96cd28
7
- data.tar.gz: dfdb53d32f0c66ac0da153c02379149d5fdad6cf606e3063ac79696bc282a774bbd1181ab44ecaef7556c33e7cd49b12a52e4c3400a0a3368802e797cd5ba013
6
+ metadata.gz: ba1449c5956148662132dbb6ab9e636d71bbee328c6f6650ae9f0f66b200affd63facf7fab828f254a3d0f264563fed87c11dded7afd566a09542b445c00aa1d
7
+ data.tar.gz: a1085aa3c7ba6621bada85118dc60d403549677d0a83915350188893e7ec5af8916a94d5989b7d3b51b7263c8dbae5df5a7aa73da78d9353c6e9cdec841ae92b
data/bin/fvt ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'flutter_version_tool'
5
+
6
+ class FVTExecutor
7
+
8
+ attr_accessor :options, :changingVersion, :changingBuild
9
+
10
+ def initialize
11
+ self.options = {}
12
+ self.changingVersion = false
13
+ self.changingBuild = false
14
+ end
15
+
16
+ def parse
17
+ OptionParser.new do |parser|
18
+ parser.banner = "Usage: fvt [options] version [pubspec path]"
19
+ parser.on("-v VERSION", "versionName value") do |v|
20
+ self.options[:version] = v
21
+ self.changingVersion = true
22
+ end
23
+ parser.on("-b BUILD", "versionCode value") do |b|
24
+ self.options[:build] = b
25
+ self.changingBuild = true
26
+ end
27
+ parser.on("--path PATH", "pubspec.yml path") do |p|
28
+ self.options[:path] = p
29
+ end
30
+ end.parse!
31
+ end
32
+
33
+ end
34
+
35
+ executor = FVTExecutor.new
36
+ executor.parse
37
+
38
+ fvt = executor.options[:path].nil? ? FlutterVersionTool.new : FlutterVersionTool.new(executor.options[:path])
39
+ p "Current pubspec app version is " + fvt.vFull
40
+
41
+ if executor.changingVersion
42
+ fvt.changeVersionName(executor.options[:version]);
43
+ p "New versionName (version): " + executor.options[:version]
44
+ end
45
+ if executor.changingBuild
46
+ fvt.changeVersionCode(executor.options[:build]);
47
+ p "New versionCode (build): " + executor.options[:build]
48
+ end
@@ -1,88 +1,149 @@
1
+ require 'yaml'
2
+
1
3
  class FlutterVersionTool
2
- attr_reader :pubspecPath, :vName, :vCode, :vMajor, :vMinor, :vPatch
3
-
4
- def vFull
5
- return "#{@vMajor.to_s}.#{@vMinor.to_s}.#{@vPatch.to_s}+#{@vCode.to_s}"
4
+ attr_reader :pubspecPath, :vName, :vCode, :vMajor, :vMinor, :vPatch
5
+
6
+ def vFull
7
+ return "#{@vMajor.to_s}.#{@vMinor.to_s}.#{@vPatch.to_s}+#{@vCode.to_s}"
8
+ end
9
+
10
+ def initialize(path = "pubspec.yaml")
11
+ # Load version from pubspec file
12
+ #
13
+ # Example:
14
+ # >> fvt = FlutterVersionTool.new("some_project/path/pubspec.yaml")
15
+ #
16
+ # Arguments:
17
+ # pubspecPath: (String)
18
+
19
+ @pubspecPath = path
20
+
21
+ begin
22
+ pubspec = YAML::load_file(@pubspecPath)
23
+ rescue
24
+ raise 'Read pubspec.yaml failed'
6
25
  end
7
-
8
- def initialize(path)
9
- @pubspecPath = path
10
-
11
- begin
12
- pubspec = YAML.load_file(@pubspecPath)
13
- rescue
14
- raise 'Read pubspec.yaml failed'
26
+
27
+ version = pubspec["version"]
28
+
29
+ begin
30
+ if not version.include? "+"
31
+ raise
15
32
  end
16
-
17
- version = pubspec["version"]
18
-
19
- begin
20
- if not version.include? "+"
21
- raise
22
- end
23
- v_sections = version.split("+")
24
- @vName = v_sections[0].to_s
25
- @vCode = v_sections[1].to_i
26
- rescue
27
- @noCode = true
28
- @vName = version
29
- @vCode = 0
33
+ v_sections = version.split("+")
34
+ @vName = v_sections[0].to_s
35
+ @vCode = v_sections[1].to_i
36
+ rescue
37
+ @noCode = true
38
+ @vName = version
39
+ @vCode = 0
40
+ end
41
+
42
+ parseSemVer(@vName)
43
+
44
+ # begin
45
+ # if not vName.include? "."
46
+ # raise
47
+ # end
48
+ # vName_sections = @vName.split(".")
49
+ # @vMajor = vName_sections[0].to_i
50
+ # @vMinor = vName_sections[1].to_i
51
+ # if (vName_sections.length() > 2)
52
+ # @vPatch = vName_sections[2].to_i
53
+ # else
54
+ # @vPatch = 0
55
+ # end
56
+ # rescue
57
+ # @vMajor = @vName.to_i
58
+ # @vMinor = 0
59
+ # @vPatch = 0
60
+ # end
61
+
62
+ end
63
+
64
+ private def parseSemVer(pVersion)
65
+ begin
66
+ if not pVersion.include? "."
67
+ raise
30
68
  end
31
-
32
- begin
33
- if not vName.include? "."
34
- raise
35
- end
36
- vName_sections = @vName.split(".")
37
- @vMajor = vName_sections[0].to_i
38
- @vMinor = vName_sections[1].to_i
39
- if (vName_sections.length() > 2)
40
- @vPatch = vName_sections[2].to_i
41
- else
42
- @vPatch = 0
43
- end
44
- rescue
45
- @vMajor = @vName.to_i
46
- @vMinor = 0
47
- @vPatch = 0
69
+ pVersion_sections = pVersion.split(".")
70
+ @vMajor = pVersion_sections[0].to_i
71
+ @vMinor = pVersion_sections[1].to_i
72
+ if (pVersion_sections.length() > 2)
73
+ @vPatch = pVersion_sections[2].to_i
74
+ else
75
+ @vPatch = 0
48
76
  end
49
-
50
- end
51
-
52
- private def commitChanges
53
- fileString = File.read(@pubspecPath)
54
- newFileString = fileString.gsub(/^version:\s.+/, "version: "+self.vFull)
55
- File.write(@pubspecPath, newFileString)
56
- end
57
-
58
- def changeVersionCode(p_code)
59
- @vCode=p_code.to_i
60
- commitChanges
61
- end
62
-
63
- def bumpVersionCode(increment = 1)
64
- @vCode= @vCode+increment
65
- commitChanges
77
+ rescue
78
+ @vMajor = pVersion.to_i
79
+ @vMinor = 0
80
+ @vPatch = 0
66
81
  end
67
-
68
- def bumpVersionName(level = "major", increment)
69
- case level
70
- when "major"
71
- @vMajor=@vMajor+increment
72
- @vMinor=0
73
- @vPatch=0
74
- puts "Bumping major"
75
- when "minor"
76
- @vMinor=@vMinor+increment
77
- @vPatch=0
78
- puts "Bumping minor"
79
- when "patch"
80
- @vPatch=@vPatch+increment
81
- puts "Bumping patch"
82
- else puts "Nope"
83
- end
84
- commitChanges
82
+ end
83
+
84
+ private def commitChanges
85
+ fileString = File.read(@pubspecPath)
86
+ newFileString = fileString.gsub(/^version:\s.+/, "version: " + self.vFull)
87
+ File.write(@pubspecPath, newFileString)
88
+ end
89
+
90
+ def changeVersionName(p_name)
91
+ @vName = p_name.to_s
92
+ parseSemVer(@vName)
93
+ commitChanges
94
+ end
95
+
96
+ def changeVersionCode(p_code)
97
+ # Change version build number directly to any number
98
+ #
99
+ # Example:
100
+ # >> fvt.changeVersionCode(140)
101
+ # Arguments:
102
+ # p_code: (Integer)
103
+
104
+ @vCode = p_code.to_i
105
+ commitChanges
106
+ end
107
+
108
+ def bumpVersionCode(increment = 1)
109
+ # Increment version build number (default by +1)
110
+ #
111
+ # Example:
112
+ # >> fvt.bumpVersionCode(1)
113
+ # Arguments:
114
+ # increment: (Integer)
115
+
116
+ @vCode = @vCode + increment
117
+ commitChanges
118
+ end
119
+
120
+ def bumpVersionName(level = "major", increment = 1)
121
+ # Increment version name semantically (default major version by +1)
122
+ #
123
+ # Example:
124
+ # >> fvt.bumpVersionName("patch")
125
+ # Arguments:
126
+ # level: ("major","minor","patch")
127
+ # increment: (Integer)
128
+
129
+ case level
130
+ when "major"
131
+ @vMajor = @vMajor + increment
132
+ @vMinor = 0
133
+ @vPatch = 0
134
+ puts "Bumping major"
135
+ when "minor"
136
+ @vMinor = @vMinor + increment
137
+ @vPatch = 0
138
+ puts "Bumping minor"
139
+ when "patch"
140
+ @vPatch = @vPatch + increment
141
+ puts "Bumping patch"
142
+ else
143
+ puts "Nope"
85
144
  end
86
-
145
+ commitChanges
87
146
  end
147
+
148
+ end
88
149
 
metadata CHANGED
@@ -1,21 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flutter_version_tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rim Ganiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-18 00:00:00.000000000 Z
11
+ date: 2023-04-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A tool for maintaning Flutter project versioning
14
14
  email: cj_rimix@rambler.ru
15
- executables: []
15
+ executables:
16
+ - fvt
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  files:
20
+ - bin/fvt
19
21
  - lib/flutter_version_tool.rb
20
22
  homepage: https://rubygems.org/gems/flutter_version_tool
21
23
  licenses:
@@ -29,14 +31,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
29
31
  requirements:
30
32
  - - ">="
31
33
  - !ruby/object:Gem::Version
32
- version: '0'
34
+ version: 2.5.1
33
35
  required_rubygems_version: !ruby/object:Gem::Requirement
34
36
  requirements:
35
37
  - - ">="
36
38
  - !ruby/object:Gem::Version
37
39
  version: '0'
38
40
  requirements: []
39
- rubygems_version: 3.3.7
41
+ rubygems_version: 3.4.6
40
42
  signing_key:
41
43
  specification_version: 4
42
44
  summary: Flutter Version Tool