Discourse Theme CLI (console app to help you build themes)

(Kris) #57

Are you using the per-user API (visit your user profile, click admin, and generate the API key from there) and not the “All users” API (which is from admin/api)?

1 Like

I tried both keys. Maybe I’m doing something else wrong.

1: Installed Ruby locally (Win 10)
2: Installed the discourse_theme gem
3: Ran discourse_theme new C:\theme
4. Ran discourse_theme watch C:\theme
4: Got message: No site found! Where would you like to synchronize the theme to:
5. Entered: http://myforum.nodechef.com
6. Got message: No API key found in DISCOURSE_API_KEY env var enter your API key:
7. Entered my admin (per-user) API key.
8. Got one of two error messages:

Uploading theme from C:/theme to http://myforum.nodechef.com : Error importing theme status: 500 {"status":500,"error":"Internal Server Error"} Please add the following to your Gemfile to avoid polling for changes: gem 'wdm', '>= 0.1.0' if Gem.win_platform?

Or, if I enter the global API key I get the 404 error instead:

Uploading theme from C:\theme to http://myforum.nodechef.com : Error importing theme status: 404 The requested URL or resource could not be found.


Setting up a solid workflow for custom theme development
(Jay Pfaffman) #59

My guess is that Your API key is not for an admin (or it’s the global key, which also won’t work).


Isn’t this an admin account?

Admin? > Yes

(Jay Pfaffman) #61

If I have any assets, I get an error:

Uploading theme from /home/pfaffman/src/discourse-three-columns-custom to https://test2.meshach.hosted-by-lc.com/ : Error importing theme status: 422
{"errors":["Error cloning git repository, access is denied or repository is not found"]}

