Ejemplo n.º 1
0
 private void ProcessNpmInstall(string projectPath)
 {
     try
     {
         UpdateStatusMessage("Clearing NPM cache...");
         NodePackageUtils.NpmClearCache(projectPath);
         UpdateStatusMessage("Running NPM install...");
         OutputWindowWriter.WriteLine("--- NPM install started ---");
         NodePackageUtils.RunNpmInstall(projectPath,
                                        (sender, args) =>
         {
             if (!string.IsNullOrEmpty(args.Data))
             {
                 var s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                 OutputWindowWriter.WriteLine(s);
             }
         },
                                        (sender, args) =>
         {
             if (!string.IsNullOrEmpty(args.Data))
             {
                 var s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                 OutputWindowWriter.WriteLine(s);
             }
         }, 600);
         UpdateStatusMessage("Ready");
         StatusBar.Clear();
     }
     catch (Exception exception)
     {
         OutputWindowWriter.WriteLine("An error has occurred during an NPM install");
         OutputWindowWriter.WriteLine("NPM install failed: " + exception.Message);
     }
     OutputWindowWriter.WriteLine("--- NPM install complete ---");
 }
        private void ProcessTypingsInstall(string projectPath)
        {
            if (skipTypings)
            {
                return;
            }
            try
            {
                var appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                if (!File.Exists(Path.Combine(projectPath, "typings.json")))
                {
                    return;
                }
                if (!NodePackageUtils.HasTypingsOnPath())
                {
                    var npmFolder = Path.Combine(appDataFolder, "npm");
                    npmFolder.AddToPathEnvironmentVariable();
                }

                UpdateStatusMessage("Downloading typings depedencies...");
                NodePackageUtils.RunTypingsInstall(projectPath, (sender, args) =>
                {
                    if (!string.IsNullOrEmpty(args.Data))
                    {
                        var s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                        OutputWindowWriter.WriteLine(s);
                    }
                }, (sender, args) =>
                {
                    if (!string.IsNullOrEmpty(args.Data))
                    {
                        var s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                        OutputWindowWriter.WriteLine(s);
                    }
                });
            }
            catch (Exception exception)
            {
                MessageBox.Show(@"Typings install failed: " + exception.Message,
                                @"An error has occurred during a Typings install.",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1,
                                MessageBoxOptions.DefaultDesktopOnly,
                                false);
            }
        }
Ejemplo n.º 3
0
 private void StartRequiredPackageInstallations()
 {
     try
     {
         // Initialize the progress _bar.
         StatusBar.Progress(ref _progressRef, 1, "", 0, 0);
         OutputWindowWriter.Show();
         for (var index = 0; index < _npmPackages.Count; index++)
         {
             var package = _npmPackages[index];
             UpdateStatusMessage("Installing required NPM package '" + package.Id + "'...");
             package.InstallGlobally(
                 (sender, args) =>
             {
                 if (!string.IsNullOrEmpty(args.Data))
                 {
                     var s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                     OutputWindowWriter.WriteLine(s);
                 }
             },
                 (sender, args) =>
             {
                 if (!string.IsNullOrEmpty(args.Data))
                 {
                     var s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                     OutputWindowWriter.WriteLine(s);
                 }
             });     //Installs global npm package if missing
             StatusBar.Progress(ref _progressRef, 1, "", Convert.ToUInt32(index),
                                Convert.ToUInt32(_npmPackages.Count));
         }
     }
     catch (ProcessException pe)
     {
         MessageBox.Show(@"An error has occurred during a NPM package installation - " + pe.Message,
                         @"An error has occurred during a NPM package installation.",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Error,
                         MessageBoxDefaultButton.Button1,
                         MessageBoxOptions.DefaultDesktopOnly,
                         false);
         throw new WizardBackoutException("An error has occurred during a NPM package installation.");
     }
     catch (TimeoutException te)
     {
         MessageBox.Show(@"An NPM install has timed out - " + te.Message,
                         @"An error has occurred during a NPM package installation.",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Error,
                         MessageBoxDefaultButton.Button1,
                         MessageBoxOptions.DefaultDesktopOnly,
                         false);
         throw new WizardBackoutException("An error has occurred during a NPM package installation.");
     }
     catch (Exception e)
     {
         MessageBox.Show(@"An error has occurred during a NPM package installation." + e.Message,
                         @"An error has occurred during a NPM package installation.",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Error,
                         MessageBoxDefaultButton.Button1,
                         MessageBoxOptions.DefaultDesktopOnly,
                         false);
         throw new WizardBackoutException("An error has occurred during a NPM package installation.");
     }
 }
        public static void TryBowerInstall(this Document document, OutputWindowWriter windowWriter)
        {
            lock (BowerStartingLock)
            {
                if (_bowerInstallRunning)
                {
                    return;
                }
                windowWriter.Show();
                windowWriter.WriteLine("--- Bower install started ---");
                Task.Run(() =>
                {
                    try
                    {
                        NodePackageUtils.RunBowerInstall(document.Path,
                            (sender, args) =>
                            {
                                if (string.IsNullOrEmpty(args.Data))
                                {
                                    return;
                                }
                                string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                                windowWriter.WriteLine(s);
                            },
                            (sender, args) =>
                            {
                                if (string.IsNullOrEmpty(args.Data))
                                {
                                    return;
                                }
                                string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                                windowWriter.WriteLine(s);
                            });
                    }
                    catch (Exception e)
                    {
                        windowWriter.WriteLine(e.Message);
                    }

                    lock (BowerRunningLock)
                    {
                        _bowerInstallRunning = false;
                    }
                    windowWriter.WriteLine("--- Bower install complete ---");
                });
                lock (BowerRunningLock)
                {
                    _bowerInstallRunning = true;
                }
            }
        }
Ejemplo n.º 5
0
        public void ProjectFinishedGenerating(Project project)
        {
            string projectPath = project.FullName.Substring(0,
                                                            project.FullName.LastIndexOf("\\", StringComparison.Ordinal));

            System.Threading.Tasks.Task.Run(() =>
            {
                StartRequiredPackageInstallations();
                try
                {
                    if (!NodePackageUtils.HasBowerOnPath())
                    {
                        string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                        string npmFolder     = Path.Combine(appDataFolder, "npm");
                        npmFolder.AddToPathEnvironmentVariable();
                    }
                    UpdateStatusMessage("Downloading bower depedencies...");
                    NodePackageUtils.RunBowerInstall(projectPath, (sender, args) =>
                    {
                        if (!string.IsNullOrEmpty(args.Data))
                        {
                            string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                            OutputWindowWriter.WriteLine(s);
                        }
                    }, (sender, args) =>
                    {
                        if (!string.IsNullOrEmpty(args.Data))
                        {
                            string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                            OutputWindowWriter.WriteLine(s);
                        }
                    });
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Bower install failed: " + exception.Message,
                                    "An error has occurred during a Bower install.",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error,
                                    MessageBoxDefaultButton.Button1,
                                    MessageBoxOptions.DefaultDesktopOnly,
                                    false);
                }
            }).Wait();

            UpdateStatusMessage("Downloading NPM depedencies...");
            OutputWindowWriter.ShowOutputPane(dte);
            System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    UpdateStatusMessage("Clearing NPM cache...");
                    NodePackageUtils.NpmClearCache(projectPath);
                    UpdateStatusMessage("Running NPM install...");
                    OutputWindowWriter.WriteLine("--- NPM install started ---");
                    NodePackageUtils.RunNpmInstall(projectPath,
                                                   (sender, args) =>
                    {
                        if (!string.IsNullOrEmpty(args.Data))
                        {
                            string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                            OutputWindowWriter.WriteLine(s);
                        }
                    },
                                                   (sender, args) =>
                    {
                        if (!string.IsNullOrEmpty(args.Data))
                        {
                            string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                            OutputWindowWriter.WriteLine(s);
                        }
                    }, 600);
                    UpdateStatusMessage("Ready");
                    StatusBar.Clear();
                }
                catch (Exception exception)
                {
                    OutputWindowWriter.WriteLine("An error has occurred during an NPM install");
                    OutputWindowWriter.WriteLine("NPM install failed: " + exception.Message);
                }
                OutputWindowWriter.WriteLine("--- NPM install complete ---");
            });
        }
        private static void BowerDocumentHandler(Document document, OutputWindowWriter windowWriter)
        {
            if (document.IsBowerUpdateDisabled())
            {
                return;
            }

            _hasBowerInstalled = _hasBowerInstalled ? _hasBowerInstalled : NodePackageUtils.HasBowerOnPath();

            if (!_hasBowerInstalled)
            {
                windowWriter.Show();
                windowWriter.WriteLine(
                    "Bower Installation not detected. Run npm install bower -g to install if Node.js/NPM already installed.");
                return;
            }
            document.TryBowerInstall(windowWriter);
        }
        private static void NpmDocumentHandler(Document document, OutputWindowWriter windowWriter)
        {
            if (document.IsNpmUpdateDisable())
            {
                return;
            }

            _hasNpmInstalled = _hasNpmInstalled
                ? _hasNpmInstalled
                : NodePackageUtils.TryRegisterNpmFromDefaultLocation();

            if (!_hasNpmInstalled)
            {
                windowWriter.Show();
                windowWriter.WriteLine("Node.js Installation not detected. Visit http://nodejs.org/ to download.");
                return;
            }
            document.TryRunNpmInstall(windowWriter);
        }
        private static void HandleDtoUpdate(Document document, INativeTypesHandler typesHandler,
            OutputWindowWriter outputWindowWriter)
        {
            string fullPath = document.ProjectItem.GetFullPath();
            outputWindowWriter.ShowOutputPane(document.DTE);
            outputWindowWriter.Show();
            outputWindowWriter.WriteLine(
                "--- Updating ServiceStack Reference '" +
                fullPath.Substring(fullPath.LastIndexOf("\\", StringComparison.Ordinal) + 1) +
                "' ---");
            var existingGeneratedCode = File.ReadAllLines(fullPath).Join(Environment.NewLine);
            string baseUrl;
            if (!typesHandler.TryExtractBaseUrl(existingGeneratedCode, out baseUrl))
            {
                outputWindowWriter.WriteLine("Failed to update ServiceStack Reference: Unabled to find BaseUrl");
                return;
            }
            try
            {
                var options = typesHandler.ParseComments(existingGeneratedCode);
                string updatedCode = typesHandler.GetUpdatedCode(baseUrl, options);

                //Can't work out another way that ensures UI is updated.
                //Overwriting the file inconsistently prompts the user that file has changed.
                //Sometimes old code persists even though file has changed.
                document.Close();
                using (var streamWriter = File.CreateText(fullPath))
                {
                    streamWriter.Write(updatedCode);
                    streamWriter.Flush();
                }
                //HACK to ensure new file is loaded
                Task.Run(() => { document.DTE.ItemOperations.OpenFile(fullPath); });
            }
            catch (Exception e)
            {
                outputWindowWriter.WriteLine("Failed to update ServiceStack Reference: Unhandled error - " + e.Message);
            }

            outputWindowWriter.WriteLine("--- Update ServiceStack Reference Complete ---");
        }