diff --git a/README.md b/README.md index c91533b..9999aef 100644 --- a/README.md +++ b/README.md @@ -32,4 +32,20 @@ Get additional help using the `help` option: ```console nupu --help +``` + +### Ignoring directories + +Out of the box, NuPU ignores a list of directories to process like `bin`, `.git`, `packages`, and similar. You can override this behavior by creating a file named `.nupuignore` in a root folder you want to run the NuPU command in: + +``` +.git +.github +.vs +.vscode +bin +obj +packages +node_modules +my_custom_folder ``` \ No newline at end of file diff --git a/src/NuPU/UpdateCommand.cs b/src/NuPU/UpdateCommand.cs index 025c2b0..f4496af 100644 --- a/src/NuPU/UpdateCommand.cs +++ b/src/NuPU/UpdateCommand.cs @@ -36,9 +36,10 @@ public override async Task ExecuteAsync(CommandContext context, UpdateComma : updateCommandSettings.Directory; var rootDir = new DirectoryInfo(rootPath); + var ignoreDirs = ResolveIgnoreDirs(rootPath); + var csProjFiles = rootDir.EnumerateFiles("*.csproj", new EnumerationOptions { IgnoreInaccessible = true, RecurseSubdirectories = updateCommandSettings.Recursive }); - var ignoreDirs = new[] { ".git", ".github", ".vs", ".vscode", "bin", "obj", "packages", "node_modules" }; - foreach (var csProjFile in csProjFiles.Where(f => !ignoreDirs.Contains(f.DirectoryName))) + foreach (var csProjFile in csProjFiles.Where(f => !Ignored(f, ignoreDirs))) { var settings = Settings.LoadDefaultSettings(csProjFile.Directory.FullName); var enabledSources = SettingsUtility.GetEnabledSources(settings); @@ -178,6 +179,35 @@ public override async Task ExecuteAsync(CommandContext context, UpdateComma return 0; } + private bool Ignored(FileInfo fileInfo, List ignoreDirs) + { + if (ignoreDirs.Count == 0) return false; + + var directory = fileInfo.Directory; + while (directory != null) + { + if (ignoreDirs.Contains(directory.Name)) return true; + directory = directory.Parent; + } + + return false; + } + + private List ResolveIgnoreDirs(string rootPath) + { + var ignoreDirs = new List { ".git", ".github", ".vs", ".vscode", "bin", "obj", "packages", "node_modules" }; + + var nupuIgnore = Path.Combine(rootPath, ".nupuignore"); + if (File.Exists(nupuIgnore)) + { + AnsiConsole.MarkupLine($"Ignore directories in [yellow]{nupuIgnore}[/]"); + var lines = File.ReadAllLines(nupuIgnore); + ignoreDirs = lines.Where(l => !string.IsNullOrWhiteSpace(l)).ToList(); + } + + return ignoreDirs; + } + private static IEnumerable HighestRevision(IEnumerable versions, NuGetVersion nugetVersion) { var toReturn = new List();