adamralph / bau

The C# task runner
MIT License
152 stars 17 forks source link

Directory task #186

Open adamralph opened 9 years ago

adamralph commented 9 years ago
.Directory("artifacts/output")

.NuGetPack("pack").DependsOn("build", "clobber", "artifacts/output").Do(nuget => nuget
    .Files("MyProject.csproj")
    .Output("artifacts/output"))

(Of course, individual plugins can also build in the ability to create folders on the fly if it makes sense in those contexts.)

aarondandy commented 9 years ago

Here is an example of one of my create directory tasks for some ideas on usage.

.Task("create-artifact-folders").Do(() => {
    var dirsToCreate = new[] {
        artifactDir,
        nugetOutputDir,
        logsDir
    }.Where(di => !di.Exists);
    foreach(var di in dirsToCreate) {
        di.Create();
    }
    System.Threading.Thread.Sleep(100);
})

would be much better as

.Directory("create-artifact-folders").Do(d => d.Create(artifactDir, nugetOutputDir, logsDir));

adamralph commented 9 years ago

I envisage the .Directory() task as just taking a single path which would also serve as the task name, but there could also be a .Directories("foo").Do(() => directories.Paths(artifactDir, nugetOutputDir, logsDir))

aarondandy commented 9 years ago

Only partially related to the issue:

I have started defining DirectoryInfo and FileInfo instances at the top of my baufile instead of using strings. It's not for everybody but as time goes on I find myself using it more. For example instead of needing to use the snippet I pasted above I am now doing this: OutDir = artifactDir.CreateSubdirectory("publishTemp").FullName as CreateSubdirectory does nothing if the directory already exists.

adamralph commented 9 years ago

Can use the outcome of #187