Permalink
Browse files

Attach origin of a 3rd party command

Summary:
Fixes #9236 as suggested.

<img width="505" alt="screen shot 2016-08-22 at 21 34 44" src="https://cloud.githubusercontent.com/assets/2464966/17868740/701a0ba0-68b0-11e6-87a5-4753d5bec688.png">

(just used dummy plugin that is actually deprecated to show the output)
Closes #9529

Differential Revision: D3784933

fbshipit-source-id: ee7d6a5b82a51b3dd9fa9e4cbca31bcf14761ae4
  • Loading branch information...
1 parent 35e7a26 commit ab8c00e896de8ac9083870709d6b19a59c5ced16 @grabbou grabbou committed with Facebook Github Bot 2 Aug 29, 2016
Showing with 27 additions and 1 deletion.
  1. +9 −0 local-cli/cliEntry.js
  2. +4 −0 local-cli/commands.js
  3. +14 −1 local-cli/core/getCommands.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(
@@ -28,6 +28,10 @@ export type Command = {
desc: string,
cmd: string,
}>,
+ pkg?: {
+ version: string,
+ name: string,
+ },
};
const documentedCommands = [
@@ -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);
};

0 comments on commit ab8c00e

Please sign in to comment.