Skip to content

Commit

Permalink
simplify spring setup
Browse files Browse the repository at this point in the history
  • Loading branch information
alexevanczuk committed Nov 18, 2021
1 parent 3b968e6 commit 7d753a9
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 112 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Or install it yourself as:

$ gem install packwerk

3. Run `bundle exec packwerk init` to generate the configuration files
2. Run `bundle binstub packwerk` to generate the binstub
3. Run `bin/packwerk init` to generate the configuration files

## Usage

Expand Down
12 changes: 9 additions & 3 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,19 @@ The [package principles](https://en.wikipedia.org/wiki/Package_principles) page

## Getting started

After including Packwerk in the Gemfile, you can generate the necessary files to get Packwerk running by executing:
After including Packwerk in the Gemfile, you will first want to generate a binstub:
You can do this by running `bundle binstub packwerk`, which will generate a [binstub](https://bundler.io/man/bundle-binstubs.1.html#DESCRIPTION) for packwerk.

bundle exec packwerk init
Then, you can generate the necessary files to get Packwerk running by executing:

bin/packwerk init

Here is a list of files generated:

| File | Location | Description |
|-----------------------------|--------------|------------|
| Packwerk configuration | packwerk.yml | See [Setting up the configuration file](#Setting-up-the-configuration-file) |
| Root package | package.yml | A package for the root folder |
| Bin script | bin/packwerk | A binstub for executing packwerk with spring (if available)
| Custom inflections | config/inflections.yml | A custom inflections file is only required if you have custom inflections in `inflections.rb`, see [Inflections](#Inflections) |

After that, you may begin creating packages for your application. See [Defining packages](#Defining-packages)
Expand All @@ -70,6 +72,10 @@ Packwerk reads from the `packwerk.yml` configuration file in the root directory.
| custom_associations | N/A | list of custom associations, if any |
| parallel | true | when true, fork code parsing out to subprocesses |

## Setting up Spring

[Spring](https://github.com/rails/spring) is a preloader for Rails. Because `packwerk` loads `Rails`, it can be sped up dramatically by enabling spring. Packwerk supports the usage of Spring. To enable Spring, first run `bin/spring binstub packwerk` which will "springify" the generated binstub. Secondly, spring needs to know about the packwerk spring command when spring is loading. To do that, add `require 'packwerk/spring_command'` to the bottom of `config/spring.rb` in your application.

### Using a custom ERB parser

You can specify a custom ERB parser if needed. For example, if you're using `<%graphql>` tags from https://github.com/github/graphql-client in your ERBs, you can use a custom parser subclass to comment them out so that Packwerk can parse the rest of the file:
Expand Down
8 changes: 7 additions & 1 deletion exe/packwerk
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@

require "packwerk"

Packwerk::Cli.new(style: Packwerk::OutputStyles::Coloured.new).run(ARGV.dup)
# 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
cli = Packwerk::Cli.new(style: Packwerk::OutputStyles::Coloured.new)
cli.run(packwerk_argv)
5 changes: 0 additions & 5 deletions lib/packwerk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
require "active_support"
require "fileutils"

# See https://github.com/jonleighton/spring-commands-rspec for an example of this pattern
if defined?(Spring.register_command)
require "packwerk/spring_command"
end

module Packwerk
extend ActiveSupport::Autoload

Expand Down
5 changes: 2 additions & 3 deletions lib/packwerk/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,13 @@ 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 && binstub
success = configuration_file && inflections_file && root_package

result = if success
<<~EOS
🎉 Packwerk is ready to be used. You can start defining packages and run `packwerk check`.
🎉 Packwerk is ready to be used. You can start defining packages and run `bin/packwerk check`.
For more information on how to use Packwerk, see: https://github.com/Shopify/packwerk/blob/main/USAGE.md
EOS
else
Expand Down
42 changes: 0 additions & 42 deletions lib/packwerk/generators/binstub.rb

This file was deleted.

21 changes: 0 additions & 21 deletions lib/packwerk/generators/templates/packwerk

This file was deleted.

1 change: 1 addition & 0 deletions lib/packwerk/spring_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ def call
end
end

puts "registering command"
Spring.register_command("packwerk", SpringCommand.new)
end
36 changes: 0 additions & 36 deletions test/unit/generators/binstub_test.rb

This file was deleted.

0 comments on commit 7d753a9

Please sign in to comment.