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
109 lines (80 loc) • 3.23 kB
JavaScript
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 _constants() {
const data = require("../../constants");
_constants = function () {
return data;
};
return data;
}
function _generalError() {
const data = _interopRequireDefault(require("../../error/general-error"));
_generalError = function () {
return data;
};
return data;
}
function _logger() {
const data = _interopRequireDefault(require("../../logger/logger"));
_logger = function () {
return data;
};
return data;
}
class BitStructure {
constructor(componentsDefaultDirectory, dependenciesDirectory) {
(0, _defineProperty2().default)(this, "_componentsDefaultDirectoryUnProcessed", void 0);
(0, _defineProperty2().default)(this, "_componentsDefaultDirectory", void 0);
(0, _defineProperty2().default)(this, "dependenciesDirectory", void 0);
this._componentsDefaultDirectoryUnProcessed = componentsDefaultDirectory || _constants().DEFAULT_COMPONENTS_DIR_PATH;
this.dependenciesDirectory = dependenciesDirectory || _constants().DEFAULT_DEPENDENCIES_DIR_PATH;
} // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
get dependenciesDirStructure() {
return this.dependenciesDirectory;
} // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
get componentsDefaultDirectory() {
if (!this._componentsDefaultDirectory) {
const dirStructure = this._componentsDefaultDirectoryUnProcessed;
const dirStructureParsed = [];
dirStructure.split('/').forEach(dir => {
if (dir.startsWith('{') && dir.endsWith('}')) {
// this is a dynamic parameter
const dirStripped = dir.replace(/[{}]/g, '');
const componentPart = this._getComponentStructurePart(dirStructure, dirStripped); // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
if (componentPart) dirStructureParsed.push(`{${componentPart}}`);
} else {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
dirStructureParsed.push(dir);
}
});
this._componentsDefaultDirectory = dirStructureParsed.join('/');
}
return this._componentsDefaultDirectory;
}
_getComponentStructurePart(componentStructure, componentPart) {
switch (componentPart) {
case 'name':
case 'scope':
case 'version':
return componentPart;
case 'namespace':
_logger().default.warn('your bit.json has an obsolete "namespace" set in componentsDefaultDirectory property, it has been ignored');
return '';
// this the dynamic namespace feature, the namespace doesn't exist, it's part of the name
default:
throw new (_generalError().default)(`the "${componentPart}" part of the component structure "${componentStructure}" is invalid, it must be one of the following: "name", "scope" or "version" `);
}
}
}
exports.default = BitStructure;
;