Exemple #1
0
        /// <summary>
        ///     Parses XML from WizardData and installs required npm packages
        /// </summary>
        /// <example>
        ///     <![CDATA[
        /// <NodeJS>
        ///     <npm-package id="grunt"/>
        ///     <npm-package id="grunt-cli" />
        ///     <npm-package id="gulp" />
        ///     <npm-package id="bower" />
        /// </NodeJS>]]>
        /// </example>
        /// <param name="automationObject"></param>
        /// <param name="replacementsDictionary"></param>
        /// <param name="runKind"></param>
        /// <param name="customParams"></param>
        public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary,
                               WizardRunKind runKind, object[] customParams)
        {
            _dte = (DTE)automationObject;

            using (var serviceProvider = new ServiceProvider((IServiceProvider)automationObject))
            {
                var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
                using (var container = new CompositionContainer(componentModel.DefaultExportProvider))
                {
                    container.ComposeParts(this);
                }
            }
            var wizardData = replacementsDictionary["$wizarddata$"];
            //HACK WizardData looks like root node, but not passed to this arg so we wrap it.
            //Problem is that only one SHARED WizardData node is supported and multiple wizards might use it.
            var element = XElement.Parse("<WizardData>" + wizardData + "</WizardData>");

            _npmPackages =
                element.Descendants()
                .Where(x => x.Name.LocalName.EqualsIgnoreCase("npm-package"))
                .Select(x => new NpmPackage {
                Id = x.Attribute("id").Value
            })
                .ToList();

            if (NodePackageUtils.TryRegisterNpmFromDefaultLocation())
            {
                if (!NodePackageUtils.HasBowerOnPath())
                {
                    UpdateStatusMessage("Installing bower...");
                    NodePackageUtils.InstallNpmPackageGlobally("bower");
                }
            }
        }
Exemple #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 ---");
 }
Exemple #3
0
        /// <summary>
        /// Parses XML from WizardData and installs required npm packages
        /// </summary>
        /// <example>
        /// <![CDATA[
        /// <NodeJS>
        ///     <npm-package id="grunt"/>
        ///     <npm-package id="grunt-cli" />
        ///     <npm-package id="gulp" />
        ///     <npm-package id="bower" />
        /// </NodeJS>]]>
        /// </example>
        /// <param name="automationObject"></param>
        /// <param name="replacementsDictionary"></param>
        /// <param name="runKind"></param>
        /// <param name="customParams"></param>
        public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary,
                               WizardRunKind runKind, object[] customParams)
        {
            dte = (DTE)automationObject;
            string wizardData = replacementsDictionary["$wizarddata$"];
            //HACK WizardData looks like root node, but not passed to this arg so we wrap it.
            //Problem is that only one SHARED WizardData node is supported and multiple extensions might use it.
            XElement element = XElement.Parse("<WizardData>" + wizardData + "</WizardData>");

            npmPackages =
                element.Descendants()
                .Where(x => x.Name.LocalName.EqualsIgnoreCase("npm-package"))
                .Select(x => new NpmPackage {
                Id = x.Attribute("id").Value
            })
                .ToList();

            if (NodePackageUtils.TryRegisterNpmFromDefaultLocation())
            {
                if (!NodePackageUtils.HasBowerOnPath())
                {
                    UpdateStatusMessage("Installing bower...");
                    NodePackageUtils.InstallNpmPackageGlobally("bower");
                }
            }
        }
 public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
 {
     if (runKind == WizardRunKind.AsMultiProject)
     {
         if (!NodePackageUtils.TryRegisterNpmFromDefaultLocation())
         {
             var form = new NodeJSInstallationPrompt();
             form.ShowDialog();
             if (!form.NodeFoundOnPath)
             {
                 //Advise to restart VS and backout?
                 throw new WizardBackoutException("Node.js installation required");
             }
         }
     }
 }
        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);
            }
        }
Exemple #6
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 ---");
            });
        }