Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bundle list command #13

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 9 additions & 28 deletions src/AbpDevTools/Commands/AbpBundleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public class AbpBundleCommand : ICommand
public bool GraphBuild { get; set; }

protected IConsole? console;
protected AbpBundleListCommand listCommand;

public AbpBundleCommand(AbpBundleListCommand listCommand)
{
this.listCommand = listCommand;
}

public async ValueTask ExecuteAsync(IConsole console)
{
Expand All @@ -37,10 +43,7 @@ public async ValueTask ExecuteAsync(IConsole console)

await Task.Yield();

return Directory.EnumerateFiles(WorkingDirectory, "*.csproj", SearchOption.AllDirectories)
.Where(IsCsprojBlazorWasm)
.Select(x => new FileInfo(x))
.ToArray();
return listCommand.GetWasmProjects();
});

if (wasmCsprojs.Length == 0)
Expand All @@ -56,7 +59,8 @@ public async ValueTask ExecuteAsync(IConsole console)
{
if (GraphBuild)
{
var compiled = await AnsiConsole.Status().StartAsync($"[grey]Building {csproj.Name}...[/]", async (ctx) =>
var index = Array.IndexOf(wasmCsprojs, csproj) + 1;
var compiled = await AnsiConsole.Status().StartAsync($"[grey]{index/wasmCsprojs.Length} Building {csproj.Name}...[/]", async (ctx) =>
{
ctx.Spinner(Spinner.Known.SimpleDotsScrolling);

Expand Down Expand Up @@ -107,27 +111,4 @@ public async ValueTask ExecuteAsync(IConsole console)
});
}
}

static bool IsCsprojBlazorWasm(string file)
{
using var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read);
using var streamReader = new StreamReader(fileStream, Encoding.UTF8, true);

for (int i = 0; i < 4; i++)
{
var line = streamReader.ReadLine();

if (string.IsNullOrEmpty(line))
{
continue;
}

if (line.Contains("Sdk=\"Microsoft.NET.Sdk.BlazorWebAssembly\""))
{
return true;
}
}

return false;
}
}
62 changes: 62 additions & 0 deletions src/AbpDevTools/Commands/AbpBundleListCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Text;
using CliFx.Infrastructure;

[Command("bundle list", Description = "List projects that needs to run 'abp bundle'.")]
public class AbpBundleListCommand : ICommand
{
[CommandParameter(0, IsRequired = false, Description = "Working directory for the command. Probably project or solution directory path goes here. Default: . (Current Directory)")]
public string? WorkingDirectory { get; set; }

public async ValueTask ExecuteAsync(IConsole console)
{
if (string.IsNullOrEmpty(WorkingDirectory))
{
WorkingDirectory = Directory.GetCurrentDirectory();
}

var wasmCsprojs = GetWasmProjects();

if (wasmCsprojs.Length == 0)
{
await console.Output.WriteLineAsync("No Blazor WASM projects found. No files to bundle.");

return;
}

await console.Output.WriteLineAsync("Blazor WASM projects found:");
foreach (var csproj in wasmCsprojs)
{
await console.Output.WriteLineAsync($"- {csproj.FullName}");
}
}

public FileInfo[] GetWasmProjects(){
return Directory.EnumerateFiles(WorkingDirectory!, "*.csproj", SearchOption.AllDirectories)
.Where(IsCsprojBlazorWasm)
.Select(x => new FileInfo(x))
.ToArray();
}

static bool IsCsprojBlazorWasm(string file)
{
using var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read);
using var streamReader = new StreamReader(fileStream, Encoding.UTF8, true);

for (int i = 0; i < 4; i++)
{
var line = streamReader.ReadLine();

if (string.IsNullOrEmpty(line))
{
continue;
}

if (line.Contains("Sdk=\"Microsoft.NET.Sdk.BlazorWebAssembly\""))
{
return true;
}
}

return false;
}
}
1 change: 1 addition & 0 deletions src/AbpDevTools/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static CliApplicationBuilder BuildServices(this CliApplicationBuilder bui
typeof(EnvironmentCommand),
typeof(EnvironmentConfigurationCommand),
typeof(AbpBundleCommand),
typeof(AbpBundleListCommand),
typeof(TestCommand),
typeof(UpdateCheckCommand),
typeof(CleanCommand),
Expand Down
Loading