class Schmersion::Releaser

Constants

COLORS

Public Class Methods

new(repo, **options) click to toggle source
# File lib/schmersion/releaser.rb, line 10
def initialize(repo, **options)
  @repo = repo
  @options = options
  @exports = {}
end

Public Instance Methods

release() click to toggle source
# File lib/schmersion/releaser.rb, line 16
def release
  check_for_for_existing_version
  generate_exports
  preview_exports
  save_exports
  commit
  tag
  display_prompt
end

Private Instance Methods

action(action, text) { || ... } click to toggle source
# File lib/schmersion/releaser.rb, line 122
def action(action, text)
  yield unless dry_run?
  print "#{action}: ".colorize(action_color)
  puts text
end
action_color() click to toggle source
# File lib/schmersion/releaser.rb, line 118
def action_color
  dry_run? ? :magenta : :green
end
check_for_for_existing_version() click to toggle source
# File lib/schmersion/releaser.rb, line 28
def check_for_for_existing_version
  if @repo.version?(version.version)
    raise Error, "#{version.version} already exists in this repository"
  end

  true
end
commit() click to toggle source
# File lib/schmersion/releaser.rb, line 71
def commit
  return if skip?(:commit)

  action 'commit', version.commit_message do
    @repo.repo.reset
    @exports.each_key do |formatter|
      @repo.repo.add(formatter.filename)
    end
    @repo.repo.commit(version.commit_message, allow_empty: true)
  end
end
display_prompt() click to toggle source
# File lib/schmersion/releaser.rb, line 91
def display_prompt
  puts
  puts "Release of #{version.version} completed".white.on_green

  return if skip?(:tag) && skip?(:commit)

  print 'Now run '
  print "git push --tags origin #{@repo.current_branch}".cyan
  puts ' to publish'
end
dry_run?() click to toggle source
# File lib/schmersion/releaser.rb, line 114
def dry_run?
  @options[:dry_run] == true
end
generate_exports() click to toggle source
# File lib/schmersion/releaser.rb, line 36
def generate_exports
  return if skip?(:export)

  @exports = {}
  @repo.config.exports.each do |formatter|
    output = formatter.generate(@repo, version)
    @exports[formatter] = output
  end
  @exports
end
preview_exports() click to toggle source
# File lib/schmersion/releaser.rb, line 47
def preview_exports
  return if skip?(:export)
  return unless dry_run?

  @exports.each_with_index do |(formatter, output), index|
    color = COLORS[index % COLORS.size]
    puts formatter.filename.colorize(color: :white, background: color)
    output.split("\n").each do |line|
      print '> '.colorize(color: color)
      puts line
    end
  end
end
save_exports() click to toggle source
# File lib/schmersion/releaser.rb, line 61
def save_exports
  return if skip?(:export)

  @exports.each do |formatter, output|
    action 'save', formatter.filename do
      formatter.insert(output)
    end
  end
end
skip?(type) click to toggle source
# File lib/schmersion/releaser.rb, line 128
def skip?(type)
  return false if @options[:skips].nil?

  @options[:skips].include?(type)
end
tag() click to toggle source
# File lib/schmersion/releaser.rb, line 83
def tag
  return if skip?(:tag)

  action 'tag', version.version.to_s do
    @repo.repo.add_tag(version.version.to_s)
  end
end
version() click to toggle source
# File lib/schmersion/releaser.rb, line 102
def version
  @version ||= begin
    @repo.pending_version(
      override_version: @options[:version],
      version_options: {
        pre: @options[:pre],
        breaking_change_not_major: @repo.config.version_options[:breaking_change_not_major]
      }
    )[1]
  end
end