Skip to content

Commit

Permalink
Attach origin of a 3rd party command
Browse files Browse the repository at this point in the history
Summary:
Fixes facebook#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 facebook#9529

Differential Revision: D3784933

fbshipit-source-id: ee7d6a5b82a51b3dd9fa9e4cbca31bcf14761ae4
  • Loading branch information
grabbou authored and Facebook Github Bot 2 committed Aug 29, 2016
1 parent 35e7a26 commit ab8c00e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
9 changes: 9 additions & 0 deletions local-cli/cliEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, ' '),
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions local-cli/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export type Command = {
desc: string,
cmd: string,
}>,
pkg?: {
version: string,
name: string,
},
};

const documentedCommands = [
Expand Down
15 changes: 14 additions & 1 deletion local-cli/core/getCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.