Exemple #1
0
        //private List<BowerPackage> bowerPackages;

        /// <summary>
        /// Parses XML from WizardData and installs required npm packages
        /// </summary>
        /// <example>
        /// <![CDATA[
        /// <NodeJSRequirements requiresNpm="true">
        ///     <npm-package id="grunt"/>
        ///     <npm-package id="grunt-cli" />
        ///     <npm-package id="gulp" />
        ///     <npm-package id="bower" />
        /// </NodeJSRequirements>]]>
        /// </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$"];
            XElement element    = XElement.Parse(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");
                }
            }

            //Not needed
            //bowerPackages =
            //    element.Descendants()
            //        .Where(x => x.Name.LocalName.EqualsIgnoreCase("bower-package"))
            //        .Select(x => new BowerPackage {Id = x.Attribute("id").Value})
            //        .ToList();
        }
 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");
             }
         }
     }
 }
Exemple #3
0
        public void ProjectFinishedGenerating(Project project)
        {
            //
            var outputWindowPane = _dte.Windows.Item(OutputWindowGuid); //Output window pane
            var _outputWindow    = new OutputWindowWriter(ServiceStackVSPackageCmdSetGuid, "ServiceStackVS");

            outputWindowPane.Visible = true;
            string projectPath = project.FullName.Substring(0,
                                                            project.FullName.LastIndexOf("\\", System.StringComparison.Ordinal));

            System.Threading.Tasks.Task.Run(() =>
            {
                StartRequiredPackageInstallations(_outputWindow);
                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);
                            _outputWindow.WriteLine(s);
                        }
                    }, (sender, args) =>
                    {
                        if (!string.IsNullOrEmpty(args.Data))
                        {
                            string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                            _outputWindow.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...");
            System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    UpdateStatusMessage("Clearing NPM cache...");
                    NodePackageUtils.NpmClearCache(projectPath);
                    UpdateStatusMessage("Running NPM install...");
                    NodePackageUtils.RunNpmInstall(projectPath,
                                                   (sender, args) =>
                    {
                        if (!string.IsNullOrEmpty(args.Data))
                        {
                            string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                            _outputWindow.WriteLine(s);
                        }
                    },
                                                   (sender, args) =>
                    {
                        if (!string.IsNullOrEmpty(args.Data))
                        {
                            string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                            _outputWindow.WriteLine(s);
                        }
                    }, 600);
                    _outputWindow.WriteLine("NPM Install complete");
                    UpdateStatusMessage("Ready");
                    StatusBar.Clear();
                }
                catch (Exception exception)
                {
                    _outputWindow.WriteLine("An error has occurred during an NPM install");
                    _outputWindow.WriteLine("NPM install failed: " + exception.Message);
                }
            });
        }