private bool IsGulpFile()
        {
            // gets the full path of the clicked file
            var path = SolutionHelpers.GetSourceFilePath();

            return((path.ToLower().IndexOf("gulpfile.js") != -1) || (path.ToLower().IndexOf("gulpfile.ts") != -1) || (path.ToLower().IndexOf("gulpfile.coffee") != -1));
        }
        /// <summary>
        ///     Determines if the current file is a gruntfile
        /// </summary>
        /// <returns>Boolean that indicates if the clicked file was a gruntfile</returns>
        private bool IsGruntFile()
        {
            // gets the full path of the clicked file
            var path = SolutionHelpers.GetSourceFilePath();

            return(path.ToLower().IndexOf("gruntfile.js") != -1);
        }
        /// <summary>
        /// Sets the visibility of the command and creates the dynamic list of commands
        /// </summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="e">Event arguments</param>
        private void SetVisibility(object sender, EventArgs e)
        {
            // gets the full path of the clicked file
            var path = SolutionHelpers.GetSourceFilePath();

            var myCommand = sender as OleMenuCommand;

            // if the currently selected file is a Gruntfile set the command to visible
            myCommand.Visible = this.IsGruntFile();


            if (!this.IsGruntFile() && !this.IsGulpFile())
            {
                this.lastFile = path;
            }

            if (!this.IsNewFile())
            {
                return;
            }



            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            // delete the old command list
            if (commands == null)
            {
                commands = new List <OleMenuCommand>();
            }

            foreach (var cmd in commands)
            {
                mcs.RemoveCommand(cmd);
            }

            if (myCommand.Visible)
            {
                this.lastFile = path;
                var list = GruntParser.ReadAllTasks(path);
                if (list.Contains("default"))
                {
                    list.Remove("default");
                }

                // creates the list of commands
                int j = 1;
                foreach (var ele in list)
                {
                    CommandID menuCommandID = new CommandID(GuidList.guidGruntLauncherCmdSet, (int)PkgCmdIDList.cmdidGruntLauncher + j);
                    j++;
                    OleMenuCommand command = new OleMenuCommand(this.MenuItemCallback, menuCommandID);
                    command.Text = "Grunt: " + ele;
                    command.BeforeQueryStatus += (x, y) => { (x as OleMenuCommand).Visible = true; };
                    commands.Add(command);
                    mcs.AddCommand(command);
                }
            }
        }
        private void NpmBeforeQueryStatus(object sender, EventArgs e)
        {
            OleMenuCommand button = (OleMenuCommand)sender;

            packageFile = SolutionHelpers.GetSourceFilePath();
            bool isPackage = Path.GetFileName(packageFile).Equals("package.json", StringComparison.OrdinalIgnoreCase);

            button.Visible = isPackage;
        }
        /// <summary>
        ///     Determines if the solution explorer context menu has been opened on a new file since
        ///     last time
        /// </summary>
        /// <returns>Boolean that indicates if a new file was clicked</returns>
        private bool IsNewFile()
        {
            // gets the full path of the clicked file
            var path = SolutionHelpers.GetSourceFilePath();

            // optimization to avoid parsing the file again if the clicked file has not changed since last time
            if (path == this.lastFile)
            {
                return(false);
            }

            return(true);
        }
        private static void RunProcess(OleMenuCommand cmd, string argument, bool fromRoot)
        {
            dte.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationBuild);

            try
            {
                System.Diagnostics.ProcessStartInfo procStartInfo = new ProcessStartInfo()
                {
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    StandardOutputEncoding = Encoding.UTF8,
                    StandardErrorEncoding  = Encoding.UTF8,
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                    WorkingDirectory       = fromRoot ? SolutionHelpers.GetRootFolder(dte) : Path.GetDirectoryName(SolutionHelpers.GetSourceFilePath()),
                    FileName  = "cmd",
                    Arguments = argument,
                };

                System.Diagnostics.Process proc = new System.Diagnostics.Process()
                {
                    StartInfo           = procStartInfo,
                    EnableRaisingEvents = true
                };

                OutputHelpers.Output("Executing " + cmd.Text + " \r\n\r\n", true);

                proc.OutputDataReceived += (object sendingProcess, DataReceivedEventArgs outLine) => OutputHelpers.Output(outLine.Data + "\r\n");
                proc.ErrorDataReceived  += (object sendingProcess, DataReceivedEventArgs outLine) => OutputHelpers.Output(outLine.Data + "\r\n");
                proc.Exited             += (x, y) =>
                {
                    processes.Remove(cmd);
                    cmd.Checked = false;
                    dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationBuild);
                };

                proc.Start();

                proc.BeginOutputReadLine();
                proc.BeginErrorReadLine();

                cmd.Checked = true;

                processes.Add(cmd, proc);
            }
            catch (Exception ex)
            {
                OutputHelpers.Output(ex.Message);
            }
        }
        private void UpdateBower(object sender, EventArgs e)
        {
            string         path   = SolutionHelpers.GetSourceFilePath();
            OleMenuCommand button = (OleMenuCommand)sender;

            if (isParent)
            {
                button.Text = "Update Bower Packages";
                RunProcess(button, " /c \"bower update 2>&1 \" ", true);
            }
            else if (isChild)
            {
                string bowerPackage = new DirectoryInfo(path).Name;
                RunProcess(button, " /c \"bower update " + bowerPackage + " 2>&1 \" ", true);
            }
        }
        private void BowerBeforeQueryStatus(object sender, EventArgs e)
        {
            OleMenuCommand button = (OleMenuCommand)sender;
            string         path   = SolutionHelpers.GetSourceFilePath();

            isParent = path.EndsWith("bower_components\\", StringComparison.OrdinalIgnoreCase);

            if (isParent)
            {
                button.Text = "Bower: Update all packages";
            }
            else
            {
                isChild     = Directory.GetParent(path).Parent.Name.EndsWith("bower_components", StringComparison.OrdinalIgnoreCase);
                button.Text = "Bower: Update " + Directory.GetParent(path).Name;
            }

            button.Visible = isParent || isChild;
        }
        private void GulpBeforeQueryStatus(object sender, EventArgs e)
        {
            // gets the full path of the clicked file
            var path = SolutionHelpers.GetSourceFilePath();

            var myCommand = sender as OleMenuCommand;

            myCommand.Visible = this.IsGulpFile();


            if (!this.IsNewFile())
            {
                return;
            }

            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            // delete the old command list
            if (commands == null)
            {
                commands = new List <OleMenuCommand>();
            }

            foreach (var cmd in commands)
            {
                mcs.RemoveCommand(cmd);
            }

            if (myCommand.Visible)
            {
                this.lastFile = path;

                var list = GulpParser.ReadAllTasks(path);

                myCommand.Text    = "Gulp";
                myCommand.Enabled = true;

                if (list.Count == 0)
                {
                    myCommand.Enabled = false;
                    myCommand.Text    = "Gulpfile.js not found";
                }

                if (list.Contains("default"))
                {
                    list.Remove("default");
                }

                string n = exclusionRegex;

                Regex a = null;

                if (!string.IsNullOrEmpty(n))
                {
                    try
                    {
                        a = new Regex(n);
                    }
                    catch (Exception)
                    {
                        // invalid regex -> ignore
                    }
                }

                // creates the list of commands
                int j = 1;
                foreach (var ele in list)
                {
                    if (a != null)
                    {
                        if (a.Match(ele).Success)
                        {
                            continue;
                        }
                    }


                    CommandID menuCommandID = new CommandID(GuidList.guidGruntLauncherCmdSet, (int)PkgCmdIDList.cmdidGulpLauncher + j);
                    j++;
                    OleMenuCommand command = new OleMenuCommand(this.GulpCallback, menuCommandID);
                    command.Text = "Gulp: " + ele;
                    command.BeforeQueryStatus += (x, y) => { (x as OleMenuCommand).Visible = true; };
                    commands.Add(command);
                    mcs.AddCommand(command);
                }
            }
        }