@rnv/engine-core
Version:
ReNative Engine Core
80 lines • 4.28 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var core_1 = require("@rnv/core");
var linker_1 = require("./linker");
var _linkPackage = function (pkg) {
if (!(0, core_1.fsExistsSync)(pkg.cacheDir)) {
(0, core_1.mkdirSync)(pkg.cacheDir);
}
if (pkg.isBrokenLink) {
(0, core_1.logInfo)("".concat(pkg.name, " is a ").concat((0, core_1.chalk)().red('broken'), " link. Attempting to fix..."));
(0, core_1.fsUnlinkSync)(pkg.nmPath);
}
else if (pkg.isLinked) {
(0, core_1.logInfo)("".concat(pkg.name, " is already linked. SKIPPING"));
}
else if (pkg.skipLinking) {
(0, core_1.logInfo)("".concat(pkg.name, " is set to skip linking. SKIPPING"));
}
else if (pkg.nmPathExists) {
if (pkg.unlinkedPathExists) {
(0, core_1.logInfo)("".concat(pkg.name, " found in existing cache. Removing and relinking..."));
(0, core_1.removeDirSync)(pkg.unlinkedPath);
}
(0, core_1.mkdirSync)(pkg.unlinkedPath);
(0, core_1.fsRenameSync)(pkg.nmPath, pkg.unlinkedPath);
(0, core_1.fsSymlinkSync)(pkg.sourcePath, pkg.nmPath);
(0, core_1.logInfo)("".concat((0, core_1.chalk)().green('✔'), " ").concat(pkg.name, " (").concat((0, core_1.chalk)().gray(pkg.nmPath), ")"));
}
else if (pkg.unlinkedPathExists) {
(0, core_1.logInfo)("".concat(pkg.name, " found in unlinked cache. Attempting to relink..."));
(0, core_1.fsSymlinkSync)(pkg.sourcePath, pkg.nmPath);
(0, core_1.logInfo)("".concat(pkg.name, " => link => ").concat((0, core_1.chalk)().green('SUCCESS'), " (").concat((0, core_1.chalk)().gray(pkg.nmPath), ")"));
}
};
var runtimeLibs = ['@rnv/renative'];
exports.default = (0, core_1.createTask)({
description: 'Links development version or renative with this project',
fn: function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var linkablePackages, msg, choices, slpDefaults, selectedLinkableProjects;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
linkablePackages = (0, linker_1.traverseTargetProject)((0, linker_1.getSourceDir)());
msg = 'Found following source packages:\n\n';
choices = [];
linkablePackages.forEach(function (pkg) {
var title = "".concat(pkg.nmPath.replace(pkg.name, (0, core_1.chalk)().bold.white(pkg.name)), " ").concat(pkg.isBrokenLink ? (0, core_1.chalk)().red('(broken)') : pkg.isLinked ? (0, core_1.chalk)().green('(linked)') : '(unlinked)', "\n");
msg += title;
var addon = runtimeLibs.includes(pkg.name)
? (0, core_1.chalk)().yellow(' (Runtime lib. will not work with react-native)')
: '';
choices.push({ name: "".concat(pkg.name).concat(addon), value: pkg });
});
(0, core_1.logInfo)(msg);
slpDefaults = linkablePackages.filter(function (pkg) { return !runtimeLibs.includes(pkg.name); });
return [4 /*yield*/, (0, core_1.inquirerPrompt)({
name: 'selectedLinkableProjects',
type: 'checkbox',
message: "Found following packages to link?",
default: slpDefaults,
loop: false,
choices: choices,
})];
case 1:
selectedLinkableProjects = (_a.sent()).selectedLinkableProjects;
(0, core_1.logInfo)('Linking packages...');
selectedLinkableProjects.forEach(function (pkg) {
_linkPackage(pkg);
});
return [2 /*return*/, true];
}
});
}); },
task: core_1.RnvTaskName.link,
options: [{ key: 'dir', description: 'Source folder to be linked into project', isValueType: true }],
isGlobalScope: true,
ignoreEngines: true,
});
//# sourceMappingURL=taskLink.js.map
;