Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce suspenders:setup generator #1157

Merged
merged 8 commits into from
Feb 16, 2024

Conversation

stevepolitodesign
Copy link
Contributor

@stevepolitodesign stevepolitodesign commented Feb 6, 2024

Replaces the default setup script provided by Rails. The trade-off being
that the implementation is simple, but the cost is we risk drifting from Rails.
After attempting to use gsub_file and insert_into_file, it felt simpler
to just override the file completely.

Clobber and precompile assets during setup if using Sprockets. This
is helpful in cases where one might switch branches frequently, which
can result in broken assets.

Additionally, we setup the test environment to avoid issues with asset
compilation in tests.

@stevepolitodesign stevepolitodesign changed the base branch from main to suspenders-3-0-0 February 6, 2024 00:27
Replaces the [default setup script][] provided by Rails. The trade-off
being that the implementation is simple, but the cost is we risk
drifting from Rails. After attempting to use [gsub_file][] and
[insert_into_file][], it felt simpler to just override the file
completely.

Uses [Homebrew Bundle][] in combination with [asdf][] to install system
and tool dependencies locally.

Re-introduces [dev:prime][] to seed development data on top of [seed][]
data necessary for production.

Allow caller to wipe the database clean by setting `WIPE_DATABASE=true`
before running `bin/setup`.

Additionally, we [setup the test environment][] to avoid issues with
asset compilation.

[default setup script]: https://github.com/rails/rails/blob/main/railties/lib/rails/generators/rails/app/templates/bin/setup.tt
[gsub_file]: https://rubydoc.info/gems/thor/Thor/Actions#gsub_file-instance_method
[insert_into_file]: https://rubydoc.info/gems/thor/Thor/Actions#insert_into_file-instance_method
[Homebrew Bundle]: https://github.com/Homebrew/homebrew-bundle
[asdf]: https://asdf-vm.com
[dev:prime]: https://thoughtbot.com/blog/priming-the-pump
[seed]: https://guides.rubyonrails.org/active_record_migrations.html#migrations-and-seed-data
[setup the test environment]: https://github.com/rails/rails/pull/47719/files
Running `dev:prime` calls `db:setup`, which appears to be wiping the
database for us. I tried updating it to use `db:prepare`, but that means
we will always seed the database with data from the `dev.rake` file,
resulting in duplicate records.

This implementation is consistent with the existing implementation.
Clobber and precompile assets during setup if using [Sprockets][]. This
is helpful in cases where one might switch branches frequently, which
can result in broken assets.

[Sprockets]: https://github.com/rails/sprockets
Copy link
Contributor

@mike-burns mike-burns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it conflates system setup with app setup. I'm not sold on mixing the two.

