diff --git a/local-cli/cliEntry.js b/local-cli/cliEntry.js index 7a6653ce0..0c12903f9 100644 --- a/local-cli/cliEntry.js +++ b/local-cli/cliEntry.js @@ -52,11 +52,19 @@ function printHelpInformation() { cmdName = cmdName + '|' + this._alias; } + const sourceInformation = this.pkg + ? [ + ` ${chalk.bold('Source:')} ${this.pkg.name}@${this.pkg.version}`, + '', + ] + : []; + let output = [ '', chalk.bold(chalk.cyan((` react-native ${cmdName} ${this.usage()}`))), ` ${this._description}`, '', + ...sourceInformation, ` ${chalk.bold('Options:')}`, '', this.optionHelp().replace(/^/gm, ' '), @@ -114,6 +122,7 @@ const addCommand = (command: Command, config: Config) => { cmd.helpInformation = printHelpInformation.bind(cmd); cmd.examples = command.examples; + cmd.pkg = command.pkg; options .forEach(opt => cmd.option( diff --git a/local-cli/commands.js b/local-cli/commands.js index 5d7e78389..1a2b677e2 100644 --- a/local-cli/commands.js +++ b/local-cli/commands.js @@ -28,6 +28,10 @@ export type Command = { desc: string, cmd: string, }>, + pkg?: { + version: string, + name: string, + }, }; const documentedCommands = [ diff --git a/local-cli/core/getCommands.js b/local-cli/core/getCommands.js index d40664300..96eaaad0c 100644 --- a/local-cli/core/getCommands.js +++ b/local-cli/core/getCommands.js @@ -2,11 +2,24 @@ const path = require('path'); const findPlugins = require('./findPlugins'); const flatten = require('lodash').flatten; +const attachPackage = (command, pkg) => Array.isArray(command) + ? command.map(cmd => attachPackage(cmd, pkg)) + : { ...command, pkg }; + /** * @return {Array} Array of commands */ module.exports = function getCommands() { const appRoot = process.cwd(); - const plugins = findPlugins([appRoot]).map(name => require(path.join(appRoot, 'node_modules', name))); + const plugins = findPlugins([appRoot]) + .map(pathToCommands => { + const name = pathToCommands.split('/')[0]; + + return attachPackage( + require(path.join(appRoot, 'node_modules', pathToCommands)), + require(path.join(appRoot, 'node_modules', name, 'package.json')) + ); + }); + return flatten(plugins); };