Esempio n. 1
0
        /// <summary>
        ///     Handles npm command.
        /// </summary>
        /// <param name="parameters">Parameters.</param>
        private void HandleNpmCommand(string[] parameters)
        {
            string setDirectory = string.Format(@"set-location ""{0}""", _solutionManager.ActiveProjectPath);
            var    command      = string.Format("npm {0}", string.Join(" ", parameters));
            Collection <PSObject> results;

            using (PowerShell shell = PowerShell.Create())
            {
                shell.AddScript(setDirectory);
                shell.AddScript(command);

                shell.Streams.Progress.DataAdded += OnProgress;
                shell.Streams.Error.DataAdded    += OnError;
                shell.Streams.Verbose.DataAdded  += OnVerbose;
                shell.Streams.Warning.DataAdded  += OnWarning;

                results = shell.Invoke();
            }

            foreach (PSObject result in results)
            {
                WriteLine(result.ToString());
            }

            WriteLine();

            if (parameters.Length < 2)
            {
                return;
            }

            switch (parameters[0].ToLowerInvariant())
            {
            case "install":
            {
                var path = string.Format(@"{0}\node_modules\{1}", _solutionManager.ActiveProjectPath, parameters[1]);
                _solutionManager.AddDirectory(path);
            }
            break;

            case "uninstall":
            {
                var path = string.Format(@"node_modules\{0}", parameters[1]);
                _solutionManager.RemoveDirectory(path);
            }
            break;
            }
        }