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

I tried.

This is what I get now:

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-132-yb24z9.rb extconf.rb
checking for ffi.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
/usr/lib/ruby/2.5.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from /usr/lib/ruby/2.5.0/mkmf.rb:590:in `try_cpp'
        from /usr/lib/ruby/2.5.0/mkmf.rb:1097:in `block in have_header'
        from /usr/lib/ruby/2.5.0/mkmf.rb:947:in `block in checking_for'
        from /usr/lib/ruby/2.5.0/mkmf.rb:350:in `block (2 levels) in postpone'
        from /usr/lib/ruby/2.5.0/mkmf.rb:320:in `open'
        from /usr/lib/ruby/2.5.0/mkmf.rb:350:in `block in postpone'
        from /usr/lib/ruby/2.5.0/mkmf.rb:320:in `open'
        from /usr/lib/ruby/2.5.0/mkmf.rb:346:in `postpone'
        from /usr/lib/ruby/2.5.0/mkmf.rb:946:in `checking_for'
        from /usr/lib/ruby/2.5.0/mkmf.rb:1096:in `have_header'
        from extconf.rb:16:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:


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

That’s the likely issue. If you’re on a Mac, you’ll need to install the dev tools, via xcode-select --install.


I installed via Ubuntu on Windows.

I did:

apt-get install ruby-dev

It installed, and still have the issue.

Hmm, you might want to look up how to install Ruby for your specific Ubuntu version.

So much work! I’ll figure it out later :stuck_out_tongue:

oh, looks like you are missing libffi-dev try:

sudo apt-get install libffi-dev

Note you can just install ruby on windows direct and it should work … I recall testing it.


Ruby direct, as in the windows installer?

Yeah the windows installer should work, I tested it in the past.

If your API key isn’t accepted, append


to the end of your API key when asked in the CLI.

Funnily, once I’ve done that I can just remove that addition from the api_keys: entry in the file .discourse_theme again and it keeps working.

Yeah we should fix this so it works with global api keys @david


I’m getting an error when trying to watch a new theme on the latest Discourse.

Processing by Admin::ThemesController#import as JSON
  Parameters: {"theme_id"=>"", "bundle"=>#<ActionDispatch::Http::UploadedFile:0x00007ffc319c0da8 @tempfile=#<Tempfile:/var/folders/gs/x3l5ycqx4nbg5vdhhtb08n8m0000gn/T/RackMultipart20190415-51566-1sy5rhr.gz>, @original_filename="bundle.tar.gz", @content_type="application/tar+gzip", @headers="Content-Disposition: form-data; name=\"bundle\"; filename=\"bundle.tar.gz\"\r\nContent-Length: 612\r\nContent-Type: application/tar+gzip\r\nContent-Transfer-Encoding: binary\r\n">, "api_key"=>"[FILTERED]"}
Can't verify CSRF token authenticity.
  Theme Load (2.2ms)  SELECT  "themes".* FROM "themes" WHERE "themes"."id" = NULL LIMIT 1
Completed 500 Internal Server Error in 47ms (ActiveRecord: 2.2ms)

NoMethodError - undefined method `id' for nil:NilClass:
  app/models/remote_theme.rb:152:in `update_from_remote'
  app/models/remote_theme.rb:49:in `update_tgz_theme'
  app/controllers/admin/themes_controller.rb:93:in `import'
  lib/middleware/omniauth_bypass_middleware.rb:32:in `call'
  lib/content_security_policy/middleware.rb:12:in `call'
  config/initializers/100-quiet_logger.rb:16:in `call'
  config/initializers/100-silence_logger.rb:29:in `call'
  lib/middleware/missing_avatars.rb:21:in `call'
  lib/middleware/turbo_dev.rb:34:in `call'

Thanks @angus, I think you must have an empty file in your theme, which wasn’t handled properly. It should be fixed as soon as this hits tests-passed:


Working again, thanks :+1:


I downloaded the cli last week and I am still experiencing this issue. the cli updates all of the changes from the local theme to the live preview. however, when I change the color-schemes in about.json, the changes are not reflected.

Additionally, I cannot rewrite the color-scheme variables from the common.scss either. and clicking on the add color scheme from the admin of the theme-creator refreshes the admin page only.

Any freedback on how to resolve this issue on my side or any idea for a workaround is appreciated.

Thank you

@david any ideas here ^^^


@ryanerwin sorry for the massive delay here, but this should now be fixed (details here)

The reason here wasn’t the size of the theme, but the number of uploads. Each time there was an error, Discourse cached one more file. Once they were all cached, it worked :tada:. Now it should work first time.

@ahmadabdolsaheb this should now be fixed: FIX: Correctly clear theme stylesheet cache when changing color scheme · discourse/discourse@e84531a · GitHub

I have found an issue in the last few days where the CLI will crash if you add a new file to the theme folder while the cli is running. Simple workaround is to restart it whenever you add a file, but I will get this fixed soon.


Awesome. Thanks @david Seems to be working great now :tada:


This is fixed in version 0.2.3, which I just pushed to RubyGems


Have this error on initial download from theme-creator.discourse.org:

/usr/lib64/ruby/gems/2.6.0/gems/discourse_theme-0.2.3/lib/discourse_theme/downloader.rb:12:in `initialize': not in gzip format (Zlib::GzipFile::Error)

What can be wrong?


Thanks for reporting @artur-shaik, this should be fixed in the latest version of the CLI (0.3.0) which I just pushed. To update to latest run gem update discourse_theme