Clean up
This commit is contained in:
parent
5ccb40bb44
commit
91431fd996
@ -97,14 +97,14 @@ public class CrudRouterGenerator
|
|||||||
var entityRoutePrefix = fqn.PascalizedName.Kebaberize().Pluralize().ToLower();
|
var entityRoutePrefix = fqn.PascalizedName.Kebaberize().Pluralize().ToLower();
|
||||||
|
|
||||||
var serviceFilePath = Path.Join(
|
var serviceFilePath = Path.Join(
|
||||||
Features.Api.FeatureName, "services", fqn.FolderPath, $"{fqn.SnakeCasedName}_service"
|
Features.Api.FeatureName, "services", fqn.Namespace, $"{fqn.SnakeCasedName}_service"
|
||||||
);
|
);
|
||||||
|
|
||||||
var serviceImportPath = serviceFilePath.SlashesToDots();
|
var serviceImportPath = serviceFilePath.SlashesToDots();
|
||||||
var routerFolderPath = Path.Join(Features.Api.FeatureName, "routers", fqn.FolderPath);
|
var routerFolderPath = Path.Join(Features.Api.FeatureName, "routers", fqn.Namespace);
|
||||||
var routerFilePath = Path.Join(routerFolderPath, $"{fqn.SnakeCasedName}");
|
var routerFilePath = Path.Join(routerFolderPath, $"{fqn.SnakeCasedName}");
|
||||||
var routerImportPath = routerFolderPath.SlashesToDots();
|
var routerImportPath = routerFolderPath.SlashesToDots();
|
||||||
var requestsFolderPath = Path.Join(Features.Api.FeatureName, "requests", fqn.FolderPath);
|
var requestsFolderPath = Path.Join(Features.Api.FeatureName, "requests", fqn.Namespace);
|
||||||
|
|
||||||
var createRequestImportPath = Path.Join(requestsFolderPath, $"Create{fqn.PascalizedName}Request")
|
var createRequestImportPath = Path.Join(requestsFolderPath, $"Create{fqn.PascalizedName}Request")
|
||||||
.SlashesToDots()
|
.SlashesToDots()
|
||||||
|
@ -147,8 +147,8 @@ public partial class EntityLinker
|
|||||||
var fqn = new FullyQualifiedName(name);
|
var fqn = new FullyQualifiedName(name);
|
||||||
var path = $"{Features.Db.FeatureName}/entities";
|
var path = $"{Features.Db.FeatureName}/entities";
|
||||||
|
|
||||||
if (fqn.HasPath)
|
if (fqn.HasNamespace)
|
||||||
path = Path.Combine(path, fqn.FolderPath);
|
path = Path.Combine(path, fqn.Namespace);
|
||||||
|
|
||||||
path = Path.Combine(path, $"{fqn.SnakeCasedName}.py");
|
path = Path.Combine(path, $"{fqn.SnakeCasedName}.py");
|
||||||
var entity = new EntityModel(fqn.PascalizedName, path, await _context.ReadFile(path));
|
var entity = new EntityModel(fqn.PascalizedName, path, await _context.ReadFile(path));
|
||||||
|
@ -51,8 +51,7 @@ public class RequestClassGenerator
|
|||||||
var requestFilePath = Path.Join(
|
var requestFilePath = Path.Join(
|
||||||
Features.Api.FeatureName,
|
Features.Api.FeatureName,
|
||||||
"requests",
|
"requests",
|
||||||
fqn.FolderPath,
|
fqn.Namespace,
|
||||||
// requestsFolderPath,
|
|
||||||
$"{type.ToString().ToLower()}_{fqn.SnakeCasedName}_request.py"
|
$"{type.ToString().ToLower()}_{fqn.SnakeCasedName}_request.py"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -60,7 +59,6 @@ public class RequestClassGenerator
|
|||||||
.Replace("%imports%", GetImportString(entitySource, fieldInfo, type))
|
.Replace("%imports%", GetImportString(entitySource, fieldInfo, type))
|
||||||
.Replace("%request_type%", type.ToString().Pascalize())
|
.Replace("%request_type%", type.ToString().Pascalize())
|
||||||
.Replace("%entity_class_name%", fqn.PascalizedName)
|
.Replace("%entity_class_name%", fqn.PascalizedName)
|
||||||
// .Replace("%entity_class_name%", entityClassName)
|
|
||||||
.Replace("%fields%", fields)
|
.Replace("%fields%", fields)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -7,15 +7,21 @@ public class RequiresPluginAttribute : Attribute
|
|||||||
{
|
{
|
||||||
public void RequirePluginProject(string command)
|
public void RequirePluginProject(string command)
|
||||||
{
|
{
|
||||||
|
var currentDirectoryInfo = new DirectoryInfo(Environment.CurrentDirectory);
|
||||||
var matcher = new Matcher()
|
var matcher = new Matcher()
|
||||||
.AddInclude("*.csproj")
|
.AddInclude("*.csproj")
|
||||||
.Execute(new DirectoryInfoWrapper(new DirectoryInfo(Environment.CurrentDirectory)));
|
.Execute(new DirectoryInfoWrapper(currentDirectoryInfo));
|
||||||
|
|
||||||
if (!matcher.HasMatches)
|
if (!matcher.HasMatches)
|
||||||
throw new($"Command '{command}' must be run in a command plugin project.");
|
throw new($"Command '{command}' must be run in a command plugin project.");
|
||||||
|
|
||||||
var csprojFileName = $"{Path.GetDirectoryName(Environment.CurrentDirectory)}.csproj";
|
var csprojFileName = $"{new DirectoryInfo(Environment.CurrentDirectory).Name}.csproj";
|
||||||
bool IsCsprojFile(FilePatternMatch file) => Path.GetFileNameWithoutExtension(file.Path).Equals(csprojFileName);
|
|
||||||
|
bool IsCsprojFile(FilePatternMatch file)
|
||||||
|
{
|
||||||
|
return Path.GetFileName(file.Path) == csprojFileName;
|
||||||
|
}
|
||||||
|
|
||||||
var hasCsprojFile = matcher.Files.Any(IsCsprojFile);
|
var hasCsprojFile = matcher.Files.Any(IsCsprojFile);
|
||||||
|
|
||||||
if (!hasCsprojFile)
|
if (!hasCsprojFile)
|
||||||
|
@ -5,16 +5,16 @@ namespace MycroForge.CLI.Commands;
|
|||||||
|
|
||||||
public class FullyQualifiedName
|
public class FullyQualifiedName
|
||||||
{
|
{
|
||||||
public string FolderPath { get; }
|
public string Namespace { get; }
|
||||||
public string PascalizedName { get; }
|
public string PascalizedName { get; }
|
||||||
public string SnakeCasedName { get; }
|
public string SnakeCasedName { get; }
|
||||||
|
|
||||||
public string FilePath =>
|
public string FilePath =>
|
||||||
string.IsNullOrEmpty(FolderPath.Trim())
|
string.IsNullOrEmpty(Namespace.Trim())
|
||||||
? SnakeCasedName
|
? 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)
|
public FullyQualifiedName(string name)
|
||||||
@ -27,7 +27,7 @@ public class FullyQualifiedName
|
|||||||
name = fullName[1];
|
name = fullName[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
FolderPath = path;
|
Namespace = path;
|
||||||
PascalizedName = name.Pascalize();
|
PascalizedName = name.Pascalize();
|
||||||
SnakeCasedName = SnakeCase(name);
|
SnakeCasedName = SnakeCase(name);
|
||||||
}
|
}
|
||||||
|
@ -43,19 +43,17 @@ public partial class MycroForge
|
|||||||
private async Task ExecuteAsync(string name)
|
private async Task ExecuteAsync(string name)
|
||||||
{
|
{
|
||||||
var fqn = new FullyQualifiedName(name);
|
var fqn = new FullyQualifiedName(name);
|
||||||
var folderPath = $"{Features.Api.FeatureName}/routers";
|
var routersFolderPath = $"{Features.Api.FeatureName}/routers";
|
||||||
|
|
||||||
_context.AssertDirectoryExists(folderPath);
|
if (fqn.HasNamespace)
|
||||||
|
routersFolderPath = Path.Combine(routersFolderPath, fqn.Namespace);
|
||||||
if (fqn.HasPath)
|
|
||||||
folderPath = Path.Combine(folderPath, fqn.FolderPath);
|
|
||||||
|
|
||||||
var fileName = $"{fqn.SnakeCasedName}.py";
|
var fileName = $"{fqn.SnakeCasedName}.py";
|
||||||
var filePath = Path.Combine(folderPath, fileName);
|
var filePath = Path.Combine(routersFolderPath, fileName);
|
||||||
|
|
||||||
await _context.CreateFile(filePath, Template);
|
await _context.CreateFile(filePath, Template);
|
||||||
|
|
||||||
var moduleImportPath = folderPath
|
var moduleImportPath = routersFolderPath
|
||||||
.Replace('\\', '.')
|
.Replace('\\', '.')
|
||||||
.Replace('/', '.');
|
.Replace('/', '.');
|
||||||
|
|
||||||
|
@ -73,8 +73,8 @@ public partial class MycroForge
|
|||||||
|
|
||||||
_context.AssertDirectoryExists(Features.Db.FeatureName);
|
_context.AssertDirectoryExists(Features.Db.FeatureName);
|
||||||
|
|
||||||
if (fqn.HasPath)
|
if (fqn.HasNamespace)
|
||||||
folderPath = Path.Combine(folderPath, fqn.FolderPath);
|
folderPath = Path.Combine(folderPath, fqn.Namespace);
|
||||||
|
|
||||||
var _columns = GetColumnDefinitions(columns.ToArray());
|
var _columns = GetColumnDefinitions(columns.ToArray());
|
||||||
var typeImports = string.Join(", ", _columns.Select(c => c.OrmType.Split('(').First()).Distinct());
|
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)
|
private async Task ExecuteAsync(string name)
|
||||||
{
|
{
|
||||||
_context.AssertDirectoryExists($"{Features.Db.FeatureName}/versions");
|
|
||||||
|
|
||||||
await _context.Bash(
|
await _context.Bash(
|
||||||
"source .venv/bin/activate",
|
"source .venv/bin/activate",
|
||||||
$"alembic revision --autogenerate -m \"{name}\" --rev-id $(date -u +\"%Y%m%d%H%M%S\")"
|
$"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 fqn = new FullyQualifiedName(name);
|
||||||
var folderPath = string.Empty;
|
var folderPath = string.Empty;
|
||||||
|
|
||||||
if (fqn.HasPath)
|
if (fqn.HasNamespace)
|
||||||
folderPath = Path.Combine(folderPath, fqn.FolderPath);
|
folderPath = Path.Combine(folderPath, fqn.Namespace);
|
||||||
|
|
||||||
var filePath = Path.Combine(folderPath, $"{fqn.SnakeCasedName}.py");
|
var filePath = Path.Combine(folderPath, $"{fqn.SnakeCasedName}.py");
|
||||||
var template = withSession ? WithSessionTemplate : DefaultTemplate;
|
var template = withSession ? WithSessionTemplate : DefaultTemplate;
|
||||||
|
36
MycroForge.CLI/My.Plugin/HelloWorldCommand.cs
Normal file
36
MycroForge.CLI/My.Plugin/HelloWorldCommand.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System.CommandLine;
|
||||||
|
using MycroForge.Core;
|
||||||
|
using MycroForge.Core.Contract;
|
||||||
|
using RootCommand = MycroForge.Core.RootCommand;
|
||||||
|
|
||||||
|
namespace My.Plugin;
|
||||||
|
|
||||||
|
public class HelloWorldCommand : Command, ISubCommandOf<RootCommand>
|
||||||
|
{
|
||||||
|
private readonly Argument<string> NameArgument =
|
||||||
|
new(name: "name", description: "The name of the person to greet");
|
||||||
|
|
||||||
|
private readonly Option<bool> AllCapsOption =
|
||||||
|
new(aliases: ["-a", "--all-caps"], description: "Print the name in all caps");
|
||||||
|
|
||||||
|
private readonly ProjectContext _context;
|
||||||
|
|
||||||
|
public HelloWorldCommand(ProjectContext context) :
|
||||||
|
base("hello", "An example command generated by dotnet new using the m4gp template")
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
AddArgument(NameArgument);
|
||||||
|
AddOption(AllCapsOption);
|
||||||
|
this.SetHandler(ExecuteAsync, NameArgument, AllCapsOption);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ExecuteAsync(string name, bool allCaps)
|
||||||
|
{
|
||||||
|
name = allCaps ? name.ToUpper() : name;
|
||||||
|
|
||||||
|
await _context.CreateFile("hello_world.txt",
|
||||||
|
$"Hello {name}!",
|
||||||
|
"This file was generated by your custom command!"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
15
MycroForge.CLI/My.Plugin/HelloWorldCommandPlugin.cs
Normal file
15
MycroForge.CLI/My.Plugin/HelloWorldCommandPlugin.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using MycroForge.Core.Contract;
|
||||||
|
using RootCommand = MycroForge.Core.RootCommand;
|
||||||
|
|
||||||
|
namespace My.Plugin;
|
||||||
|
|
||||||
|
public class HelloWorldCommandPlugin : ICommandPlugin
|
||||||
|
{
|
||||||
|
public string Name => "My.Plugin";
|
||||||
|
|
||||||
|
public void RegisterServices(IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddScoped<ISubCommandOf<RootCommand>, HelloWorldCommand>();
|
||||||
|
}
|
||||||
|
}
|
17
MycroForge.CLI/My.Plugin/My.Plugin.csproj
Normal file
17
MycroForge.CLI/My.Plugin/My.Plugin.csproj
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include=".template.config\template.json" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MycroForge.Core" Version="1.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
Reference in New Issue
Block a user