getSelectProjectsMessage.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = getSelectProjectsMessage;
  6. function _chalk() {
  7. const data = _interopRequireDefault(require('chalk'));
  8. _chalk = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. var _getProjectDisplayName = _interopRequireDefault(
  14. require('./getProjectDisplayName')
  15. );
  16. function _interopRequireDefault(obj) {
  17. return obj && obj.__esModule ? obj : {default: obj};
  18. }
  19. /**
  20. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  21. *
  22. * This source code is licensed under the MIT license found in the
  23. * LICENSE file in the root directory of this source tree.
  24. */
  25. function getSelectProjectsMessage(projectConfigs) {
  26. if (projectConfigs.length === 0) {
  27. return getNoSelectionWarning();
  28. }
  29. return getProjectsRunningMessage(projectConfigs);
  30. }
  31. function getNoSelectionWarning() {
  32. return _chalk().default.yellow(
  33. 'You provided values for --selectProjects but no projects were found matching the selection.\n'
  34. );
  35. }
  36. function getProjectsRunningMessage(projectConfigs) {
  37. if (projectConfigs.length === 1) {
  38. const name = (0, _getProjectDisplayName.default)(projectConfigs[0]);
  39. return `Running one project: ${_chalk().default.bold(name)}\n`;
  40. }
  41. const projectsList = projectConfigs
  42. .map(getProjectNameListElement)
  43. .sort()
  44. .join('\n');
  45. return `Running ${projectConfigs.length} projects:\n${projectsList}\n`;
  46. }
  47. function getProjectNameListElement(projectConfig) {
  48. const name = (0, _getProjectDisplayName.default)(projectConfig);
  49. const elementContent = name
  50. ? _chalk().default.bold(name)
  51. : '<unnamed project>';
  52. return `- ${elementContent}`;
  53. }