-
-
Notifications
You must be signed in to change notification settings - Fork 529
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
Suspenders 3.0.0 #1135
Suspenders 3.0.0 #1135
Conversation
1cfee95
to
06c8d27
Compare
RUBY_VERSION_RANGE = [minimum_ruby_version, maximum_ruby_version].freeze | ||
VERSION = "20230113.0".freeze | ||
VERSION = "3.0.0".freeze | ||
RAILS_VERSION = "~> 7.0".freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're removing the executable, we don't need to be on the latest version of Rails. My thinking was, I don't want to prevent someone not on >= 7.1
to be able to use the gem since it's just generators.
However, the only downside to that is if a generator uses a feature from >= 7.1
, that feature won't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you've just begun. I'll watch as you commit more!
44f783e
to
2a0f7ff
Compare
In an effort to improve the developer experience and reduce technical debt, we replace the existing project with the output from running: ``` rails plugin new suspenders ``` This will allow us to use existing [testing helpers][] provided by Rails. Because of this, we deliberately switch from RSpec to MiniTest. Additionally, we move away from [calver][]. Prior to that the latest major version was `1`. This feels like a good opportunity to go back to `semver` and start fresh with `3.0.0` [testing helpers]: https://edgeguides.rubyonrails.org/generators.html#testing-generators [calver]: https://calver.org
All generators will affect the "test" app located in `test/dummy`. Although the "test" app contains most files for a Rails application, it does not contain everything. This means during the setup phase of our tests, we'll need to create files to ensure the generator is working correctly. These helpers aim to improve the developer experience by creating a simple API to create and delete files in the "test" app. It should be noted that any files and directories created in the setup won't be removed automatically after each test, so we introduce additional helpers to be called during the [teardown][] callback. [teardown]: https://github.com/rails/rails/blob/00dfa109d6a5f4fb13d745f83d5cc779eba3b352/railties/lib/rails/generators/testing/setup_and_teardown.rb#L13
Use [mocha][] for mocking and stubbing. Specifically, this will aid with testing that we correctly install a gem with bundler in our generators. [mocha]: https://github.com/freerange/mocha
2a0f7ff
to
84e0c95
Compare
Ported over from #1105 Installs [capybara_accessibility_audit] and [capybara_accessible_selectors]. `./bin/rails g suspenders:accessibility` Introduces `Suspenders::Generators::APIAppUnsupported` module for generators that cannot be run in an [API only][] application. This uses a [concern][] to ensure we raise an error before the generator including the module invokes any of its methods. [capybara_accessibility_audit]: https://github.com/thoughtbot/capybara_accessibility_audit [capybara_accessible_selectors]: https://github.com/citizensadvice/capybara_accessible_selectors [API only]: https://guides.rubyonrails.org/api_app.html [concern]: https://api.rubyonrails.org/classes/ActiveSupport/Concern.html
This is a work around for an [issue][] with `vim-test`. Borrowed an [existing][] `./bin/rails` configuration from an [Engine][], which is very similar to a [plugin][]. The only difference is that we do not need the `ENGINE_ROOT` setting. [issue]: vim-test/vim-test#477 [existing]: https://github.com/rails/rails/blob/main/railties/lib/rails/generators/rails/plugin/templates/bin/rails.tt [Engine]: https://guides.rubyonrails.org/engines.html [plugin]: https://guides.rubyonrails.org/plugins.html
Ports the existing generator to Suspenders 3.0.
it's the same but shorter
Maintains functionally with the [existing generator][] while adding support for the [default Rails test suite]. With this change, the generator can be invoked on a Rails application that uses RSpec or the [default Rails test suite][]. Adds generator which adds a test to lint all Factories in an effort to improve developer experience. Additionally, we remove the generation of the `dev:prime` task as we felt that should be the responsibly of another generator. [existing generator]: https://github.com/thoughtbot/suspenders/blob/main/lib/suspenders/generators/factories_generator.rb [default Rails test suite]: https://guides.rubyonrails.org/testing.html
NEWS should only contain items relevant to the consumer. Although the module improves the developer experience, it's not relevant to someone using the gem.
Uses the [bundler-audit][] gem to update the local security database and show any relevant issues with the app's dependencies. This generator is only responsible for installing the gem and adding the Rake task. The [original implementation][] was written in 2014, and is no longer relevant. This is because the gem ships [with a Rake task][] that can be set as the default task, which will be addressed in #1144 Also exposes `backup_file` and `restore_file` test helpers into the public API. [bundler-audit]: https://github.com/rubysec/bundler-audit [original implementation]: e23157e [with a Rake task]: https://github.com/rubysec/bundler-audit#rake-tasks
Configures applications to use [PostCSS][1] or [Tailwind][2] via [cssbundling-rails][3]. Defaults to `PostCSS` with [modern-normalize][8], with the option to override via `--css=tailwind`. These options were pulled from the [supported list of options][4] in Rails. Also creates additional stylesheets if using PostCSS. We choose to use [cssbundling-rails][4] instead of [dartsass-rails][5] or [tailwindcss-rails][6] (or even just css) because we want to rely on Node to process the CSS. Although we could have chosen to avoid using Node altogether, we feel it's better to support it since we'll need it for additional generators, like [StyleLintGenerator][7], and to support [modern-normalize][8]. Updates `within_api_only_app` by allowing support to conditionally comment out the api configuration. This provided and opportunity to clean up existing setup steps. [1]: https://postcss.org [2]: https://tailwindcss.com [3]: https://github.com/rails/cssbundling-rails [4]: https://github.com/rails/rails/blob/438cad462638b02210fc48b700c29dcd0428a8b7/railties/lib/rails/generators/app_base.rb#L22 [5]: https://github.com/rails/dartsass-rails [6]: https://github.com/rails/tailwindcss-rails [7]: https://github.com/thoughtbot/suspenders/blob/main/lib/suspenders/generators/stylelint_generator.rb [8]: https://github.com/sindresorhus/modern-normalize [9]: https://tailwindcss.com/docs/functions-and-directives#layer
Ports the existing generator to Suspenders 3.0.
Closes #1107 Closes #1143 Creates a holistic linting solution that covers JavaScript, CSS, Ruby and ERB. Introduces [scripts][] that leverage [@thoughtbot/eslint-config][], [@thoughtbot/stylelint-config][] and [prettier][]. Also introduces `.prettierrc` based off of our [Guides][]. We need to pin `stylelint` and `@thoughtbot/stlyelint-config` to specific versions to account for this [open issue][]. Unfortunately, running `yarn run lint:stylelint` results in deprecation warnings, which will need to be addressed separately. [scripts]: https://docs.npmjs.com/cli/v6/using-npm/scripts [@thoughtbot/eslint-config]: https://github.com/thoughtbot/eslint-config [@thoughtbot/stylelint-config]: https://github.com/thoughtbot/stylelint-config [prettier]: https://prettier.io [Guides]: https://github.com/thoughtbot/guides/blob/main/javascript/README.md#formatting [open issue]: thoughtbot/stylelint-config#46 Introduces `rake standard` which also runs `erblint` to lint ERB files via [better_html][], [erb_lint][] and [erblint-github][]. [better_html]: https://github.com/Shopify/better-html [erb_lint]: https://github.com/Shopify/erb-lint [erblint-github]: https://github.com/github/erblint-github A future commit will ensure these linting rules are run during CI. In an effort to support that future commit, we ensure to run `yarn run fix:prettier` and `bundle exec standard:fix_unsafely` once the generator is complete. Otherwise, CI would fail because of linting violations. We call `standard:fix_unsafely` since `standard:fix` returns an error status code on new Rails applications. Running `standard:fix_unsafely` fixes this issue and returns a success status code. It should be noted that we deliberately permit this generator to be invoked on API only applications, because those applications can still contain views, like ones used for mailers. However, a future commit could explore removing the JavaScript linters. Also improves the developer experience by introducing `with_test_suite` helper, allowing the caller to run the generator in an application using minitest or RSpec.
Add necessary files to make the [plugin][] an [engine][], which automatically loads Rake tasks located in `lib/tasks`. This means when the `suspenders` gem is installed, the consumer can run `bundle exec rake suspenders:rake`, and any future tasks. Because `suspenders:lint` and `suspenders:advisories` may not necessarily have been invoked, we need to check if those gems are installed. [plugin]: https://guides.rubyonrails.org/plugins.html [engine]: https://guides.rubyonrails.org/engines.html Co-authored-by: Mike Burns <[email protected]>
When we introduced #1148 we did not test it against applications that invoked `suspenders:styles --css=tailwind`.
Configures flash messages, page titles via the [title][] gem, and sets the document [lang][]. [title]: https://github.com/calebhearth/title [lang]: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang It should be noted that running `rails gscaffold` generates [views][] that contain the flash. Although we could have [overridden][] this generator, that would risk drift between our overridden generator and the one in Rails core. Additionally, we decided to remove the `FlashesHelper` introduced in [6c562b9][] since that is not a pattern we currently use. [views]: https://github.com/rails/rails/blob/main/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt [overridden]: https://guides.rubyonrails.org/generators.html#overriding-rails-generator-templates [6c562b9]: 6c562b9
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
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
This prepares us to merge `suspenders-3-0-0` into `main`. Once we formally release to RubyGems, we can remove the reference to GitHub.
Now that [Suspenders 3.0.0][] has [merged][], we can improve the developer experience by placing all option into our `railsrc` file. Once this commit it merged, we can link to our dotfiles from the Suspenders README. [Suspenders 3.0.0]: https://github.com/thoughtbot/suspenders [merged]: thoughtbot/suspenders#1135
Now that [Suspenders 3.0.0][] has [merged][], we can improve the developer experience by placing all option into our `railsrc` file. Once this commit it merged, we can link to our dotfiles from the Suspenders README. Also closes #746 [Suspenders 3.0.0]: https://github.com/thoughtbot/suspenders [merged]: thoughtbot/suspenders#1135
Now that [Suspenders 3.0.0][] has [merged][], we can improve the developer experience by placing all option into our `railsrc` file. Once this commit it merged, we can link to our dotfiles from the Suspenders README. Also closes #746 [Suspenders 3.0.0]: https://github.com/thoughtbot/suspenders [merged]: thoughtbot/suspenders#1135
Now that [Suspenders 3.0.0][] has [merged][], we can improve the developer experience by placing all options into our `railsrc` file. Once this commit it merged, we can link to our dotfiles from the Suspenders README. Also closes #746 [Suspenders 3.0.0]: https://github.com/thoughtbot/suspenders [merged]: thoughtbot/suspenders#1135
With the merge of #1135 and some subsequent follow-ups, we are ready to officially release the next version of Suspenders.
With the merge of #1135 and some subsequent follow-ups, we are ready to officially release the next version of Suspenders.
With the merge of #1135 and some subsequent follow-ups, we are ready to officially release the next version of Suspenders. Because we moved to [calver][] in #1106, we need to continue using calver, since the latest release `20230113.0` is greater than `3.0.0`, which was set in haste in ab3eb97 In an effort to better brand this release, we give it the code name "Tailored". [calver]: https://calver.org
With the merge of #1135 and some subsequent follow-ups, we are ready to officially release the next version of Suspenders. Because we moved to [calver][] in #1106, we need to continue using calver, since the latest release `20230113.0` is greater than `3.0.0`, which was set in haste in ab3eb97 In an effort to better brand this release, we give it the code name "Tailored". [calver]: https://calver.org
Follow-up to #728 In an effort to create parity with the [upcoming release of Suspenders][1], we pass the `--skip-test` argument when running [rails new][2]. This means if you're using our `railsrc` file, you would just need to pass the `-m` argument when generating a new Rails application. [1]: thoughtbot/suspenders#1135 [2]: https://guides.rubyonrails.org/command_line.html#rails-new
Now that [Suspenders 3.0.0][] has [merged][], we can improve the developer experience by placing all options into our `railsrc` file. Once this commit it merged, we can link to our dotfiles from the Suspenders README. Also closes #746 [Suspenders 3.0.0]: https://github.com/thoughtbot/suspenders [merged]: thoughtbot/suspenders#1135
Rewrite Suspenders as a Rails engine in an effort to achieve our goals while improving the developer experience, reducing technical debt and auditing our existing generators. The goal is to leverage as much of
rails new
as possible, and only deviate where necesary.This removes the
suspenders
system executable in favor of application templates. Moving forwared, there will be two ways to use Suspenders.With New Applications
With Existing Applications
How to review this pull request
This long running feature branch is built upon a commit for each new generator. For more contenxt, I recommend looking at the commit history. I tried to make each pull request as detailed as possible.
To get a sense if everything works in concert, run the following:
Then I recommend scaffolding out a resource and adding a system test too.
Contributing
The
3.0.0
release is focused on all generators needed for a new Rails application. Anything that is not necessary for a new application will be added in a subsequent release. Additionally, a future release will need to account for existing applications in a way that does not re-install gems.This branch will remain as a draft until all to-dos are complete.
./bin/seup
. Note, this you'll need to use Ruby3.0.0
or higher.If something needs to change about the core branch (CI improvements, setup
improvements, directory structure) commit directly to this branch and rebase
Status
App Generators
These were extracted from AppGenerator. Some generators were left out because they are no longer relevant.
Should we break these up into smaller generators, or just consolidate everything into an
AppGenerator
?suspenders:email
andlib/tasks/suspenders.rake
. We did not doconfigure_time_formats
because that may end up beind dead code, and is not neccersary for new apps.)config/initializers/errors.rb
isn't mission critical, and the JSON encoding for timestamps should probably use the Rails default, which is milliseconds)create_database
, do we need thedatabase.yml
overwrite? It is just for Heroku?)New Generators Worth Considering
These could be added as part of the initial release, or as a subsequent minor release.
dev:prime
suspenders:db:migrate
suspenders:json
suspenders:install:api
.suspenders:authorization
suspenders:prerequisites
suspenders:templates
To do
lib/install/web.rb
and any references to this branch.suspenders:lint
to account for changes in ESlint Lint Generator: Account for breaking changes in ESLint #1192suspenders:install:web
and application template #1152bin/rails
andbin/rake
works inproduction
Rails::Generators::Actions#gem_group
: Prepend existing gem groups rails/rails#49512.ruby-version
file for improved developer experience.suspenders:rake
. It does not seem to be invoked when runningbundle exec rake
.Once all is complete, rebase and merge to keep commit history.