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); });
            }
        }
Ejemplo n.º 2
0
        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); });
            }
        }
Ejemplo n.º 3
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); });
            }
        }
Ejemplo n.º 4
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 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 ---");
        }