react-native/local-cli/core/getCommands.js
Eric Rozell 3dac49a4f5 Update getCommands.js
Summary:
Fixes issue with path for Windows. cc grabbou
Closes https://github.com/facebook/react-native/pull/9898

Differential Revision: D3864923

fbshipit-source-id: e785bfe0f01f9cf0c1964518fed03e2090300a31
2016-09-14 13:43:47 -07:00

26 lines
721 B
JavaScript

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(pathToCommands => {
const name = pathToCommands.split(path.sep)[0];
return attachPackage(
require(path.join(appRoot, 'node_modules', pathToCommands)),
require(path.join(appRoot, 'node_modules', name, 'package.json'))
);
});
return flatten(plugins);
};