Clean up
This commit is contained in:
@@ -7,15 +7,21 @@ public class RequiresPluginAttribute : Attribute
|
||||
{
|
||||
public void RequirePluginProject(string command)
|
||||
{
|
||||
var currentDirectoryInfo = new DirectoryInfo(Environment.CurrentDirectory);
|
||||
var matcher = new Matcher()
|
||||
.AddInclude("*.csproj")
|
||||
.Execute(new DirectoryInfoWrapper(new DirectoryInfo(Environment.CurrentDirectory)));
|
||||
.Execute(new DirectoryInfoWrapper(currentDirectoryInfo));
|
||||
|
||||
if (!matcher.HasMatches)
|
||||
throw new($"Command '{command}' must be run in a command plugin project.");
|
||||
|
||||
var csprojFileName = $"{Path.GetDirectoryName(Environment.CurrentDirectory)}.csproj";
|
||||
bool IsCsprojFile(FilePatternMatch file) => Path.GetFileNameWithoutExtension(file.Path).Equals(csprojFileName);
|
||||
var csprojFileName = $"{new DirectoryInfo(Environment.CurrentDirectory).Name}.csproj";
|
||||
|
||||
bool IsCsprojFile(FilePatternMatch file)
|
||||
{
|
||||
return Path.GetFileName(file.Path) == csprojFileName;
|
||||
}
|
||||
|
||||
var hasCsprojFile = matcher.Files.Any(IsCsprojFile);
|
||||
|
||||
if (!hasCsprojFile)
|
||||
|
||||
@@ -5,16 +5,16 @@ namespace MycroForge.CLI.Commands;
|
||||
|
||||
public class FullyQualifiedName
|
||||
{
|
||||
public string FolderPath { get; }
|
||||
public string Namespace { get; }
|
||||
public string PascalizedName { get; }
|
||||
public string SnakeCasedName { get; }
|
||||
|
||||
public string FilePath =>
|
||||
string.IsNullOrEmpty(FolderPath.Trim())
|
||||
string.IsNullOrEmpty(Namespace.Trim())
|
||||
? SnakeCasedName
|
||||
: Path.Join(FolderPath, SnakeCasedName);
|
||||
: Path.Join(Namespace, SnakeCasedName);
|
||||
|
||||
public bool HasPath => FolderPath.Length > 0;
|
||||
public bool HasNamespace => Namespace.Length > 0;
|
||||
|
||||
|
||||
public FullyQualifiedName(string name)
|
||||
@@ -27,7 +27,7 @@ public class FullyQualifiedName
|
||||
name = fullName[1];
|
||||
}
|
||||
|
||||
FolderPath = path;
|
||||
Namespace = path;
|
||||
PascalizedName = name.Pascalize();
|
||||
SnakeCasedName = SnakeCase(name);
|
||||
}
|
||||
|
||||
@@ -43,19 +43,17 @@ public partial class MycroForge
|
||||
private async Task ExecuteAsync(string name)
|
||||
{
|
||||
var fqn = new FullyQualifiedName(name);
|
||||
var folderPath = $"{Features.Api.FeatureName}/routers";
|
||||
var routersFolderPath = $"{Features.Api.FeatureName}/routers";
|
||||
|
||||
_context.AssertDirectoryExists(folderPath);
|
||||
|
||||
if (fqn.HasPath)
|
||||
folderPath = Path.Combine(folderPath, fqn.FolderPath);
|
||||
if (fqn.HasNamespace)
|
||||
routersFolderPath = Path.Combine(routersFolderPath, fqn.Namespace);
|
||||
|
||||
var fileName = $"{fqn.SnakeCasedName}.py";
|
||||
var filePath = Path.Combine(folderPath, fileName);
|
||||
var filePath = Path.Combine(routersFolderPath, fileName);
|
||||
|
||||
await _context.CreateFile(filePath, Template);
|
||||
|
||||
var moduleImportPath = folderPath
|
||||
var moduleImportPath = routersFolderPath
|
||||
.Replace('\\', '.')
|
||||
.Replace('/', '.');
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ public partial class MycroForge
|
||||
|
||||
_context.AssertDirectoryExists(Features.Db.FeatureName);
|
||||
|
||||
if (fqn.HasPath)
|
||||
folderPath = Path.Combine(folderPath, fqn.FolderPath);
|
||||
if (fqn.HasNamespace)
|
||||
folderPath = Path.Combine(folderPath, fqn.Namespace);
|
||||
|
||||
var _columns = GetColumnDefinitions(columns.ToArray());
|
||||
var typeImports = string.Join(", ", _columns.Select(c => c.OrmType.Split('(').First()).Distinct());
|
||||
|
||||
@@ -27,8 +27,6 @@ public partial class MycroForge
|
||||
|
||||
private async Task ExecuteAsync(string name)
|
||||
{
|
||||
_context.AssertDirectoryExists($"{Features.Db.FeatureName}/versions");
|
||||
|
||||
await _context.Bash(
|
||||
"source .venv/bin/activate",
|
||||
$"alembic revision --autogenerate -m \"{name}\" --rev-id $(date -u +\"%Y%m%d%H%M%S\")"
|
||||
|
||||
@@ -58,8 +58,8 @@ public partial class MycroForge
|
||||
var fqn = new FullyQualifiedName(name);
|
||||
var folderPath = string.Empty;
|
||||
|
||||
if (fqn.HasPath)
|
||||
folderPath = Path.Combine(folderPath, fqn.FolderPath);
|
||||
if (fqn.HasNamespace)
|
||||
folderPath = Path.Combine(folderPath, fqn.Namespace);
|
||||
|
||||
var filePath = Path.Combine(folderPath, $"{fqn.SnakeCasedName}.py");
|
||||
var template = withSession ? WithSessionTemplate : DefaultTemplate;
|
||||
|
||||
Reference in New Issue
Block a user