Sha256: f2d6a244be0ee2f89a8c015a420d56542c04b37245496b5f7549290e31ff060b
Contents?: true
Size: 1.88 KB
Versions: 1
Compression:
Stored size: 1.88 KB
Contents
# frozen_string_literal: true module Makit VERSION = "0.0.40" class Version # given an array of version strings, return the highest version def self.get_highest_version(versions) versions.sort { |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }.last end def self.get_version_from_file(path) if(!File.exist?(path)) raise "file #{path}does not exist" end extension = File.extname(path) #switch = extension.downcase #case switch #if extension == ".csproj" switch = extension.downcase case switch when ".csproj" Makit::Version.detect_from_file(path, /<Version>([-\w\d.]+)</) when ".wxs" Makit::Version.detect_from_file(path, / Version="([\d\.]+)"/) else raise "unrecognized file type" end end def self.detect_from_file(filename, regex) if File.exist?(filename) match = IO.read(filename).match(regex) match.captures[0] if !match.nil? && match.captures.length.positive? else raise "unable to find version in #{filename}" end end def self.set_version_in_file(filename, version) text = IO.read(filename) new_text = text new_text = text.gsub(/version\s?=\s?['|"]([.\d]+)['|"]/, "version='#{version}'") if filename.include?(".gemspec") new_text = text.gsub(/<Version>([-\w\d.]+)</, "<Version>#{version}<") if filename.include?(".csproj") new_text = text.gsub(/<version>([-\w\d.]+)</, "<version>#{version}<") if filename.include?(".nuspec") new_text = text.gsub(/ Version="([\d\.]+)"/, " Version=\"#{version}\"") if filename.include?(".wxs") new_text = text.gsub(/version\s+=\s+['"]([\w.]+)['"]/, "version=\"#{version}\"") if filename.include?(".toml") File.open(filename, "w") { |f| f.write(new_text) } if new_text != text end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
makit-0.0.40 | lib/makit/version.rb |