Firing Up Discourse for Plugin Development on macOS (the easy way)

A lot of people seem to have problems after they install all the prerequisites, to develop for Discourse on macOS.

Let me show you how I do it when I login to my mac.

First, I run a very simple script called setrails in one terminal:

and in another terminal, I run a very similar script called setunicorn and we are "ready to go":

As you can see on localhost:3000

Then to start developing, let's say today I am working on my container-names plugin, I just cd into the plugins directory and start Visual Studio Code:

Which opens my VSC IDE ready to go;

So, what are these two little scripts to get started?

$ cat setrails
export GEM_HOME=/Users/Tim/bin
export GEM_PATH=/Users/Tim/bin
export RAILS_ENV=development
# load rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - --no-rehash)"
cd /Users/Tim/discourse
gem install cppjieba_rb -v '0.3.3' --source 'https://rubygems.org/'
bundle exec rails server

and likewise:

$ cat setunicorn
export GEM_HOME=/Users/Tim/bin
export GEM_PATH=/Users/Tim/bin
export RAILS_ENV=development
# load rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - --no-rehash)"
cd /Users/Tim/discourse
gem install cppjieba_rb -v '0.3.3' --source 'https://rubygems.org/'
bundle exec unicorn

and normally I open a web browser to discourse on github and search the discourse repo code for examples to follow in the areas I want to code:

Hope this helps.

Any questions, please ask!

I would be happy to see people here develop plugins for discourse (and not just talk about it and promise me they will do it, and never do it ....)

Discourse is free and open source. Why not develop a plugin? I have developed two admin utilities so far and heavily modified one ad serving plugin to work with Revive Ad server. If I can do it, you can too!

See also:

1 Like

These days I fired up my Discourse dev environment on macOS even easier:

#login to the mac after booting
cd discourse. # /Users/Tim/discourse

export GEM_HOME=/Users/Tim/bin
export GEM_PATH=/Users/Tim/bin
export RAILS_ENV=development
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - --no-rehash)"

and then fire up rails

bundle exec 'rails s'

no need, generally speaking, to start unicorn.

the go to:

http://localhost:3000

Thats pretty much it.

Then, open another terminal

cd /Users/Tim/discourse/plugins/plugin-dev-of-the-day
code .

to fire up Visual Studio code.

When changes to the plugin only effect Ruby files, just kill and restart rails server;

#control c  the bundle exec 'rails s' process
bundle exec 'rails s' process

when a change to the code effects javascript or changes to the Ruby files require Discourse cache clearing, do this before restarting rails server:

rm -rf /Users/Tim/discourse/tmp/cache

That's it.

When I want to enter the rails console, I open another terminal and do this:

cd /Users/Tim/discourse
export GEM_HOME=/Users/Tim/bin
export GEM_PATH=/Users/Tim/bin
export RAILS_ENV=development
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - --no-rehash)"

Then, do this:

bundle exec 'rails c'

Questions? Please post in reply.