Automating Discourse Plugin Setup with `create-discourse-plugin` gem

:mega: This plugin is now bundled with Discourse core. There is no need to use this gem.
To create a new plugin, use:
rake plugin:create[plugin-name]

Since I started developing discourse plugins, I felt the overall setup could be more straightforward. We should have a better overall developer experience when creating a plugin.

In that spirit, I’ve created in my free time this gem called create-discourse-plugin

What does it do?

It clones and creates a copy of the discourse-plugin-skeleton under your username or org based on your chosen option. After doing that, it updates all placeholders with the name of your plugin. Making it ready to start development.

How to use?

In the same spirit as npx create-next-app or npx meteor

 gem exec create-discourse-plugin <plugin-name>

image

Requirements

Contribuiting

16 Likes

Thank you! I’ve thought about doing this every time I’ve made a new plugin for the past couple of years! It looks like you have don’t a much better job than I would have. I can’t wait to try it!

6 Likes

This is so awesome, so when are you going to get annoyed enough to make

 gem exec create-discourse-theme <theme-name>

? :wink:

6 Likes

That would be discourse_theme new :wink:


@grubba how would you feel about rolling this into core as a rake task? Like

bin/rake plugin:create

People need to have a working core dev environment to work on plugins anyway, so it seems like a good fit? It would also make more ‘official’, and easier for the whole team to maintain.

I wonder if it would be better to make it 100% git, instead of relying on people using github (and having the gh cli)? Some people use other services to host their plugins, and also may not want them to immediately be made public.

In discourse_theme we maintain a local cache of the theme-skeleton, so it even works offline!

6 Likes

Doh! I only ever use watch! And I think when I tried it long ago it, I don’t know. But I forgot about it. :exploding_head:

2 Likes

I guess it makes sense! People have tested it, and I’ve received a few complaints and feedback and made some adjustments. I think it is in pretty good shape to make it official. I’ll work within the next few days on adding it to the core.

I agree that using gh is not ideal, and I’ll figure out a solution. Maybe what discourse_theme new does is what I was looking for…

5 Likes

I have great news! I’ve just merged this new rake task into core:

rake plugin:create[name]

It works similarly to the gem, but it does not push to GitHub, giving you the choice of what to do–precisely like discourse_theme new

I’ll tag this gem as deprecated, as we have a more official solution

9 Likes

EDIT: I removed Gemfile.lock from .gitignore, like it said. And now it works.

No Gemfile.lock allowed in .gitignore
Cloning 'https://github.com/discourse/discourse-plugin-skeleton' to '/home/pfaffman/src/discourse-repos/discourse/plugins/discourse-public-bookmark-timers'...
Initializing git repository...
Initialized empty Git repository in /home/pfaffman/src/discourse-repos/discourse/plugins/discourse-public-bookmark-timers/.git/
The following paths are ignored by one of your .gitignore files:
Gemfile.lock
hint: Use -f if you really want to add them.
hint: Turn this message off by running
hint: "git config advice.addIgnoredFile false"
rake aborted!
Command failed with exit 1: git
/home/pfaffman/src/discourse-repos/discourse/lib/tasks/plugin.rake:352:in `system'
/home/pfaffman/src/discourse-repos/discourse/lib/tasks/plugin.rake:352:in `block (2 levels) in <main>'
/home/pfaffman/src/discourse-repos/discourse/lib/tasks/plugin.rake:344:in `chdir'
/home/pfaffman/src/discourse-repos/discourse/lib/tasks/plugin.rake:344:in `block in <main>'
Tasks: TOP => plugin:create
(See full trace by running task with --trace)

I tried again after running git config advice.addIgnoredFile false with the same result.

And also

$ gem exec create-discourse-theme discourse-public-bookmark-timers

ERROR:  Could not find a valid gem 'create-discourse-theme' (>= 0) in any repository
ERROR:  Possible alternatives: create-discourse-plugin, discourse_theme, askclass-course-theme, date_discreter, opensource-theme
1 Like