public void ProjectFinishedGenerating(Project project)
        {
            var projectPath = project.FullName.Substring(0,
                                                         project.FullName.LastIndexOf("\\", StringComparison.Ordinal));

            //npm package.json validation requires lower-case names:
            var packageJsonPath = Path.Combine(projectPath, "package.json");

            if (projectName != null && File.Exists(packageJsonPath))
            {
                var originalContent = File.ReadAllText(packageJsonPath);
                var proectNameKebab = projectName.SplitCamelCase().Replace(" ", "-").ToLower();

                File.WriteAllText(packageJsonPath, originalContent
                                  .ReplaceAll($"\"{projectName}\"", $"\"{proectNameKebab}\""));
            }

            Task.Run(() => { StartRequiredPackageInstallations(); }).Wait();
            // Typings isn't supported by any built in VS features.. yet.., run manually and wait
            // This is due to problem with TSX intellisense which is fixed if project reloaded.
            // This is to ensure *.d.ts files are ready when template first loads
            Task.Run(() => { ProcessTypingsInstall(projectPath); }).Wait();
            //Only run Bower/NPM install via SSVS for VS 2012/2013
            //VS2015 built in Task Runner detects and runs required installs.
            //VS2013 Update 5 also does package restore on load.
            if (MajorVisualStudioVersion == 12 && !ExtensionManager.HasExtension("Package Intellisense") || MajorVisualStudioVersion == 11)
            {
                Task.Run(() => { ProcessBowerInstall(projectPath); }).Wait();

                UpdateStatusMessage("Downloading NPM depedencies...");
                OutputWindowWriter.ShowOutputPane(dte);

                Task.Run(() => { ProcessNpmInstall(projectPath); });
            }
        }
Esempio n. 2
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 ---");
 }
 public static void HandleDocumentSaved(Document document, OutputWindowWriter windowWriter)
 {
     foreach (var filterWatcher in FilterWatchers)
     {
         var predicate = filterWatcher.Key;
         var fileHandler = filterWatcher.Value;
         if (!predicate(document))
         {
             continue;
         }
         fileHandler(document, windowWriter);
         break;
     }
 }
        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);
            }
        }
        public void ProjectFinishedGenerating(Project project)
        {
            var projectPath = project.FullName.Substring(0,
                                                         project.FullName.LastIndexOf("\\", StringComparison.Ordinal));

            Task.Run(() => { StartRequiredPackageInstallations(); });
            //Only run Bower/NPM insatll via SSVS for VS 2012/2013
            //VS2015 built in Task Runner detects and runs required installs.
            if (MajorVisualStudioVersion < 14)
            {
                Task.Run(() => { ProcessBowerInstall(projectPath); }).Wait();

                UpdateStatusMessage("Downloading NPM depedencies...");
                OutputWindowWriter.ShowOutputPane(_dte);

                Task.Run(() => { ProcessNpmInstall(projectPath); });
            }
        }
        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);
        }
Esempio n. 7
0
        public void ProjectFinishedGenerating(Project project)
        {
            var projectPath = project.FullName.Substring(0,
                                                         project.FullName.LastIndexOf("\\", StringComparison.Ordinal));

            Task.Run(() => { StartRequiredPackageInstallations(); }).Wait();
            // Typings isn't supported by any built in VS features.. yet.., run manually and wait
            // This is due to problem with TSX intellisense which is fixed if project reloaded.
            // This is to ensure *.d.ts files are ready when template first loads
            Task.Run(() => { ProcessTypingsInstall(projectPath); }).Wait();
            //Only run Bower/NPM install via SSVS for VS 2012/2013
            //VS2015 built in Task Runner detects and runs required installs.
            //VS2013 Update 5 also does package restore on load.
            if (MajorVisualStudioVersion == 12 && !ExtensionManager.HasExtension("Package Intellisense") || MajorVisualStudioVersion == 11)
            {
                Task.Run(() => { ProcessBowerInstall(projectPath); }).Wait();

                UpdateStatusMessage("Downloading NPM depedencies...");
                OutputWindowWriter.ShowOutputPane(_dte);

                Task.Run(() => { ProcessNpmInstall(projectPath); });
            }
        }
Esempio n. 8
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;
                }
            }
        }
 public static void HandleDocumentSaved(this Document document, OutputWindowWriter windowWriter)
 {
     DocumentSavedHandlers.HandleDocumentSaved(document, windowWriter);
 }
Esempio n. 11
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 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 ---");
        }