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

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)?


#58

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.

Notes:


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


#60

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.


(Angus McLeod) #69

Awesome :slight_smile:

Live reload isn’t working for me (and wasn’t prior to this update either). The changes are being picked up by the watcher, but they don’t appear on my local instance until I reload. Any ideas on how to debug?

Example: Dropbox - Kapture 2019-02-20 at 11.29.17.mp4

Note the errors in the console in the video are images that failed to load.


CSS auto refresh not working?
(Justin DiRose) #70

I’ve noticed this for the last couple of betas (same in some instances when working on theme CSS from the GUI).

Additionally, I’ve noticed the cli crashes sometimes after adding a new file. I saw this yesterday, and unfortunately I don’t have my trace handy. I’ll post it if I run into it again.

Edit: Here’s the backtrace:

[2019-02-20T15:48:52.370212 #85337] ERROR -- : exception while processing events: undefined method `gsub' for nil:NilClass Backtrace:
 -- ~/.rbenv/versions/2.5.2/lib/ruby/gems/2.5.0/gems/discourse_theme-0.2.2/lib/discourse_theme/watcher.rb:30:in `block in watch'
 -- ~/.rbenv/versions/2.5.2/lib/ruby/gems/2.5.0/gems/listen-3.1.5/lib/listen/event/config.rb:23:in `call'
 -- ~/.rbenv/versions/2.5.2/lib/ruby/gems/2.5.0/gems/listen-3.1.5/lib/listen/event/processor.rb:115:in `_process_changes'
 -- ~/.rbenv/versions/2.5.2/lib/ruby/gems/2.5.0/gems/listen-3.1.5/lib/listen/event/processor.rb:19:in `block in loop_for'
 -- ~/.rbenv/versions/2.5.2/lib/ruby/gems/2.5.0/gems/listen-3.1.5/lib/listen/event/processor.rb:15:in `loop'
 -- ~/.rbenv/versions/2.5.2/lib/ruby/gems/2.5.0/gems/listen-3.1.5/lib/listen/event/processor.rb:15:in `loop_for'
 -- ~/.rbenv/versions/2.5.2/lib/ruby/gems/2.5.0/gems/listen-3.1.5/lib/listen/event/loop.rb:84:in `_wait_for_changes'
 -- ~/.rbenv/versions/2.5.2/lib/ruby/gems/2.5.0/gems/listen-3.1.5/lib/listen/event/loop.rb:42:in `block in setup'
 -- ~/.rbenv/versions/2.5.2/lib/ruby/gems/2.5.0/gems/listen-3.1.5/lib/listen/internals/thread_pool.rb:6:in `block in add'

I’m wondering if I need a newer Ruby version installed for this.


(David Taylor) #72

@angus, I’ve seen this lack of CSS reload recently as well. For me it has been with core stylesheets, not themes/plugins, so I don’t think it’s related to the theme CLI. I’ll try and track down the issue, but if you have a consistent repro please let me know. I expect it has to do with the way the local development environment is set up.

Edit: oh I see this has its own topic now: CSS auto refresh not working?

Thanks, I’ll look into this :+1: