public IEnumerable<IGooseAction> Create(ActionConfiguration configuration, IEnumerable<string> files) { if (configuration.IsValid) { foreach (var file in files) { var workingDirectory = Path.Combine(configuration.ProjectRoot, configuration.RelativeWorkingDirectory); var environmentVariables = new CommandEvironmentVariables(file); var command = this.commandBuilder.Build(configuration, environmentVariables); yield return new PowerShellGooseAction(this.powerShellTaskFactory, command); if (!CommandScope.File.Equals(configuration.Scope)) { yield break; } } } }
public ShellCommand Build(ActionConfiguration configuration, CommandEvironmentVariables environmentVariables) { var solutionRoot = configuration.SolutionRoot; var projectRoot = configuration.ProjectRoot; var relativeWorkingDirectory = configuration.RelativeWorkingDirectory; var absoluteWorkingDirectory = Path.Combine(projectRoot, relativeWorkingDirectory); var absoluteFilePath = environmentVariables.FilePath; var relativeFilePath = string.IsNullOrEmpty(projectRoot) ? absoluteFilePath : absoluteFilePath.Replace(projectRoot, "").TrimStart('\\', '/'); var payload = configuration.Command .Replace("{absolute-file-path}", absoluteFilePath) .Replace("{relative-file-path}", relativeFilePath) .Replace("{solution-root}", solutionRoot) .Replace("{project-root}", projectRoot) .Replace("{working-directory}", absoluteWorkingDirectory); return new ShellCommand(absoluteWorkingDirectory, payload); }