-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using CliFx.Infrastructure; | ||
using Spectre.Console; | ||
|
||
namespace AbpDevTools.Commands; | ||
|
||
[Command("clean", Description = "Cleans 'bin', 'obj' and 'node_modules' folders recursively.")] | ||
public class CleanCommand : ICommand | ||
{ | ||
[CommandParameter(0, IsRequired = false, Description = "Working directory to run build. Probably project or solution directory path goes here. Default: . (Current Directory)")] | ||
public string WorkingDirectory { get; set; } | ||
|
||
private static readonly string[] foldersToDelete = new[] | ||
{ | ||
Path.DirectorySeparatorChar + "bin", | ||
Path.DirectorySeparatorChar + "obj", | ||
Path.DirectorySeparatorChar + "node_modules" | ||
}; | ||
|
||
public async ValueTask ExecuteAsync(IConsole console) | ||
{ | ||
if (string.IsNullOrEmpty(WorkingDirectory)) | ||
{ | ||
WorkingDirectory = Directory.GetCurrentDirectory(); | ||
} | ||
|
||
await AnsiConsole.Status() | ||
.StartAsync("Looking for directories...", async ctx => | ||
{ | ||
ctx.Spinner(Spinner.Known.SimpleDotsScrolling); | ||
await Task.Yield(); | ||
var directories = Directory.EnumerateDirectories(WorkingDirectory, string.Empty, SearchOption.AllDirectories) | ||
.Where(x => foldersToDelete.Any(a => x.EndsWith(a))); | ||
foreach (var directory in directories) | ||
{ | ||
ctx.Status($"Deleting {directory}..."); | ||
Directory.Delete(directory, true); | ||
} | ||
}); | ||
|
||
console.Output.WriteLine("Cleaned successfully."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters