JezK
Edit File: portable-script.js
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.makePortableProxyScript = makePortableProxyScript; function _regenerator() { var data = _interopRequireDefault(require("@babel/runtime/regenerator")); _regenerator = function _regenerator() { return data; }; return data; } function _slicedToArray2() { var data = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); _slicedToArray2 = function _slicedToArray2() { return data; }; return data; } function _asyncToGenerator2() { var data = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); _asyncToGenerator2 = function _asyncToGenerator2() { return data; }; return data; } function fs() { var data = _interopRequireWildcard(require("./fs.js")); fs = function fs() { return data; }; return data; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } var path = require('path'); function makePortableProxyScriptUnix(_x, _x2, _x3) { return _makePortableProxyScriptUnix.apply(this, arguments); } function _makePortableProxyScriptUnix() { _makePortableProxyScriptUnix = (0, _asyncToGenerator2()["default"])( /*#__PURE__*/_regenerator()["default"].mark(function _callee(source, destination, options) { var environment, prependedArguments, appendedArguments, filePath, sourcePath; return _regenerator()["default"].wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: environment = options.extraEnvironment ? Array.from(options.extraEnvironment.entries()).map(function (_ref) { var _ref2 = (0, _slicedToArray2()["default"])(_ref, 2), key = _ref2[0], value = _ref2[1]; return "".concat(key, "=\"").concat(value, "\""); }).join(' ') + ' ' : ''; prependedArguments = options.prependArguments ? ' ' + options.prependArguments.map(function (arg) { return "\"".concat(arg, "\""); }).join(' ') : ''; appendedArguments = options.appendArguments ? ' ' + options.appendArguments.map(function (arg) { return "\"".concat(arg, "\""); }).join(' ') : ''; filePath = "".concat(destination, "/").concat(options.proxyBasename || path.basename(source)); // Unless impossible we want to preserve any symlinks used to call us when forwarding the call to the binary (so we // cannot use realpath or transform relative paths into absolute ones), but we also need to tell the sh interpreter // that the symlink should be resolved relative to the script directory (hence dirname "$0" at runtime). sourcePath = path.isAbsolute(source) ? source : "$(dirname \"$0\")/../".concat(source); _context.next = 7; return fs().mkdirp(destination); case 7: if (!(process.platform === 'win32')) { _context.next = 12; break; } _context.next = 10; return fs().writeFile(filePath + '.cmd', "@".concat(environment, "\"").concat(sourcePath, "\" ").concat(prependedArguments, " ").concat(appendedArguments, " %*\r\n")); case 10: _context.next = 16; break; case 12: _context.next = 14; return fs().writeFile(filePath, "#!/bin/sh\n\n".concat(environment, "exec \"").concat(sourcePath, "\"").concat(prependedArguments, " \"$@\"").concat(appendedArguments, "\n")); case 14: _context.next = 16; return fs().chmod(filePath, 493); case 16: case "end": return _context.stop(); } }, _callee); })); return _makePortableProxyScriptUnix.apply(this, arguments); } function makePortableProxyScript(source, destination) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; return makePortableProxyScriptUnix(source, destination, options); } //# sourceMappingURL=portable-script.js.map