Here is about.json:

  "name": "Next Three Columns",
  "about_url": "URL",
  "license_url": "URL",
  "assets": {
    "background-image": "assets/background.jpg"
  "color_schemes": {

If I remove

 "background-image": "assets/background.jpg"

it works fine.

I tried creating a new theme with discourse_theme and even pushing it to a public github repo. But adding assets seems to be a problem.

I just upgraded the site that I’m pushing to in case that made a difference, but it didn’t.

Edit: The problem was that S3 uploads were improperly configured. Trying to upload into a post gave me “Invalid region” which eventually let me know that S3 was broken.

This isn’t a :bug: with discourse_theme, but it is a UI problem with . . . something.

(Jeff Atwood) #62

How do you propose this could be handled better?

(Jay Pfaffman) #63

It would seem like the cli could have a better error message.

 {"errors":["Error cloning git repository, access is denied or repository is not found"]}

didn’t help much. It’s not a problem with git per se but with images being broken in Discourse.

But I suspect that relatively few people who use the theme cli will be working with broken Discourse installs, so I guess this is just a personal problem. :slight_smile:

(Mike Wickett) #64

Wasn’t sure if I should ask this question here, or somewhere related to Theme Creator, but I’m unclear on how to get an API key for Theme Creator so I can use the Theme CLI tool with Theme Creator. Any guidance would be appreciated.

(Vinoth Kannan) #65

It’s already answered in How to create an api key on the admin panel. If you needed a user specific API key then you have to generate it in the URL /admin/users/USER_ID/USERNAME.

(Mike Wickett) #66

Thanks for the reply. I’m wondering about getting an API key specifically for https://theme-creator.discourse.org so that I can use the Theme CLI tool with Theme Creator. I’m not an admin of Theme Creator obviously, so not sure if this is feasible.

(David Taylor) #67

Hit “Edit Locally”:

Then generate an API key in the dialog that appears:

(David Taylor) #68

I just pushed a major update for this tool. The key changes are

  • Interactive user interface - this makes it much easier to get set up

  • API keys are stored per-site, instead of per-theme. So if you regularly use the same site, this will save a lot of time

  • If your API key changes, just add --reset to the command - no more manual editing of the config file

  • A new command discourse_theme download foldername allows you to download a theme from a live Discourse site, and then allows you to immediately start editing it

  • Improved error messages

  • The scaffold generated by discourse_theme new now includes the file/folder for theme translations

Here’s a quick demo video of the new interface and download command:

This should all work if you’re running the latest version of Discourse. If not, you will see a warning, and some errors for the download command.

These changes should all be compatible with macOS, Windows and Linux, but as always feel free to post bugs/comments/ideas below. If you have an old version of the tool installed, just run gem update discourse_theme.

Note that some of these features are not yet compatible with theme-creator.discourse.org. That should be remedied next week.

Version 0.2.1 of discourse_theme CLI is now fully compatible with the live version of theme-creator.discourse.org.

(Justin DiRose) #73

Here’s something I’d love to see – the ability to sync theme code both ways between a development instance and a folder.

There are times where it’s easier to make a change in the Discourse GUI, and I think it would be neat if those changes could sync if the watch option was running instead of copy/pasting code back and forth.

It may not be a trivial deal to implement, but just throwing an idea (not even sure if it’s a good one) out!

(David Taylor) #74

Cool idea! As a workaround for now you can use the theme CLI to “download” a theme from Discourse. So if you make a change in the Discourse GUI, stop “watching”, run a download, then start watching again.

(Justin DiRose) #75

I wondered if it did that but I didn’t want to test it on the active project I was working on! :laughing:

That’s great to know!

(Ryan Erwin) #76

Normally I use git to grab the most recent theme, but today I was grabbing them via discourse_theme download and noticed that the first time I requested the theme, it didn’t work… but if I waited a few seconds and requested it again, it was working…

You just get an error 500 on the CLI tool, so this is an excerpt from the rails/production log… First time it shows “UndefinedConversionError” second time it shows “Sent data theme…tar.gz”

Server is running current version of tests-passed ( v2.3.0.beta5 +80 )

grabbing my theme…

Started GET "/admin/customize/themes/74/export?api_key=[FILTERED]" for at 2019-03-19 08:51:19 +0000
Processing by Admin::ThemesController#export as */*
  Parameters: {"api_key"=>"[FILTERED]", "id"=>"74"}
Completed 500 Internal Server Error in 668ms (ActiveRecord: 10.0ms)
Encoding::UndefinedConversionError ("\x89" from ASCII-8BIT to UTF-8)
/var/www/discourse/lib/theme_store/tgz_exporter.rb:45:in `write'

Same thing one minute laster…

Processing by Admin::ThemesController#export as */*
  Parameters: {"api_key"=>"[FILTERED]", "id"=>"74"}
  Rendering text template
  Rendered text template (0.0ms)
Sent data discourse-custom-signup-and-login--cli-version-.tar.gz (0.5ms)
Completed 200 OK in 105ms (Views: 0.4ms | ActiveRecord: 34.6ms)

Note that I have one theme called “Cakeday Customizations” that’s only 20K and it worked the first time… But the other themes took longer… For example one called “Category Groups Customization” is 412K and I got several error 500’s before the download completed.

(David Taylor) #77

Are you connecting to a local development instance, or a production instance?

Are you able to share the very large 412K theme?

(Ryan Erwin) #78

Connecting to a production instance.

I can send to you via PM… Just a moment.

(c0ry) #79

I want to use this, but when I try to install on my local computer, I get this after installing ruby:

root@God:~# gem install discourse_theme
Building native extensions. This could take a while...
ERROR:  Error installing discourse_theme:
        ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.5.0/gems/ffi-1.10.0/ext/ffi_c
/usr/bin/ruby2.5 -r ./siteconf20190319-422-z057a8.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.5.0/gems/ffi-1.10.0 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/ffi-1.10.0/gem_make.out
(Penar Musaraj) #80

That looks like an issue with your ruby installation. Can you install other gems correctly?

You might want to look into upgrading your Ruby version as well, we recommend 2.6.1 for dev environments now.