2016-11-14 19:12:24 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-05-20 11:52:08 +00:00
|
|
|
const findPlugins = require('./findPlugins');
|
2016-11-14 19:12:24 +00:00
|
|
|
const path = require('path');
|
2016-08-03 07:49:03 +00:00
|
|
|
const flatten = require('lodash').flatten;
|
2016-05-20 11:52:08 +00:00
|
|
|
|
2016-08-29 15:30:52 +00:00
|
|
|
const attachPackage = (command, pkg) => Array.isArray(command)
|
|
|
|
? command.map(cmd => attachPackage(cmd, pkg))
|
|
|
|
: { ...command, pkg };
|
|
|
|
|
2016-05-20 11:52:08 +00:00
|
|
|
/**
|
|
|
|
* @return {Array} Array of commands
|
|
|
|
*/
|
|
|
|
module.exports = function getCommands() {
|
|
|
|
const appRoot = process.cwd();
|
2016-08-29 15:30:52 +00:00
|
|
|
const plugins = findPlugins([appRoot])
|
|
|
|
.map(pathToCommands => {
|
2016-09-14 20:35:36 +00:00
|
|
|
const name = pathToCommands.split(path.sep)[0];
|
2016-08-29 15:30:52 +00:00
|
|
|
|
|
|
|
return attachPackage(
|
|
|
|
require(path.join(appRoot, 'node_modules', pathToCommands)),
|
|
|
|
require(path.join(appRoot, 'node_modules', name, 'package.json'))
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-08-03 07:49:03 +00:00
|
|
|
return flatten(plugins);
|
2016-05-20 11:52:08 +00:00
|
|
|
};
|