UNPKG

actionhero

Version:

The reusable, scalable, and quick node.js API server for stateless and stateful applications

28 lines (27 loc) 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sourceRelativeLinkPath = sourceRelativeLinkPath; const fs = require("fs"); const path = require("path"); function sourceRelativeLinkPath(linkFile, pluginPaths) { const type = fs.readFileSync(linkFile).toString(); const pathParts = linkFile.split(path.sep); const name = pathParts[pathParts.length - 1].split(".")[0]; const pathsToTry = pluginPaths.slice(0); let pluginRoot; pathsToTry.forEach((pluginPath) => { const pluginPathAttempt = path.normalize(pluginPath + path.sep + name); try { const stats = fs.lstatSync(pluginPathAttempt); if (!pluginRoot && (stats.isDirectory() || stats.isSymbolicLink())) { pluginRoot = pluginPathAttempt; } } catch (e) { } }); if (!pluginRoot) { return false; } const pluginSection = path.normalize(pluginRoot + path.sep + type); return pluginSection; }