Skip to content

Commit

Permalink
Merge pull request #15 from enisn/detect-migrator
Browse files Browse the repository at this point in the history
Better migrator detection
  • Loading branch information
enisn authored Aug 21, 2024
2 parents ef93bd4 + ad9fedc commit 9c1e712
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/AbpDevTools/Commands/MigrateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using CliFx.Infrastructure;
using Spectre.Console;
using System.Diagnostics;
using System.Text;

namespace AbpDevTools.Commands;

Expand Down Expand Up @@ -46,7 +47,7 @@ public async ValueTask ExecuteAsync(IConsole console)
}

var dbMigrators = Directory.EnumerateFiles(WorkingDirectory, "*.csproj", SearchOption.AllDirectories)
.Where(x => x.EndsWith("DbMigrator.csproj"))
.Where(IsDbMigrator)
.Select(x => new FileInfo(x))
.ToList();

Expand Down Expand Up @@ -102,6 +103,39 @@ public async ValueTask ExecuteAsync(IConsole console)
KillRunningProcesses();
}

private bool IsDbMigrator(string file)
{
if (!file.EndsWith("Migrator.csproj", StringComparison.InvariantCultureIgnoreCase))
{
return false;
}

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

while (!streamReader.EndOfStream)
{
var line = streamReader.ReadLine();

if (line == null)
{
continue;
}

if (line.Contains("<OutputType>Exe</OutputType>"))
{
return true;
}

if (line.Contains("</PropertyGroup>"))
{
break;
}
}

return false;
}

private async Task RenderStatusAsync()
{
var table = new Table().Border(TableBorder.Ascii);
Expand Down

0 comments on commit 9c1e712

Please sign in to comment.