Sha256: 4d63ed083491eef05375838dfa511097b209b8815256d30f9c3774dab88dcd6f

Contents?: true

Size: 932 Bytes

Versions: 1

Compression:

Stored size: 932 Bytes

Contents

require "bundler/ui/shell"

module Gemsmith
  module Rake
    # Provides gem build functionality. Meant to be wrapped in Rake tasks.
    class Build
      def initialize shell: Bundler::UI::Shell.new, kernel: Kernel
        @shell = shell
        @kernel = kernel
      end

      def table_of_contents
        if kernel.system("command -v doctoc > /dev/null")
          kernel.system %(doctoc --title "# Table of Contents" README.md)
        else
          shell.error error_message
          kernel.exit 1
        end
      end

      def clean!
        FileUtils.rm_rf "pkg"
        shell.info "Gem artifacts cleaned."
      end

      private

      attr_reader :shell, :kernel

      def error_message
        url = "https://github.com/thlorenz/doctoc"
        command = "npm install --global doctoc"

        "Unable to update README Table of Contents, please install DocToc (#{url}): #{command}."
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gemsmith-5.6.0 lib/gemsmith/rake/build.rb