Use ember generate to generate, say, a component?

I was lamenting the woes of all of the things needed to add a route to Discourse (I’m currently trying to add an edit route to a custom model in a plugin) and my friend said “Is there a generator for those?” And, if you’re a “normal” Ember developer, there is. But I’m unable to figure out how to convince ember to let me use it to generate a component, so I’m going to stick with finding something like it and copying it.

But is there a better way? :thinking:

2 Likes

In core, yes (TIL!). You need to switch to the directory of our ember app first:

❯ cd app/assets/javascripts/discourse
❯ yarn ember generate component my-component-name
yarn run v1.22.10
$ /Users/david/discourse/discourse/app/assets/javascripts/node_modules/.bin/ember generate component my-component-name
installing component
  create app/components/my-component-name.js
  create app/templates/components/my-component-name.hbs
installing component-test
  create tests/integration/components/my-component-name-test.js
✨  Done in 2.06s.

But I don’t think there’s an easy way to do that in a plugin directory.

That’s how I do it as well :scissors: :clipboard:

3 Likes

Aha! yarn for the win!

Well, I just spent another 10 minutes trying, and I think you’re right. When I use the rails generator for a migration, I just move it from the discourse path into the plugin, so I guess the same approach might work.

I’m often relieved–and surprised–when I discover that the practices that I’ve adopted, in what seems like isolation, end up being the same practices used by people who Know What They Are Doing.

Thanks very much!

2 Likes