UNPKG

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

86 lines (62 loc) 2.13 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = createSymlinkOrCopy; function path() { const data = _interopRequireWildcard(require("path")); path = function () { return data; }; return data; } function _fsExtra() { const data = _interopRequireDefault(require("fs-extra")); _fsExtra = function () { return data; }; return data; } function _symlinkOrCopy() { const data = _interopRequireDefault(require("symlink-or-copy")); _symlinkOrCopy = function () { return data; }; return data; } function _logger() { const data = _interopRequireDefault(require("../../logger/logger")); _logger = function () { return data; }; return data; } function _showDoctorError() { const data = _interopRequireDefault(require("../../error/show-doctor-error")); _showDoctorError = function () { return data; }; return data; } /** * @param srcPath the path where the symlink is pointing to * @param destPath the path where to write the symlink * @param componentId */ function createSymlinkOrCopy(srcPath, destPath, // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! componentId = '') { _logger().default.info(`create-symlink-or-copy, deleting ${destPath}`); _fsExtra().default.removeSync(destPath); // in case a symlink already generated or when linking a component, when a component has been moved _fsExtra().default.ensureDirSync(path().dirname(destPath)); try { _logger().default.debug(`generating a symlink on ${destPath} pointing to ${srcPath}`); _symlinkOrCopy().default.sync(srcPath, destPath); } catch (err) { const errorHeader = componentId ? `failed to link a component ${componentId}` : 'failed to generate a symlink'; throw new (_showDoctorError().default)(`${errorHeader}. Symlink (or maybe copy for Windows) from: ${srcPath}, to: ${destPath} was failed. Original error: ${err}`); } }