Beispiel #1
0
        public void Run_WithInstallCommandInSpecificWorkingDirectory_ModuleInstalledinWorkingDirectory()
        {
            // arrange
            var workingDirectory = new DirectoryInfo("NpmTest");

            workingDirectory.Create();

            var target = new NpmCli(Constants.DefaultNodeExePath);

            target.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);

            // act
            target.WorkingDirectory = workingDirectory.FullName;
            target.Run("install underscore");

            // assert
            Assert.IsTrue(Directory.Exists(Path.Combine(workingDirectory.FullName, "node_modules", "underscore")));
        }
Beispiel #2
0
        public void Run_WithHelpCommand_CanExecuteCommand()
        {
            // arrange
            var output = new StringBuilder();

            var target = new NpmCli(Constants.DefaultNodeExePath);

            target.OutputDataReceived += (sender, e) =>
            {
                output.AppendLine(e.Data);
                Console.WriteLine(e.Data);
            };

            // act
            target.Run("help");

            // assert
            Assert.IsTrue(output.ToString().Contains("Usage: npm <command>"));
        }
Beispiel #3
0
        protected override void InternalExecute()
        {
            if (!string.IsNullOrEmpty(this.WorkingDirectory.Get(this.ActivityContext)) && !Directory.Exists(this.WorkingDirectory.Get(this.ActivityContext)))
            {
                this.LogBuildError(string.Format(CultureInfo.CurrentCulture, "The working directory does not exist: {0}", this.WorkingDirectory.Get(this.ActivityContext)));
                return;
            }

            string        nodeExeFullPath  = this.NodeExePath.Get(this.ActivityContext).GetDefaultIfEmpty(Constants.DefaultNodeExePath).FindExePath();
            DirectoryInfo workingDirectory = this.WorkingDirectory.Get(this.ActivityContext).ToDirectoryInfo();
            string        npmCommand       = this.Command.Get(this.ActivityContext);

            using (var npm = new NpmCli(nodeExeFullPath))
            {
                npm.OutputDataReceived += this.OnOutputDataReceived;
                npm.ErrorDataReceived  += this.OnErrorDataReceived;

                npm.WorkingDirectory = workingDirectory.FullName;

                this.LogBuildMessage("Running npm command: " + npmCommand);
                npm.Run(npmCommand);
            }
        }