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 https://github.com/facebook/react-native/pull/9529 Differential Revision: D3784933 fbshipit-source-id: ee7d6a5b82a51b3dd9fa9e4cbca31bcf14761ae4
This commit is contained in:
parent
35e7a266db
commit
ab8c00e896
|
@ -52,11 +52,19 @@ function printHelpInformation() {
|
||||||
cmdName = cmdName + '|' + this._alias;
|
cmdName = cmdName + '|' + this._alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sourceInformation = this.pkg
|
||||||
|
? [
|
||||||
|
` ${chalk.bold('Source:')} ${this.pkg.name}@${this.pkg.version}`,
|
||||||
|
'',
|
||||||
|
]
|
||||||
|
: [];
|
||||||
|
|
||||||
let output = [
|
let output = [
|
||||||
'',
|
'',
|
||||||
chalk.bold(chalk.cyan((` react-native ${cmdName} ${this.usage()}`))),
|
chalk.bold(chalk.cyan((` react-native ${cmdName} ${this.usage()}`))),
|
||||||
` ${this._description}`,
|
` ${this._description}`,
|
||||||
'',
|
'',
|
||||||
|
...sourceInformation,
|
||||||
` ${chalk.bold('Options:')}`,
|
` ${chalk.bold('Options:')}`,
|
||||||
'',
|
'',
|
||||||
this.optionHelp().replace(/^/gm, ' '),
|
this.optionHelp().replace(/^/gm, ' '),
|
||||||
|
@ -114,6 +122,7 @@ const addCommand = (command: Command, config: Config) => {
|
||||||
|
|
||||||
cmd.helpInformation = printHelpInformation.bind(cmd);
|
cmd.helpInformation = printHelpInformation.bind(cmd);
|
||||||
cmd.examples = command.examples;
|
cmd.examples = command.examples;
|
||||||
|
cmd.pkg = command.pkg;
|
||||||
|
|
||||||
options
|
options
|
||||||
.forEach(opt => cmd.option(
|
.forEach(opt => cmd.option(
|
||||||
|
|
|
@ -28,6 +28,10 @@ export type Command = {
|
||||||
desc: string,
|
desc: string,
|
||||||
cmd: string,
|
cmd: string,
|
||||||
}>,
|
}>,
|
||||||
|
pkg?: {
|
||||||
|
version: string,
|
||||||
|
name: string,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const documentedCommands = [
|
const documentedCommands = [
|
||||||
|
|
|
@ -2,11 +2,24 @@ const path = require('path');
|
||||||
const findPlugins = require('./findPlugins');
|
const findPlugins = require('./findPlugins');
|
||||||
const flatten = require('lodash').flatten;
|
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
|
* @return {Array} Array of commands
|
||||||
*/
|
*/
|
||||||
module.exports = function getCommands() {
|
module.exports = function getCommands() {
|
||||||
const appRoot = process.cwd();
|
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);
|
return flatten(plugins);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue