Пример #1
0
 private static void ConfigEnvironmentVariable(UrlTemplate urlTemplate)
 {
     if (urlTemplate.ClearData)
     {
         logger.Info("Clearing environment variable HTTP_PROXY and HTTPS_PROXY for current user");
         EnvironmentVariables.ClearHttpProxy(EnvironmentVariableTarget.User);
         EnvironmentVariables.ClearHttpsProxy(EnvironmentVariableTarget.User);
     }
     else
     {
         // Configure environment variables
         logger.Info("Setting environment variable HTTP_PROXY and HTTPS_PROXY for current user");
         logger.Info("A lot of applications such as: Ruby Gem, Ionic, Cordova, etc will be work with this configuration");
         if (urlTemplate.MustBeAuthenticated)
         {
             EnvironmentVariables.SetHttpProxy(urlTemplate.GetProxy(), EnvironmentVariableTarget.User);
             EnvironmentVariables.SetHttpsProxy(urlTemplate.GetProxySsl(), EnvironmentVariableTarget.User);
         }
         else
         {
             EnvironmentVariables.SetHttpProxy(urlTemplate.GetProxy(), EnvironmentVariableTarget.User);
             EnvironmentVariables.SetHttpsProxy(urlTemplate.GetProxySsl(), EnvironmentVariableTarget.User);
         }
     }
 }
Пример #2
0
        private static void ConfigBower(UrlTemplate urlTemplate)
        {
            // Configure bower
            if (Msdos.IsInstalled("bower.cmd"))
            {
                // bowerrc user file
                var bowerrc = Path.Combine(Windows.GetCurrentUserFolder(), ".bowerrc");

                if (urlTemplate.ClearData)
                {
                    logger.Info("Clearing proxy for bower");
                    Msdos.Run("npm.cmd", $@"config delete proxy");
                    Msdos.Run("npm.cmd", $@"config delete https-proxy");

                    if (File.Exists(bowerrc))
                    {
                        System.IO.File.Delete(bowerrc);
                    }
                }
                else
                {
                    logger.Info("Setting proxy for bower");
                    Msdos.Run("npm.cmd", $@"npm config set proxy {urlTemplate.GetProxy()}");
                    Msdos.Run("npm.cmd", $@"npm config set https-proxy {urlTemplate.GetProxySsl()}");

                    if (!File.Exists(bowerrc))
                    {
                        // create settings
                        var obj = new JObject();
                        obj.Add("proxy", urlTemplate.GetProxy());
                        obj.Add("https-proxy", urlTemplate.GetProxySsl());
                        obj.Add("no-proxy", urlTemplate.GetProxyExceptions());

                        System.IO.File.WriteAllText(bowerrc, obj.ToString());
                    }
                    else
                    {
                        // update settings
                        var content = System.IO.File.ReadAllText(bowerrc);
                        var obj     = JObject.Parse(content);
                        obj["proxy"]       = urlTemplate.GetProxy();
                        obj["https-proxy"] = urlTemplate.GetProxySsl();
                        obj["no-proxy"]    = urlTemplate.GetProxyExceptions();

                        System.IO.File.WriteAllText(bowerrc, obj.ToString());
                    }
                }
            }
        }
Пример #3
0
 private static void ConfigYarn(UrlTemplate urlTemplate)
 {
     // Configure yarn
     if (Msdos.IsInstalled("yarn.cmd"))
     {
         if (urlTemplate.ClearData)
         {
             logger.Info("Clearing proxy for yarn");
             Msdos.Run("yarn.cmd", $@"config delete proxy");
             Msdos.Run("yarn.cmd", $@"config delete https-proxy");
         }
         else
         {
             logger.Info("Setting proxy for yarn");
             Msdos.Run("yarn.cmd", $@"npm config set proxy {urlTemplate.GetProxy()}");
             Msdos.Run("yarn.cmd", $@"npm config set https-proxy {urlTemplate.GetProxySsl()}");
         }
     }
 }
Пример #4
0
 private static void ConfigGit(UrlTemplate urlTemplate)
 {
     // Configure GIT
     if (Msdos.IsInstalled("git.exe", "version"))
     {
         if (urlTemplate.ClearData)
         {
             logger.Info("Clearing proxy for GIT");
             Msdos.Run("git.exe", $"config --global --unset http.proxy");
             Msdos.Run("git.exe", $"config --global --unset https.proxy");
         }
         else
         {
             logger.Info("Setting proxy for GIT");
             Msdos.Run("git.exe", $"config --global http.proxy {urlTemplate.GetProxy()}");
             Msdos.Run("git.exe", $"config --global https.proxy {urlTemplate.GetProxySsl()}");
         }
     }
 }
Пример #5
0
        private static void ConfigNpm(UrlTemplate urlTemplate)
        {
            // Configure npm
            if (Msdos.IsInstalled("npm.cmd", "version"))
            {
                if (urlTemplate.ClearData)
                {
                    logger.Info("Clearing proxy for npm");
                    Msdos.Run("npm.cmd", $@"config delete proxy");
                    Msdos.Run("npm.cmd", $@"config delete https-proxy");
                }
                else
                {
                    logger.Info("Setting proxy for npm");
                    Msdos.Run("npm.cmd", $@"config set proxy {urlTemplate.GetProxy()}");
                    Msdos.Run("npm.cmd", $@"config set https-proxy {urlTemplate.GetProxySsl()}");

                    var npmrc = Path.Combine(Windows.GetCurrentUserFolder(), ".npmrc");
                    // npmrc file is managed automatically
                }
            }
        }