-
-
Notifications
You must be signed in to change notification settings - Fork 96
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spike prettier rubygem #116
Conversation
gem/exe/ruby-prettier
Outdated
#!/usr/bin/env ruby | ||
|
||
def prettier | ||
target = if RUBY_PLATFORM =~ /darwin/ |
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.
pkg
by default supports macos, linux, windows. But supports more
https://github.com/zeit/pkg/tree/4bdbd6a95f64479a3e651a155fa0d72f1f38c489#targets
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.
The defaults you chose make a lot of sense. Let's go with those until we get a report for other support.
package.json
Outdated
@@ -5,6 +5,7 @@ | |||
"main": "src/ruby.js", | |||
"scripts": { | |||
"test": "jest", | |||
"build:gem": "pkg --output gem/pkg/prettier --targets=linux,macos,win node_modules/prettier/bin-prettier.js && cp -r src gem && cp package.json gem", |
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.
I decided to put the gem
files into a separate folder for simplicity's sake, but all of the gem related files could be at the top level so there's no need to copy across the src directory or package file.
2e7ce0a
to
626ea8f
Compare
Wow this is so great. Okay a couple of things I think we should do before shipping this:
This is so great Alan! Thanks for the work. |
One more thing - we should ship a rubocop config with this gem so that folks can use |
2b868cd
to
9888db2
Compare
9888db2
to
74dbca9
Compare
src/ripper.rb
Outdated
build_sexp(:bodystmt, body).tap do |sexp| | ||
attach_comments_to(sexp, body[0]) | ||
end | ||
build_sexp(:bodystmt, body).tap { |sexp| attach_comments_to(sexp, body[0]) } |
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.
Separate PR for formatting this file: #123
510e85d
to
a3ab6fa
Compare
Done 馃憤
Done 馃憤 I'll spend some time tomorrow grabbing some extra meta-data from this file too, like the author, homepage, etc.
Done 馃憤
I'll punt on this to a different PR - as this PR will hopefully just be a good first step towards getting a standalone gem 馃憤
Done 馃憤 Everything should align with Prettier's semantics, the Thor CLI is pretty much just passing all the arguments straight through now.
Done 馃憤 I'm shipping the current
I'm including the current I'm hoping that I've addressed most of the things now; Let me know your latest thoughts @kddeisz 馃帀 |
a3ab6fa
to
45e191f
Compare
Just double checked that this approach actually works as expected, and all seems well on a fresh docker container which only has ruby: $ docker run -v `pwd`:`pwd` -w `pwd` -it ruby:2.6.1-stretch /bin/bash
$ gem install bundler
$ bundle
$ bundle exec ruby-prettier --version
0.6.2
$ bundle exec ruby-prettier --write src/ripper.rb
src/ripper.rb 300ms
$ node --version
bash: node: command not found |
d27d490
to
57fffbd
Compare
nice work 馃憤 |
2ec8574
to
5b93413
Compare
This is super lovely, I'm definitely looking forward to getting my hands on this! Great work and thank you for it! 馃檶 |
@kddeisz Let me know your latest thoughts so I can apply the feedback and we can get this shipped - or if you're working on an alternative approach just let me know 馃憤 |
@AlanFoster This is looking great! I want some time to sit down with it, and just haven't gotten the chance yet. No need to change anything, I'll take a look at it this week. |
Gave this a run with @yuki24 - worked well! I don't think it picks up a prettierrc etc, so we couldn't change settings when using it via |
For those of you who want to give this a try without Docker or # Add this to the Gemfile
gem 'prettier', git: 'https://github.com/AlanFoster/prettier-ruby-1', branch: 'spike-prettier-rubygem' $ bundle
$ cd `bundle show prettier`
$ yarn && yarn build:gem
$ cd -
$ bundle exec ruby-prettier --write path/to/file.rb |
@orta Prettier is meant to be opinionated right? Good catch though! I'll look to see if I can fix this scenario as part of a separate PR - or this one if it feels like a blocker 馃憤 |
Doesn't feel like a blocker to me, the hard part (the deployment etc) is the focus on this PR |
Okay so a quick update on the state of things -
Thanks again! |
3de7c79
to
516c184
Compare
516c184
to
8a1d09c
Compare
Thank you @AlanFoster! I've copied most of the changes in here into #193. Not going to merge the README changes until we fully release the gem. This is great! |
The theory is Ruby developers don't want to deal with setting up npm/node locally, or on CI servers.
Instead we'd provide a prettier gem, and we'll use https://github.com/zeit/pkg to create a standalone binary for prettier - and embed the javascript src files for
plugin-ruby
- as well as any additional rubocop configuration files.I've tested this as a proof of concept with:
Then I created a new rails project and added the Gem for testing purposes:
From the new rails project:
$ bundle exec ruby-prettier --write app/channels/application_cable/channel.rb 219ms app/channels/application_cable/connection.rb 202ms app/controllers/application_controller.rb 200ms app/helpers/application_helper.rb 202ms app/jobs/application_job.rb 196ms app/mailers/application_mailer.rb 197ms app/models/application_record.rb 206ms config/application.rb 196ms config/boot.rb 196ms config/environment.rb 201ms config/environments/development.rb 203ms config/environments/production.rb 205ms config/environments/test.rb 205ms config/initializers/application_controller_renderer.rb 196ms config/initializers/assets.rb 195ms config/initializers/backtrace_silencers.rb 195ms config/initializers/content_security_policy.rb 196ms config/initializers/cookies_serializer.rb 202ms config/initializers/filter_parameter_logging.rb 203ms config/initializers/inflections.rb 195ms config/initializers/mime_types.rb 195ms config/initializers/wrap_parameters.rb 193ms config/puma.rb 196ms config/routes.rb 202ms config/spring.rb 198ms db/seeds.rb 198ms test/application_system_test_case.rb 200ms test/test_helper.rb 201ms
This is just a spike - I'll clean this PR up as appropriate. Let me know your thoughts @kddeisz 馃憤