"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

function _defineProperty2() {
  const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

  _defineProperty2 = function () {
    return data;
  };

  return data;
}

function _chalk() {
  const data = _interopRequireDefault(require("chalk"));

  _chalk = function () {
    return data;
  };

  return data;
}

function _command() {
  const data = _interopRequireDefault(require("../../command"));

  _command = function () {
    return data;
  };

  return data;
}

function _consumer() {
  const data = require("../../../api/consumer");

  _consumer = function () {
    return data;
  };

  return data;
}

function _utils() {
  const data = require("../../../utils");

  _utils = function () {
    return data;
  };

  return data;
}

function _constants() {
  const data = require("../../../constants");

  _constants = function () {
    return data;
  };

  return data;
}

class Build extends _command().default {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2().default)(this, "name", 'build [id]');
    (0, _defineProperty2().default)(this, "description", `build any set of components with a configured compiler (as defined in bit.json)\n  https://${_constants().BASE_DOCS_DOMAIN}/docs/building-components.html`);
    (0, _defineProperty2().default)(this, "alias", '');
    (0, _defineProperty2().default)(this, "opts", [['v', 'verbose [boolean]', 'showing npm verbose output for inspection'], ['c', 'no-cache', 'ignore component cache when creating dist file']]);
    (0, _defineProperty2().default)(this, "loader", true);
    (0, _defineProperty2().default)(this, "migration", true);
  }

  action([id], {
    noCache = false,
    verbose = false
  }) {
    if (!id) return (0, _consumer().buildAll)(noCache, verbose);
    return (0, _consumer().build)(id, noCache, verbose);
  }

  report(res) {
    const noCompilerSpecifiedError = _chalk().default.yellow('compiler is not defined, please define a compiler in bit.json');

    if (!res) return noCompilerSpecifiedError;

    if (Array.isArray(res)) {
      return _chalk().default.cyan(res.join('\n'));
    }

    if (typeof res === 'object') {
      // got from build-all
      // $FlowFixMe - res is an object
      if ((0, _utils().empty)(res)) return _chalk().default.yellow('nothing to build');
      return Object.keys(res).map(component => {
        const title = _chalk().default.bold(component); // $FlowFixMe - res is an object


        const content = Array.isArray(res[component]) ? _chalk().default.cyan(res[component].join('\n')) : noCompilerSpecifiedError;
        return `${title}\n${content}\n`;
      }).join('\n');
    } // $FlowFixMe - res is a string


    return res;
  }

}

exports.default = Build;