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:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/bin/$(RUBY_BASE_NAME)2.5
        --with-ffi_c-dir
        --without-ffi_c-dir
        --with-ffi_c-include
        --without-ffi_c-include=${ffi_c-dir}/include
        --with-ffi_c-lib
        --without-ffi_c-lib=${ffi_c-dir}/lib
        --with-libffi-config
        --without-libffi-config
        --with-pkg-config
        --without-pkg-config
/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:

  /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/ffi-1.10.0/mkmf.log

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
root@God:~#

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

3 Likes

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.

2 Likes

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

&api_username=<username>

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

4 Likes

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

Error
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'
2 Likes

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:

9 Likes

Working again, thanks :+1:

2 Likes

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 ^^^

2 Likes

@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.

5 Likes

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

3 Likes

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

8 Likes