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

Custom output path #295

Closed
aviemet opened this issue Jan 26, 2022 · 8 comments
Closed

Custom output path #295

aviemet opened this issue Jan 26, 2022 · 8 comments

Comments

@aviemet
Copy link

aviemet commented Jan 26, 2022

Forgive me if this is documented, but I can't seem to figure out how to change the output path for the generated routes files. Using Rails 7 with Vite, I keep my frontend code in app/frontend, and so would like this gem to output routes to that directory. I would actually like them to be placed in a folder inside that directory. Is this currently possible?

@bogdan
Copy link
Collaborator

bogdan commented Jan 28, 2022

Yes, use file configuration option: https://github.com/railsware/js-routes#generator-options

@aviemet
Copy link
Author

aviemet commented Jan 28, 2022

Thank you for pointing that out. I'm still having issues setting the output path, it seems that changes can only be made relative to app/javascript. I believe this is the location where that limitation is set:

All of the following configurations resulted in an error:

config.file = 'app/frontend/routes' 
# app/javascript/app/frontend/routes isn't a file
config.file = Rails.root.join('app', 'frontend', 'routes') 
# app/javascript/var/project/app/frontend/routes isn't a file
config.file = 'app/frontend/routes/routes.js' 
# app/javascript/app/frontend/routes doesn't exist
config.file = Rails.root.join('app', 'frontend', 'routes', 'routes.js') 
# app/javascript/var/project/app/frontend/routes doesn't exist

The closest I've gotten was using config.file = '../frontend/routes/routes.js', however this produced strange results. It generated the d.ts file in the specified path, but the routes.js file still generated in app/javascript.

@bogdan
Copy link
Collaborator

bogdan commented Jan 28, 2022

In your last example: does app/frontend/routes directory exist? Can you make it and see if it fixes the issue?

@aviemet
Copy link
Author

aviemet commented Jan 28, 2022

Yes, the directory existed and routes.d.ts generated there, but routes.js was placed in app/javascript, which also existed.

@beeforever
Copy link

I can confirm this (js-routes 2.2.1). Last version it worked is 2.0.8

bogdan added a commit that referenced this issue Feb 1, 2022
@bogdan
Copy link
Collaborator

bogdan commented Feb 1, 2022

Fixed in 2.2.2 👍

@GabrielErbetta
Copy link

Fixed in 2.2.2 +1

Can confirm it's working.
I had just updated to 2.2.1 from 1.4.x and was trying to find the problem. Thank you very much @bogdan .

@bogdan bogdan closed this as completed Feb 1, 2022
@beeforever
Copy link

This is still not working (app/assets/javascripts/) exists within my rails app:
config/initializers/js_routes.rb:
JsRoutes.setup do |c|
c.module_type = nil
c.namespace = 'Routes'
c.prefix = Figaro.env.url_prefix
c.file = 'app/assets/javascripts/routes.js'
end

rake js:routes
Errno::ENOENT: No such file or directory @ rb_sysopen - PATH/app/javascript/app/assets/javascripts/routes.js

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

No branches or pull requests

4 participants