From f03a41d799db36c9089d47f689e21cb39eca0935 Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Tue, 28 Nov 2023 20:56:57 +0300 Subject: [PATCH] Add configuration to the Clean command --- src/AbpDevTools/Commands/CleanCommand.cs | 14 +++---- .../Commands/ConfigurationCommand.cs | 26 ++++++++++++ .../Configuration/CleanConfiguration.cs | 41 +++++++++++++++++++ src/AbpDevTools/Program.cs | 2 + 4 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 src/AbpDevTools/Configuration/CleanConfiguration.cs diff --git a/src/AbpDevTools/Commands/CleanCommand.cs b/src/AbpDevTools/Commands/CleanCommand.cs index 24f152b..ec6507e 100644 --- a/src/AbpDevTools/Commands/CleanCommand.cs +++ b/src/AbpDevTools/Commands/CleanCommand.cs @@ -1,4 +1,5 @@ -using CliFx.Infrastructure; +using AbpDevTools.Configuration; +using CliFx.Infrastructure; using Spectre.Console; namespace AbpDevTools.Commands; @@ -9,13 +10,6 @@ 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)) @@ -23,6 +17,10 @@ public async ValueTask ExecuteAsync(IConsole console) WorkingDirectory = Directory.GetCurrentDirectory(); } + var foldersToDelete = CleanConfiguration.GetOptions() + .Folders.Select(x => Path.DirectorySeparatorChar + x) + .ToArray(); + await AnsiConsole.Status() .StartAsync("Looking for directories...", async ctx => { diff --git a/src/AbpDevTools/Commands/ConfigurationCommand.cs b/src/AbpDevTools/Commands/ConfigurationCommand.cs index 23680cd..0ae1a9c 100644 --- a/src/AbpDevTools/Commands/ConfigurationCommand.cs +++ b/src/AbpDevTools/Commands/ConfigurationCommand.cs @@ -5,6 +5,20 @@ namespace AbpDevTools.Commands; +[Command("config")] +public class ConfigCommand : ICommand +{ + public async ValueTask ExecuteAsync(IConsole console) + { + await console.Output.WriteLineAsync("Available commands:\n"); + await console.Output.WriteLineAsync("- replace config"); + await console.Output.WriteLineAsync("- envapp config"); + await console.Output.WriteLineAsync("- run config"); + await console.Output.WriteLineAsync("- clean config"); + await console.Output.WriteLineAsync("- config clear | Resets all the configurations to defaults."); + } +} + public abstract class ConfigurationBaseCommand : ICommand { protected abstract string FilePath { get; } @@ -58,3 +72,15 @@ public override ValueTask ExecuteAsync(IConsole console) return base.ExecuteAsync(console); } } + +[Command("clean config")] +public class CleanConfigurationCommand : ConfigurationBaseCommand +{ + protected override string FilePath => CleanConfiguration.FilePath; + + public override ValueTask ExecuteAsync(IConsole console) + { + CleanConfiguration.GetOptions(); + return base.ExecuteAsync(console); + } +} diff --git a/src/AbpDevTools/Configuration/CleanConfiguration.cs b/src/AbpDevTools/Configuration/CleanConfiguration.cs new file mode 100644 index 0000000..e457c7d --- /dev/null +++ b/src/AbpDevTools/Configuration/CleanConfiguration.cs @@ -0,0 +1,41 @@ +using System.Text.Json; + +namespace AbpDevTools.Configuration; +public static class CleanConfiguration +{ + public static string FolderPath => Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "abpdev"); + public static string FilePath => Path.Combine(FolderPath, "clean-configuration.json"); + + public static CleanOptions GetOptions() + { + if (!Directory.Exists(FolderPath)) + Directory.CreateDirectory(FolderPath); + + var options = new CleanOptions(); + if (File.Exists(FilePath)) + { + options = JsonSerializer.Deserialize(File.ReadAllText(FilePath)); + } + else + { + File.WriteAllText(FilePath, JsonSerializer.Serialize(options, new JsonSerializerOptions + { + WriteIndented = true + })); + } + + return options; + } +} + +public class CleanOptions +{ + public string[] Folders { get; set; } = new[] + { + "bin", + "obj", + "node_modules", + }; +} \ No newline at end of file diff --git a/src/AbpDevTools/Program.cs b/src/AbpDevTools/Program.cs index 12bc934..4ff0c3a 100644 --- a/src/AbpDevTools/Program.cs +++ b/src/AbpDevTools/Program.cs @@ -35,6 +35,8 @@ public static CliApplicationBuilder BuildServices(this CliApplicationBuilder bui typeof(ReplaceConfigurationCommand), typeof(EnvironmentAppConfigurationCommand), typeof(RunConfigurationCommand), + typeof(CleanConfigurationCommand), + typeof(ConfigCommand), typeof(DisableNotificationsCommand), typeof(EnableNotificationsCommand), typeof(EnvironmentAppCommand),