bit-bin
Version:
<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b
91 lines (66 loc) • 2.07 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GraphBuilder = void 0;
function _bluebird() {
const data = require("bluebird");
_bluebird = function () {
return data;
};
return data;
}
function _defineProperty2() {
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
_defineProperty2 = function () {
return data;
};
return data;
}
function _componentGraph() {
const data = require("./component-graph");
_componentGraph = function () {
return data;
};
return data;
}
function _componentsGraph() {
const data = require("../../scope/graph/components-graph");
_componentsGraph = function () {
return data;
};
return data;
}
class GraphBuilder {
constructor(componentFactory, workspace, scope) {
this.componentFactory = componentFactory;
this.workspace = workspace;
this.scope = scope;
(0, _defineProperty2().default)(this, "_graph", void 0);
(0, _defineProperty2().default)(this, "_initialized", false);
}
getGraph() {
var _this = this;
return (0, _bluebird().coroutine)(function* () {
if (_this._graph || _this._initialized) {
return _this._graph;
}
if (_this.workspace) {
const ids = (yield _this.workspace.list()).map(comp => comp.id);
const bitIds = ids.map(id => id._legacy);
const initialGraph = yield (0, _componentsGraph().buildOneGraphForComponents)(bitIds, _this.workspace.consumer);
const graph = _componentGraph().ComponentGraph.buildFromLegacy(initialGraph, _this.componentFactory);
_this._graph = graph;
_this._initialized = true;
return _this._graph;
} // TODO: implement using buildOneGraphForComponentsUsingScope (probably)
if (_this.scope) {
_this._initialized = true;
return _this._graph;
}
return _this._graph;
})();
}
}
exports.GraphBuilder = GraphBuilder;
;