"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.taskRnvUnlink = exports["default"] = void 0;var _path = _interopRequireDefault(require("path"));
var _logger = require("../../core/systemManager/logger");
var _constants = require("../../core/constants");
var _fileutils = require("../../core/systemManager/fileutils");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { "default": obj };}function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try {var info = gen[key](arg);var value = info.value;} catch (error) {reject(error);return;}if (info.done) {resolve(value);} else {Promise.resolve(value).then(_next, _throw);}}function _asyncToGenerator(fn) {return function () {var self = this,args = arguments;return new Promise(function (resolve, reject) {var gen = fn.apply(self, args);function _next(value) {asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);}function _throw(err) {asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);}_next(undefined);});};}



var _unlinkPackage = function _unlinkPackage(c, key) {
  var rnvPath = _path["default"].join(c.paths.project.nodeModulesDir, key);
  var rnvPathUnlinked = _path["default"].join(c.paths.project.nodeModulesDir, "".concat(key, "_unlinked"));

  if (!(0, _fileutils.fsExistsSync)(rnvPathUnlinked)) {
    (0, _logger.logInfo)("".concat(key, " is not linked. SKIPPING"));
  } else if ((0, _fileutils.fsExistsSync)(rnvPath)) {
    if ((0, _fileutils.fsLstatSync)(rnvPath).isSymbolicLink()) {
      (0, _fileutils.fsUnlinkSync)(rnvPath);
      (0, _fileutils.fsRenameSync)(rnvPathUnlinked, rnvPath);
      (0, _logger.logSuccess)("".concat(key, " => unlink => SUCCESS"));
    } else {
      (0, _logger.logInfo)("".concat(key, " is not a symlink anymore. SKIPPING"));
    }
  }
};


var taskRnvUnlink = /*#__PURE__*/function () {var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(c) {return regeneratorRuntime.wrap(function _callee$(_context) {while (1) {switch (_context.prev = _context.next) {case 0:
            (0, _logger.logTask)('taskRnvUnlink');

            _constants.RNV_PACKAGES.forEach(function (pkg) {
              if (!pkg.skipLinking) {
                _unlinkPackage(c, pkg.packageName);
              }
            });return _context.abrupt("return",

            true);case 3:case "end":return _context.stop();}}}, _callee);}));return function taskRnvUnlink(_x) {return _ref.apply(this, arguments);};}();exports.taskRnvUnlink = taskRnvUnlink;var _default =


{
  description: '',
  fn: taskRnvUnlink,
  task: 'unlink',
  params: _constants.PARAMS.withBase(),
  platforms: [],
  skipPlatforms: true,
  isGlobalScope: true };exports["default"] = _default;
//# sourceMappingURL=task.rnv.unlink.js.map