Skip to content

Commit

Permalink
Revert "replace binstub with spring command"
Browse files Browse the repository at this point in the history
This reverts commit f553edc.
  • Loading branch information
alexevanczuk committed Nov 10, 2021
1 parent 52c06c9 commit 2678be4
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 49 deletions.
1 change: 1 addition & 0 deletions lib/packwerk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ module Generators
autoload :ConfigurationFile
autoload :InflectionsFile
autoload :RootPackage
autoload :Binstub
end

module ReferenceChecking
Expand Down
3 changes: 2 additions & 1 deletion lib/packwerk/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ def generate_configs
)
inflections_file = Packwerk::Generators::InflectionsFile.generate(root: @configuration.root_path, out: @out)
root_package = Packwerk::Generators::RootPackage.generate(root: @configuration.root_path, out: @out)
binstub = Packwerk::Generators::Binstub.generate(root: @configuration.root_path, out: @out)

success = configuration_file && inflections_file && root_package
success = configuration_file && inflections_file && root_package && binstub

result = if success
<<~EOS
Expand Down
42 changes: 42 additions & 0 deletions lib/packwerk/generators/binstub.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# typed: true
# frozen_string_literal: true

module Packwerk
module Generators
class Binstub
class << self
def generate(root: ".", out: $stdout)
new(root, out: out).generate
end
end

def initialize(root, out: $stdout)
@root = root
@out = out
end

def generate
@out.puts("📦 Generating binstub...")
generate_packwerk_validate_script
end

private

def generate_packwerk_validate_script
destination_file_path = File.join(@root, "bin")
FileUtils.mkdir_p(destination_file_path)

if File.exist?(File.join(destination_file_path, "packwerk"))
@out.puts("⚠️ Packwerk binstub already exists.")
return true
end

source_file_path = File.expand_path("templates/packwerk", __dir__)
FileUtils.cp(source_file_path, destination_file_path)

@out.puts("✅ Packwerk binstub generated in #{destination_file_path}")
true
end
end
end
end
28 changes: 0 additions & 28 deletions lib/packwerk/spring_command.rb

This file was deleted.

36 changes: 36 additions & 0 deletions test/unit/generators/binstub_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# typed: false
# frozen_string_literal: true

require "test_helper"

module Packwerk
module Generators
class BinstubTest < Minitest::Test
setup do
@string_io = StringIO.new
@temp_dir = Dir.mktmpdir
FileUtils.mkdir_p(Pathname.new(@temp_dir).join("bin"))
@generated_file_path = File.join(@temp_dir, "bin", "packwerk")
end

teardown do
FileUtils.remove_entry(@temp_dir)
end

test ".generate creates a bin/packwerk file" do
success = Packwerk::Generators::Binstub.generate(root: @temp_dir, out: @string_io)
assert(File.exist?(@generated_file_path))
assert success
assert_includes @string_io.string, "binstub generated"
end

test ".generate does not create a bin/packwerk file if bin/packwerk already exists" do
File.open(File.join(@temp_dir, "bin/packwerk"), "w") do |_f|
success = Packwerk::Generators::Binstub.generate(root: @temp_dir, out: @string_io)
assert success
assert_includes @string_io.string, "binstub already exists"
end
end
end
end
end
20 changes: 0 additions & 20 deletions test/unit/spring_command_test.rb

This file was deleted.

0 comments on commit 2678be4

Please sign in to comment.