UNPKG

nativescript

Version:

Command-line interface for building NativeScript projects

54 lines 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProxyService = void 0; const path = require("path"); const os_1 = require("os"); const constants_1 = require("../constants"); const yok_1 = require("../yok"); const proxyLib = require("proxy-lib"); class ProxyService { constructor($settingsService, $staticConfig) { this.$settingsService = $settingsService; this.$staticConfig = $staticConfig; this.proxyCacheFilePath = path.join(this.$settingsService.getProfileDir(), constants_1.Proxy.CACHE_FILE_NAME); this.credentialsKey = `${this.$staticConfig.CLIENT_NAME}_PROXY`; } setCache(settings) { settings.userSpecifiedSettingsFilePath = settings.userSpecifiedSettingsFilePath || this.proxyCacheFilePath; settings.credentialsKey = settings.credentialsKey || this.credentialsKey; return proxyLib.setProxySettings(settings); } getCache() { const settings = { credentialsKey: this.credentialsKey, userSpecifiedSettingsFilePath: this.proxyCacheFilePath, }; return proxyLib.getProxySettings(settings); } clearCache() { const settings = { credentialsKey: this.credentialsKey, userSpecifiedSettingsFilePath: this.proxyCacheFilePath, }; return proxyLib.clearProxySettings(settings); } async getInfo() { let message = ""; const proxyCache = await this.getCache(); if (proxyCache) { message = `Proxy Url: ${proxyCache.protocol}//${proxyCache.hostname}:${proxyCache.port}`; if (proxyCache.username) { message += `${os_1.EOL}Username: ${proxyCache.username}`; } message += `${os_1.EOL}Proxy is Enabled`; } else { message = "No proxy set"; } return message; } } exports.ProxyService = ProxyService; yok_1.injector.register("proxyService", ProxyService); //# sourceMappingURL=proxy-service.js.map