(And I say that as someone who doesn't use Homebrew.)

lib/generators/templates/setup/bin_setup.rb Outdated Show resolved Hide resolved
@@ -0,0 +1,61 @@
#!/usr/bin/env ruby
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admit, the idea of writing this shell script in Ruby never made sense to me.

lib/generators/templates/setup/dev_prime.rb Show resolved Hide resolved
@stevepolitodesign
Copy link
Contributor Author

stevepolitodesign commented Feb 9, 2024

@mike-burns

This feels like it conflates system setup with app setup. I'm not sold on mixing the two.

Is the concern that this setup script seems to favor MacOS Linux? Or, even if it were more agnostic, would you rather see the Hombrew and asdf sections removed?

Should those be the responsibility of something like Laptop

@mike-burns
Copy link
Contributor

Should those be the responsibility of something like Laptop

The system setup has traditionally been the responsibility of the Laptop script, yeah. Not sure why we would duplicate it here.

We've decided this script should not conflate system and application
setup.
We'll introduce this in a separate generator.
Copy link
Contributor

@mike-burns mike-burns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@stevepolitodesign stevepolitodesign merged commit b065ae9 into suspenders-3-0-0 Feb 16, 2024
2 checks passed
@stevepolitodesign stevepolitodesign deleted the suspenders-3-0-0-setup branch February 16, 2024 10:49
stevepolitodesign added a commit that referenced this pull request Feb 16, 2024
Follow-up to #1157

Removes obsolete files and test helpers.
stevepolitodesign added a commit that referenced this pull request Feb 16, 2024
Follow-up to #1157

Removes obsolete files and test ceremony.
stevepolitodesign added a commit that referenced this pull request Feb 19, 2024
Relates to #1157

For now, this generator simply creates `dev.rake` which contains
[dev:prime][].

Note that we'll want this generator to run **after**
`suspenders:factories`.

If future application specific tasks need to be added, we can use this
generator. However, this should not be confused with the existing
pattern of creating tasks under the suspenders namespace, such as the
existing `lib/tasks/suspenders.rake`. Tasks under this namespace cannot
be edited by the consumer, whereas tasks generated by `suspenders:tasks`
are intended to be edited by the consumer.

[dev:prime]: https://thoughtbot.com/blog/priming-the-pump
stevepolitodesign added a commit that referenced this pull request Feb 20, 2024
Relates to #1157

For now, this generator simply creates `dev.rake` which contains
[dev:prime][].

Note that we'll want this generator to run **after**
`suspenders:factories`.

If future application specific tasks need to be added, we can use this
generator. However, this should not be confused with the existing
pattern of creating tasks under the suspenders namespace, such as the
existing `lib/tasks/suspenders.rake`. Tasks under this namespace cannot
be edited by the consumer, whereas tasks generated by `suspenders:tasks`
are intended to be edited by the consumer.

[dev:prime]: https://thoughtbot.com/blog/priming-the-pump
stevepolitodesign added a commit that referenced this pull request Mar 21, 2024
Follow-up to #1157

After merging #1156, this command no longer works, since it's assumed
the app was generated with the `--skip-test` flag.
stevepolitodesign added a commit that referenced this pull request Mar 21, 2024
Follow-up to #1157

After merging #1156, this command no longer works, since it's assumed
the app was generated with the `--skip-test` flag.
stevepolitodesign added a commit that referenced this pull request May 10, 2024
Replaces the [default setup script][] provided by Rails. The trade-off
being that the implementation is simple, but the cost is we risk
drifting from Rails. After attempting to use [gsub_file][] and
[insert_into_file][], it felt simpler to just override the file
completely.

Conditionally call [dev:prime][] to seed development data on top of [seed][]
data necessary for production. A follow-up commit will re-introduce this task.

Additionally, we [setup the test environment][] to avoid issues with
asset compilation.

[default setup script]: https://github.com/rails/rails/blob/main/railties/lib/rails/generators/rails/app/templates/bin/setup.tt
[gsub_file]: https://rubydoc.info/gems/thor/Thor/Actions#gsub_file-instance_method
[insert_into_file]: https://rubydoc.info/gems/thor/Thor/Actions#insert_into_file-instance_method
[dev:prime]: https://thoughtbot.com/blog/priming-the-pump
[seed]: https://guides.rubyonrails.org/active_record_migrations.html#migrations-and-seed-data
[setup the test environment]: https://github.com/rails/rails/pull/47719/files
stevepolitodesign added a commit that referenced this pull request May 10, 2024
Follow-up to #1157

Removes obsolete files and test ceremony.
stevepolitodesign added a commit that referenced this pull request May 10, 2024
Relates to #1157

For now, this generator simply creates `dev.rake` which contains
[dev:prime][].

Note that we'll want this generator to run **after**
`suspenders:factories`.

If future application specific tasks need to be added, we can use this
generator. However, this should not be confused with the existing
pattern of creating tasks under the suspenders namespace, such as the
existing `lib/tasks/suspenders.rake`. Tasks under this namespace cannot
be edited by the consumer, whereas tasks generated by `suspenders:tasks`
are intended to be edited by the consumer.

[dev:prime]: https://thoughtbot.com/blog/priming-the-pump
stevepolitodesign added a commit that referenced this pull request May 10, 2024
Follow-up to #1157

After merging #1156, this command no longer works, since it's assumed
the app was generated with the `--skip-test` flag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants