Sha256: eeda91a167c97044d7c428ef4559b53670654640c0c83b137e40dceccce44633

Contents?: true

Size: 1.49 KB

Versions: 27

Compression:

Stored size: 1.49 KB

Contents

# typed: strict
# frozen_string_literal: true

module Tapioca
  module Commands
    class Require < CommandWithoutTracker
      sig do
        params(
          requires_path: String,
          sorbet_config_path: String,
        ).void
      end
      def initialize(requires_path:, sorbet_config_path:)
        @requires_path = requires_path
        @sorbet_config_path = sorbet_config_path

        super()
      end

      private

      sig { override.void }
      def execute
        compiler = Static::RequiresCompiler.new(@sorbet_config_path)
        name = set_color(@requires_path, :yellow, :bold)
        say("Compiling #{name}, this may take a few seconds... ")

        rb_string = compiler.compile
        if rb_string.empty?
          say("Nothing to do", :green)
          return
        end

        # Clean all existing requires before regenerating the list so we update
        # it with the new one found in the client code and remove the old ones.
        File.delete(@requires_path) if File.exist?(@requires_path)

        content = +"# typed: true\n"
        content << "# frozen_string_literal: true\n\n"
        content << rb_string

        create_file(@requires_path, content, verbose: false)

        say("Done", :green)

        say("All requires from this application have been written to #{name}.", [:green, :bold])
        cmd = set_color(default_command(:gem), :yellow, :bold)
        say("Please review changes and commit them, then run `#{cmd}`.", [:green, :bold])
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
tapioca-0.16.8 lib/tapioca/commands/require.rb
tapioca-0.16.7 lib/tapioca/commands/require.rb
tapioca-0.16.6 lib/tapioca/commands/require.rb
tapioca-0.16.5 lib/tapioca/commands/require.rb
tapioca-0.16.4 lib/tapioca/commands/require.rb
tapioca-0.16.3 lib/tapioca/commands/require.rb
tapioca-0.16.2 lib/tapioca/commands/require.rb
tapioca-0.16.1 lib/tapioca/commands/require.rb
tapioca-0.16.0 lib/tapioca/commands/require.rb
tapioca-0.15.1 lib/tapioca/commands/require.rb
tapioca-0.15.0 lib/tapioca/commands/require.rb
tapioca-0.14.4 lib/tapioca/commands/require.rb
tapioca-0.14.3 lib/tapioca/commands/require.rb
tapioca-0.13.3 lib/tapioca/commands/require.rb
tapioca-0.13.2 lib/tapioca/commands/require.rb
tapioca-0.13.1 lib/tapioca/commands/require.rb
tapioca-0.13.0 lib/tapioca/commands/require.rb
tapioca-0.12.0 lib/tapioca/commands/require.rb
tapioca-0.11.17 lib/tapioca/commands/require.rb
tapioca-0.11.16 lib/tapioca/commands/require.rb