diff --git a/lib/builders/addon.js b/lib/builders/addon.js index 3658552..ebd544d 100644 --- a/lib/builders/addon.js +++ b/lib/builders/addon.js @@ -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(''); } }; diff --git a/lib/commands/inspect.js b/lib/commands/inspect.js index 1dca148..1ef8792 100644 --- a/lib/commands/inspect.js +++ b/lib/commands/inspect.js @@ -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'); @@ -56,6 +57,7 @@ module.exports = Command.extend({ builder.banner(); builder.printMetadata(metadata); builder.printBlueprints(new BlueprintCollection(metadata)); + builder.printCommands(new CommandCollection(metadata)); } } }); diff --git a/lib/models/command.js b/lib/models/command.js new file mode 100644 index 0000000..a243374 --- /dev/null +++ b/lib/models/command.js @@ -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 +};