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

themes
(Justin DiRose) #53

Just wanted to say I’ve been doing some theme development for the last few months (fairly new to it still), and I just installed this tool.

Holy crap.

Thanks for making things a billion times easier!

9 Likes

(Sivert) #54

I’m using Discourse development version on Mac OS 10.13.6
When I use this CLI, couldn’t install theme with 404 error
Followings are what I did:

discourse_theme new custom_theme
This created new theme as well
discourse_theme watch custom_theme
It required me site url. I’m running server on my local so I typed “localhost:3000”

After that I got 404 error as following

and I tried to run html codes, so that looks like following

Please help me to fix this issue and continue theme developing

0 Likes

(David Taylor) #55

That route will return 404 to non-admin accounts. Can you check that the API key you’re using has admin access?

2 Likes

#56

Did you manage to find the issue? I’m getting the same error.

0 Likes

(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

#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:

0 Likes

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

0 Likes

#60

Isn’t this an admin account?

Admin? > Yes

0 Likes

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

0 Likes

(Jeff Atwood) #62

How do you propose this could be handled better?

0 Likes

(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:

0 Likes

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

0 Likes

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

5 Likes

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

0 Likes

(David Taylor) #67

Hit “Edit Locally”:

Then generate an API key in the dialog that appears:

9 Likes

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

16 Likes

(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!

6 Likes

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

5 Likes

(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!

0 Likes

(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 115.79.198.131 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.

0 Likes