-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate binstub along with other commands
- Loading branch information
1 parent
8cf11d1
commit f9f8638
Showing
5 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
# This file was auto-generated by Packwerk through `packwerk init` | ||
|
||
# Needs to be run in test environment in order to have test helper paths available in the autoload paths | ||
ENV["RAILS_ENV"] = "test" | ||
|
||
# Command line arguments needs to be duplicated because spring modifies it | ||
packwerk_argv = ARGV.dup | ||
|
||
begin | ||
load(File.expand_path("spring", __dir__)) | ||
rescue LoadError => e | ||
raise unless e.message.include?("spring") | ||
end | ||
|
||
require "packwerk" | ||
|
||
cli = Packwerk::Cli.new | ||
cli.run(packwerk_argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |