Skip to content

Commit

Permalink
Merge pull request #14 from san650/list-addons-commands
Browse files Browse the repository at this point in the history
List addon's commands
  • Loading branch information
san650 authored Aug 9, 2016
2 parents 9c6e4f6 + b57bd04 commit 6673363
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/builders/addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ AddonBuilder.prototype = {
});
}
console.log('');
},

printCommands: function(commands) {
if (!commands.length()) {
console.log(' Commands: none');
} else {
console.log(' Commands:');
commands.forEach(function(command) {
console.log(' ' + chalk.bold(command.name) + ' - ' + command.description);
});
}
console.log('');
}
};

Expand Down
2 changes: 2 additions & 0 deletions lib/commands/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = Command.extend({
run: function(commandOptions, rawArgs) {
var path = require('path');
var BlueprintCollection = require('../models/blueprint').Collection;
var CommandCollection = require('../models/command').Collection;
var AddonMetadata = require('../models/addon-metadata');
var AddonBuilder = require('../builders/addon');

Expand Down Expand Up @@ -56,6 +57,7 @@ module.exports = Command.extend({
builder.banner();
builder.printMetadata(metadata);
builder.printBlueprints(new BlueprintCollection(metadata));
builder.printCommands(new CommandCollection(metadata));
}
}
});
54 changes: 54 additions & 0 deletions lib/models/command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* jshint node: true */
'use strict';

function CommandMetadata(addon, command) {
if (typeof command === 'function') {
this.command = new command({ project: addon.project });
} else {
this.command = command;
}

this.name = this.command.name;
this.description = this.command.description || '(no description)';
}

function CommandCollection(addonMetadata) {
this.emberAddon = addonMetadata.emberAddon;
}

CommandCollection.prototype = {
_load: function() {
this.loaded = true;
this.items = [];

var items = this.items;
var emberAddon = this.emberAddon;
var includedCommands = (emberAddon.includedCommands && emberAddon.includedCommands()) || {};

var Command = require('ember-cli/lib/models/command');

Object.keys(includedCommands).forEach(function(key) {
items.push(new CommandMetadata(emberAddon, includedCommands[key]));
});
},

forEach: function(cb) {
if (!this.loaded) {
this._load();
}

this.items.forEach(cb);
},

length: function() {
if (!this.loaded) {
this._load();
}

return this.items.length;
}
};

module.exports = {
Collection: CommandCollection
};

0 comments on commit 6673363

Please sign in to comment.