Create Ember Addon with command line support

$ ember unused:components
More than 20% of components is unused in this project

Create an Addon

$ ember addon ember-awesome-addon-name

Plan the structure

ember-awesome-addon-name/
├── addon/
├── app/
├── ...
├── lib/
│ ├── commands/
│ └── unused.js
│ └── components.js

├── test/
└── ...

The meat: add the command

'use strict';module.exports = {
name: 'ember-awesome-addon-name',
includedCommands() {
return {
'unused:components': require('./lib/commands/unused')
};
}

};

Define the command

'use strict';const components = require('../components');module.exports = {
name: 'unused:components',
aliases: ['uc'],
availableOptions: [
{ name: 'pods', type: Boolean, default: false, aliases: ['p'] },
{ name: 'pods-dir', type: String, aliases: ['pd'] }
],
description: 'Search for unused components in your Ember project',
run(commandOptions) {
components.searchForUnusedComponents(commandOptions);
}
};
  • name — it will be used as a command you put after ember, e.g. ember nice if name: 'nice'
  • aliases — just a list of aliases for your long command
  • availableOptions — these are the arguments you will allow the developer to pass with the command like ember nice --what=everything. Like you see we set the type, can set the default value and even aliases
  • description — keep it simple. It will be shown when someone uses ember help command:
Addon description via ember help command
  • run — this function is fired when the command was used. I recommend to again use a different file for that and keep commands directory tidy.

Run

--

--

--

I connect humans and machines. Usually write about interfaces, digital products, and UX on tomekdev.com. Founder of checknlearn.com. A bit nerdy 🤓

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tomek Niezurawski

Tomek Niezurawski

I connect humans and machines. Usually write about interfaces, digital products, and UX on tomekdev.com. Founder of checknlearn.com. A bit nerdy 🤓

More from Medium

Exploring Internet Cookies and how to Create Cookies Using JavaScript

How and Find and Hire PWA Developer | Optymize

Which language & framework are you using for a backend?

Startup guide of Jest for testing your JavaScript code. (Beginner)