Plugin development workflow?


(Aja Bogdanoff) #1

What’s the usual approach to developing/debugging Discourse plugins? I’m using Vagrant’s default folder sync to edit my files, and sometimes it seems like my changes take effect immediately with a simple file save and browser refresh. Other times I need to clear the tmp/cache (or should it be the entire tmp directory?) and restart Rails, and sometimes it seems like even removing the directory and restarting Rails doesn’t work; I still see the old code on the page. Should I be clearing the browser cache each time I make a change?

And is there a better way to find Ember errors than opening Safari’s debug console?


Theming/Plugin Workflow?
(Benjamin Kampmann) #2

There are a few caveats to look out for:

Normally everything runs in the dev-environment in vagrant and automatically reloads every times changes are detected. This, however, does not work flawlessly with plugin-system as it is at the moment (based totally on my experience):

  • Anything specified in the plugin.rb-file directly (like inline JS or CSS) will not be replaced properly and sometimes still loads old files
  • specifically CSS/SASS seems to require a stop-asset-clean-start-circle more often than funny
  • anything that you do/load in after_initialize will not necessarily still be the case after changes and requires restarts – this also includes changes to core files if after_initialize would have to run after they are reloaded, which is currently not happening.

Using Firefox’s (nightly) debug console :wink: . No seriously, it is much better. But no, as Ember runs frontend-wise the only way to debug/receive all errors is through the Browser debugger.

I am currently also using it to get around the first pain point, as it allows you to create a new css/styles file in the browse that I use to build the UI interactively and then copy-paste it into the file before restarting the server.


(Aja Bogdanoff) #3

This really helped sort things out, thanks. And if anyone else reading this is starting out with plugins and wondering why one isn’t taking effect, make sure you’re listing all of the files you’re adding in the plugin.rb file. I’d forgotten one of them, which wasn’t helping so much with the troubleshooting. :wink:


(Sam Saffron) #4

I just pushed a few fixes that make asset dependencies for css files less crazy.

https://github.com/discourse/discourse/commit/c24d45cb2bf608df3a32d2ef050e9e7fc759338c

and

https://github.com/discourse/discourse/commit/b93d47a267b4349efe91176cba061073075e335f

cc @lightyear @radq

Asset pipeline and dependency tracking gets seriously hairy and hard to debug.


(David) #5

Your fix seems to not have completely addressed this issue. I still have to keep restarting the rails server when developing a plugin.

This is painful, how do people actually develop plugins for discourse? Have the existing plugins been developed by keep restarting rails?


(Sam Saffron) #6

Can you post exact steps to repro so I can fix this.

I apologize for the Rails asset pipeline, it is some of the more complex code in Rails.


(Hayeah) #7

What about the workflow for developing something like plugins/poll? I am trying to develop an Engine based plugin, but can’t get my changes to refresh after each load.

I tried various configurations of autoload_path, but still coudn’t get per-request refresh to work properly.

Tips?

@sam


#8

Also wanting to ask as someone relatively new to working in this depth with Discourse, I feel like I have to quit and relaunch via bundle exec rails s in my development vagrant install to see any changes. The entire feedback loop takes about 1-2 min for any changes which is really a huge amount of time if you consider 30 changes would be about 45 minutes spent waiting.

@lightyear As someone who’s made some reasonably complex plugins now, do you have any tips to share? It would be so incredibly useful to know how your process goes. Or @sam if you do indeed have any tips. I’m just not sure if I’m somehow missing something or if people really are indeed developing with a minute or so wait between changes.


(Sigurður Guðbrandsson) #9

Check out Rails Server needs restart every time I make changes? why? - Stack Overflow

You might want to add this config option to config/environments/development.rb

Alternatively, this was a fun read … I don’t know if this is implemented or not, but you might want to play with it
http://www.hemju.com/index.php/2011/02/rails-3-quicktip-auto-reload-lib-folders-in-development-mode/


(Kane York) #10

For any Rails controllers, models, or views, they should be auto-reloaded. Anything in lib/ or plugins/ needs a ^CupEnter cycle. Anything in app/assets/javascripts needs just a browser refresh.


#11

I suppose as @lightyear stated above, however, this is still true?

anything that you do/load in after_initialize will not necessarily still be the case after changes and requires restarts – this also includes changes to core files if after_initialize would have to run after they are reloaded, which is currently not happening.

Or should the ^C up Enter be taking care of this?


(Kane York) #12

SIGTERM, up, enter, is a “restart”.


#13

oh god of course haha… just woke up :blush: