Sha256: 96310b590a7f9897a70f74736b1fec40efe7ab37126e04397d343f8250ab72ca

Contents?: true

Size: 1.87 KB

Versions: 1

Compression:

Stored size: 1.87 KB

Contents

module RokuBuilder

  # Updates or retrives build version
  class ManifestManager

    # Updates the build version in the manifest file
    # @param root_dir [String] Path to the root directory for the app
    # @return [String] Build version on success, empty string otherwise
    def self.update_build(root_dir:)

      build_version = ""

      temp_file = Tempfile.new('manifest')
      path = File.join(root_dir, 'manifest')
      begin
        File.open(path, 'r') do |file|
          file.each_line do |line|
            if line.include?("build_version")

              #Update build version.
              build_version = line.split(".")
              if 2 == build_version.length
                iteration = build_version[1].to_i + 1
                build_version[0] = Time.now.strftime("%m%d%y")
                build_version[1] = iteration
                build_version = build_version.join(".")
              else
                #Use current date.
                build_version = Time.now.strftime("%m%d%y")+".1"
              end
              temp_file.puts "build_version=#{build_version}"
            else
              temp_file.puts line
            end
          end
        end
        temp_file.rewind
        FileUtils.cp(temp_file.path, path)
      ensure
        temp_file.close
        temp_file.unlink
      end
      build_version
    end

    # Retrive the build version from the manifest file
    # @param root_dir [String] Path to the root directory for the app
    # @return [String] Build version on success, empty string otherwise
    def self.build_version(root_dir:)
      path = File.join(root_dir, 'manifest')
      build_version = ""
      File.open(path, 'r') do |file|
        file.each_line do |line|
          if line.include?("build_version")
            build_version = line.split("=")[1].chomp
          end
        end
      end
      build_version
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roku_builder-3.3.4 lib/roku_builder/manifest_manager.rb