Skip to content

Commit

Permalink
Add configuration to the Clean command
Browse files Browse the repository at this point in the history
  • Loading branch information
enisn committed Nov 28, 2023
1 parent 319cbe0 commit f03a41d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/AbpDevTools/Commands/CleanCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CliFx.Infrastructure;
using AbpDevTools.Configuration;
using CliFx.Infrastructure;
using Spectre.Console;

namespace AbpDevTools.Commands;
Expand All @@ -9,20 +10,17 @@ 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();
}

var foldersToDelete = CleanConfiguration.GetOptions()
.Folders.Select(x => Path.DirectorySeparatorChar + x)
.ToArray();

await AnsiConsole.Status()
.StartAsync("Looking for directories...", async ctx =>
{
Expand Down
26 changes: 26 additions & 0 deletions src/AbpDevTools/Commands/ConfigurationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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);
}
}
41 changes: 41 additions & 0 deletions src/AbpDevTools/Configuration/CleanConfiguration.cs
Original file line number Diff line number Diff line change
@@ -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<CleanOptions>(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",
};
}
2 changes: 2 additions & 0 deletions src/AbpDevTools/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit f03a41d

Please sign in to comment.