Skip to content

Commit

Permalink
Add clean command
Browse files Browse the repository at this point in the history
  • Loading branch information
enisn committed Nov 20, 2023
1 parent 766de93 commit 669a764
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
45 changes: 45 additions & 0 deletions src/AbpDevTools/Commands/CleanCommand.cs
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.");
}
}
3 changes: 2 additions & 1 deletion src/AbpDevTools/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public static CliApplicationBuilder BuildServices(this CliApplicationBuilder bui
typeof(EnvironmentConfigurationCommand),
typeof(AbpBundleCommand),
typeof(TestCommand),
typeof(UpdateCheckCommand)
typeof(UpdateCheckCommand),
typeof(CleanCommand)
};

foreach (var commandType in commands)
Expand Down
2 changes: 1 addition & 1 deletion src/AbpDevTools/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"AbpDevTools": {
"commandName": "Project",
"commandLineArgs": "migrate C:\\P\\volo\\abp\\test-app\\aspnet-core\\src --no-build -e s"
"commandLineArgs": ""
}
}
}

0 comments on commit 669a764

Please sign in to comment.