Skip to content

Commit

Permalink
Unique appnames according to path in computer
Browse files Browse the repository at this point in the history
  • Loading branch information
enisn committed Nov 14, 2023
1 parent a5c2849 commit 551aa6c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/AbpDevTools/AbpDevTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<PackageReference Include="CliFx" Version="2.3.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Spectre.Console" Version="0.46.1-preview.0.20" />
<PackageReference Include="Unidecode.NET" Version="2.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
25 changes: 21 additions & 4 deletions src/AbpDevTools/Environments/ProcessEnvironmentManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using AbpDevTools.Configuration;
using CliFx.Exceptions;
using System.Diagnostics;
using System.Text.RegularExpressions;
using Unidecode.NET;

namespace AbpDevTools.Environments;
public class ProcessEnvironmentManager : IProcessEnvironmentManager
Expand Down Expand Up @@ -58,13 +60,28 @@ private static string FindAppName(string directory)
{
var dir = directory ?? Directory.GetCurrentDirectory();

if (dir.Contains("."))
var folderName = new DirectoryInfo(dir).Name;
if (folderName.Contains("."))
{
var folderName = new DirectoryInfo(dir).Name;
var appName = folderName.Split('.').First();

return folderName.Split('.').First();
dir = dir.Replace(folderName, appName);
}

return dir;
var normalized = Regex.Replace(dir.Unidecode().ToLowerInvariant(), @"[^a-z0-9]", string.Empty);

var result = TruncateStart(normalized, 116);

return result;
}

private static string TruncateStart(string value, int maximumLength)
{
if (value.Length <= maximumLength)
{
return value;
}

return value.Substring(value.Length - maximumLength);
}
}

0 comments on commit 551aa6c

Please sign in to comment.