module Reap class Project # Update VERSION stamp file. # # This file is either called VERSION, or meta/version # (case-insensitive and with optional .txt extension). # # The format of the files is: # # x.y.z status (date) # # For exmaple: # # 1.2.4 alpha (2008-10-10) # # On the command line: # # --major will bump the major number # --minor will bump the minor number # --tiny will bump the tiny number # --teeny will bump the teeny number # # One can alternately specify the entire version: # # --version=x.y.z # # As well as status: # # --status=(alpha, beta, rc1, rc2, ...) # # TODO: Should we also update a lib/version.rb file? # TODO: Considerding createing a standard status marker (a=alpha, b=beta, r=release candidate) # So a version would read, eg. 1.2.4a, or with status number, eg. 1.2.4r1). def stamp(options={}) version = options['version'] status = options['status'] bump = [options['major'], options['minor'], options['tiny'], options['teeny']] abort "Specify bumps or version, not both." if bump and version #options = configure_options(options, 'stamp') version = version || metadata.version || '0.0.0' status = status || metadata.status || '0.0.0' if bump.any?{ |x| x } points = [] version.to_s.split(/[.]/).each_with_index do |x, i| points[i] = (bump[i] ? x.to_i + 1 : x).to_s end version = points.join('.').sub(/[.0]$/,'') else abort "Invalid version -- #{version}" unless String===version && /^[0-9]/ =~ version end meta = File.directory?('meta') file = glob('{,meta/}version{,.txt}', File::FNM_CASEFOLD).first file = (meta ? 'meta/version' : 'VERSION') unless file text = "#{version} #{status} (#{Time.now.strftime('%Y-%m-%d')})" if File.exist?(file) old_text = File.read(file).strip old_version, old_status, old_date = *old_text.split(/\s/) if old_version == "#{version}" && old_status == status puts old_text return end end if dryrun? puts "echo '#{text}' > #{file}" else write(file, text) puts text puts "#{file} updated." metadata.version = version metadata.status = status metadata.released = Time.now end # TODO: Stamp .roll if roll file exists. # should we read current .roll file and use as defaults? if File.exist?('.roll') str = [] str << "name = #{metadata.name}" str << "version = #{metadata.version}" str << "status = #{metadata.status}" str << "date = #{metadata.date}" str << "default = #{metadata.default}" str << "libpath = #{metadata.libpath}" # File.open('.roll','w'){ |f| f << str.join("\n") } end end end end