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
89 lines (66 loc) • 2.42 kB
JavaScript
"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 _fsExtra() {
const data = _interopRequireDefault(require("fs-extra"));
_fsExtra = function () {
return data;
};
return data;
}
function _createSymlinkOrCopy() {
const data = _interopRequireDefault(require("../utils/fs/create-symlink-or-copy"));
_createSymlinkOrCopy = function () {
return data;
};
return data;
}
function _showDoctorError() {
const data = _interopRequireDefault(require("../error/show-doctor-error"));
_showDoctorError = function () {
return data;
};
return data;
}
class Symlink {
// current existing path
// new symlink path
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
constructor(src, dest, componentId) {
(0, _defineProperty2().default)(this, "src", void 0);
(0, _defineProperty2().default)(this, "dest", void 0);
(0, _defineProperty2().default)(this, "componentId", void 0);
(0, _defineProperty2().default)(this, "forDistOutsideComponentsDir", void 0);
this.src = src;
this.dest = dest;
this.componentId = componentId;
}
write() {
this._throwForMissingDistOutsideComponent();
return (0, _createSymlinkOrCopy().default)(this.src, this.dest, this.componentId ? this.componentId.toString() : null);
}
static makeInstance(src, dest, componentId) {
return new Symlink(src, dest, componentId);
}
_throwForMissingDistOutsideComponent() {
if (!this.forDistOutsideComponentsDir) return;
const srcExists = _fsExtra().default.existsSync(this.src);
if (!srcExists) {
const componentId = this.componentId ? this.componentId.toString() : '';
throw new (_showDoctorError().default)(`unable to link ${componentId}, the file ${this.src} is missing from the filesystem.
it happens when the "dist" directory is set to be outside the components directory, either by changing this settings later or by cloning the project without the dist directory
to rebuild the "dist" directory for all components, please run "bit import --merge".`);
}
}
}
exports.default = Symlink;