Create Ember Addon with command line support

Disclaimer:
The script presented in this post might be written without Ember ecosystem and run via `npm run script` command. But it was the only thing that came to my mind and must serve us as an example.

$ 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);
}
};
Addon description via ember help command

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