UNPKG

dev-env-installer

Version:

[![Build Status](https://travis-ci.org/mulesoft-labs/dev-env-installer.svg?branch=master)](https://travis-ci.org/mulesoft-labs/dev-env-installer)

97 lines 3.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var cp = require("child_process"); var fs = require("fs"); var path = require("path"); var modulesDetector = require("./linkedModuleDetector"); function execProcess(command, wrkDir, logEnabled, errLogEnabled, messageBefore, messageAfter, messageError, maxLogLength, onError) { if (logEnabled === void 0) { logEnabled = false; } if (errLogEnabled === void 0) { errLogEnabled = true; } if (messageBefore === void 0) { messageBefore = ''; } if (messageAfter === void 0) { messageAfter = ''; } if (messageError === void 0) { messageError = ''; } if (maxLogLength === void 0) { maxLogLength = -1; } if (onError === void 0) { onError = null; } console.log("> " + wrkDir + " " + command); try { if (logEnabled) { console.log(messageBefore); } var logObj = cp.execSync(command, { cwd: wrkDir, encoding: 'utf8', stdio: [0, 1, 2] }); if (logEnabled) { console.log(messageAfter); if (logObj) { var log = logObj.toString(); if (log.trim().length > 0) { if (maxLogLength < 0) { console.log(log); } else if (maxLogLength > 0) { console.log(log.substring(0, Math.min(maxLogLength, log.length))); } } } } return 0; } catch (err) { if (onError) { onError(err); } if (errLogEnabled) { console.log(messageError); console.log(err.message); } return err.status; } } exports.execProcess = execProcess; function getCliArgumentByName(argumentName) { for (var i = 0; i < process.argv.length; i++) { if (process.argv[i] == argumentName && i < process.argv.length - 1) { return process.argv[i + 1]; } } return null; } exports.getCliArgumentByName = getCliArgumentByName; function hasCliArgument(argumentName, mustHaveValue) { if (mustHaveValue === void 0) { mustHaveValue = false; } for (var i = 0; i < process.argv.length; i++) { if (process.argv[i] == argumentName) { if (mustHaveValue) { return i < process.argv.length - 1; } return true; } } return false; } exports.hasCliArgument = hasCliArgument; function createSymlink(absoluteSrc, absoluteDst) { if (isWindows()) { var linkCommand = "mklink /J \"" + absoluteDst + "\" \"" + absoluteSrc + "\""; if (execProcess(linkCommand, path.dirname(absoluteDst), true) != 0) { throw new Error("Could not create symlink link: '" + linkCommand + "'"); } } else { fs.symlinkSync(absoluteSrc, absoluteDst); console.log("Symlink created from '" + absoluteSrc + "' to '" + absoluteDst + "'"); } } exports.createSymlink = createSymlink; function isWindows() { var osId = process.platform; return osId.indexOf("win") == 0; } exports.isWindows = isWindows; function loadModulesStaticInfo(workspaceDescriptor) { return modulesDetector.loadModulesStaticInfo(workspaceDescriptor); } exports.loadModulesStaticInfo = loadModulesStaticInfo; //# sourceMappingURL=exportedUtils.js.map