UNPKG

@rxap/plugin-library

Version:

This package provides generators and executors for managing and maintaining Nx plugin libraries. It includes functionality for generating index exports, fixing dependencies, generating JSON schemas, and more. It helps streamline the development process fo

59 lines 2.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = runExecutor; const tslib_1 = require("tslib"); const plugin_utilities_1 = require("@rxap/plugin-utilities"); const fs_1 = require("fs"); const path_1 = require("path"); function createSymlink(target, link) { try { (0, fs_1.symlinkSync)(target, link, 'junction'); // 'junction' for directories on Windows, use 'dir' for POSIX console.log(`Symlink created: ${link} -> ${target}`); } catch (error) { console.error('Error creating symlink:', error); } } function checkSymlinkExists(linkPath) { try { const stats = (0, fs_1.lstatSync)(linkPath); return stats.isSymbolicLink(); } catch (error) { if (error.code === 'ENOENT') { // Link does not exist return false; } throw error; // Rethrow if it's an unexpected error } } function runExecutor(options, context) { return tslib_1.__awaiter(this, void 0, void 0, function* () { var _a; console.log('Executor ran for NodeModulesLinking', options); const outputPath = (0, plugin_utilities_1.GuessOutputPathFromContext)(context); const packageJsonPath = (0, path_1.join)(context.root, outputPath, 'package.json'); if (!(0, fs_1.existsSync)(packageJsonPath)) { console.log('package.json does not exist at', packageJsonPath); return { success: false }; } const packageJson = JSON.parse((0, fs_1.readFileSync)(packageJsonPath, 'utf-8')); const scope = (_a = packageJson.name.split('/')[0]) !== null && _a !== void 0 ? _a : ''; const packageName = packageJson.name.replace(scope + '/', ''); const nodeModulesDir = (0, path_1.join)(context.root, 'dist', 'node_modules', scope); (0, fs_1.mkdirSync)(nodeModulesDir, { recursive: true }); const link = (0, path_1.join)(nodeModulesDir, packageName); const target = (0, path_1.join)('../../../', outputPath); if (!checkSymlinkExists(link)) { console.log('Creating symlink:', link, '->', target); createSymlink(target, link); } else { console.log('Symlink already exists:', link); } return { success: true, }; }); } //# sourceMappingURL=executor.js.map