@@ -88,6 +88,80 @@ namespace "gem" do
8888 end
8989end
9090
91+ def change_version ( &block )
92+ version = GEMSPEC . version
93+ version_file = 'bcrypt_pbkdf.gemspec'
94+ raise "No version found" if version . nil?
95+ final = version . segments . take_while { |i | i . is_a? ( Integer ) } . to_a
96+ pre = version . segments . drop_while { |i | i . is_a? ( Integer ) } . to_a . join ( "" )
97+ pre = nil if pre . empty?
98+ tiny = final . last
99+ result = block [ pre : pre , tiny : tiny ]
100+ raise ArgumentError , "Version change logic should always return a pre" unless result . key? ( :pre )
101+
102+ puts "result: #{ result . inspect } "
103+
104+ new_pre = result [ :pre ] || [ ]
105+ new_tiny = result [ :tiny ] || tiny
106+ final [ -1 ] = new_tiny
107+ new_version = Gem ::Version . new ( [ final , *new_pre ] . join ( "." ) )
108+
109+ found = false
110+ File . open ( "#{ version_file } .new" , "w" ) do |f |
111+ File . readlines ( version_file ) . each do |line |
112+ match = /^(\s +s\. version\s *=\s *\' )[\d [a-z]\. ]+(\' \s *)$/ . match ( line )
113+ if match
114+ prefix = match [ 1 ]
115+ postfix = match [ 2 ]
116+ new_line = "#{ prefix } #{ new_version . to_s } #{ postfix } "
117+ puts "Changing:\n - #{ line } + #{ new_line } "
118+ line = new_line
119+ found = true
120+ end
121+ f . write ( line )
122+ end
123+ raise ArgumentError , "Cound not find version line in #{ version_file } " unless found
124+ end
125+
126+ FileUtils . mv version_file , "#{ version_file } .old"
127+ FileUtils . mv "#{ version_file } .new" , version_file
128+ end
129+
130+ namespace :vbump do
131+ desc "Final release"
132+ task :final do
133+ change_version do |pre :, tiny :|
134+ _ = tiny
135+ if pre . nil?
136+ { tiny : tiny + 1 , pre : nil }
137+ else
138+ raise ArgumentError , "Unexpected pre: #{ pre } " if pre . nil?
139+
140+ { pre : nil }
141+ end
142+ end
143+ end
144+
145+ desc "Increment prerelease"
146+ task :pre , [ :type ] do |_t , args |
147+ change_version do |pre :, tiny :|
148+ puts " PRE => #{ pre . inspect } "
149+ match = /^([a-z]+)(\d +)/ . match ( pre )
150+ raise ArgumentError , "Unexpected pre: #{ pre } " if match . nil? && args [ :type ] . nil?
151+
152+ if match . nil? || ( !args [ :type ] . nil? && args [ :type ] != match [ 1 ] )
153+ if pre . nil?
154+ { pre : "#{ args [ :type ] } 1" , tiny : tiny + 1 }
155+ else
156+ { pre : "#{ args [ :type ] } 1" }
157+ end
158+ else
159+ { pre : "#{ match [ 1 ] } #{ match [ 2 ] . to_i + 1 } " }
160+ end
161+ end
162+ end
163+ end
164+
91165task "package" => cross_platforms . map { |p | "gem:#{ p } " } # "package" task for all the native platforms
92166
93167Rake ::Task [ "package" ] . prerequisites . prepend ( "compile" )
0 commit comments