Skip to content

Commit

Permalink
style: reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmet-cetinkaya committed Jan 5, 2024
1 parent e6f434d commit 514b865
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ string[] codeLines

fileContent.InsertRange(
methodEndIndex,
collection: codeLines.Select(line => new string(' ', minimumSpaceCountInMethod) + line)
.Where(line => !fileContent.Contains(line))
collection: codeLines
.Select(line => new string(' ', minimumSpaceCountInMethod) + line)
.Where(line => !fileContent.Contains(line))
);
await System.IO.File.WriteAllLinesAsync(filePath, contents: fileContent.ToArray());
}
Expand Down
133 changes: 67 additions & 66 deletions src/corePackages/Core.CodeGen/File/DirectoryHelper.cs
Original file line number Diff line number Diff line change
@@ -1,67 +1,68 @@
using Core.CrossCuttingConcerns.Helpers;
using System.Reflection;

namespace Core.CodeGen.File;

public static class DirectoryHelper
{
public static string AssemblyDirectory
{
get
{
string codeBase = PlatformHelper.GetDirectoryHeader() + Assembly.GetExecutingAssembly().Location;
UriBuilder uri = new(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path)!;
}
}

public static ICollection<string> GetFilesInDirectoryTree(string root, string searchPattern)
{
List<string> files = new();

Stack<string> stack = new();
stack.Push(root);
while (stack.Count > 0)
{
string dir = stack.Pop();
files.AddRange(collection: Directory.GetFiles(dir, searchPattern));

foreach (string subDir in Directory.GetDirectories(dir))
stack.Push(subDir);
}

return files;
}

public static ICollection<string> GetDirsInDirectoryTree(string root, string searchPattern)
{
List<string> dirs = new();

Stack<string> stack = new();
stack.Push(root);
while (stack.Count > 0)
{
string dir = stack.Pop();
dirs.AddRange(collection: Directory.GetDirectories(dir, searchPattern));

foreach (string subDir in Directory.GetDirectories(dir))
stack.Push(subDir);
}

return dirs;
}

public static void DeleteDirectory(string path)
{
foreach (string subPath in Directory.EnumerateDirectories(path))
DeleteDirectory(subPath);

foreach (string filePath in Directory.EnumerateFiles(path))
{
FileInfo file = new(filePath) { Attributes = FileAttributes.Normal };
file.Delete();
}
Directory.Delete(path);
}
}
using System.Reflection;

namespace Core.CodeGen.File;

public static class DirectoryHelper
{
public static string AssemblyDirectory
{
get
{
string codeBase =
PlatformHelper.GetDirectoryHeader() + Assembly.GetExecutingAssembly().Location;
UriBuilder uri = new(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path)!;
}
}

public static ICollection<string> GetFilesInDirectoryTree(string root, string searchPattern)
{
List<string> files = new();

Stack<string> stack = new();
stack.Push(root);
while (stack.Count > 0)
{
string dir = stack.Pop();
files.AddRange(collection: Directory.GetFiles(dir, searchPattern));

foreach (string subDir in Directory.GetDirectories(dir))
stack.Push(subDir);
}

return files;
}

public static ICollection<string> GetDirsInDirectoryTree(string root, string searchPattern)
{
List<string> dirs = new();

Stack<string> stack = new();
stack.Push(root);
while (stack.Count > 0)
{
string dir = stack.Pop();
dirs.AddRange(collection: Directory.GetDirectories(dir, searchPattern));

foreach (string subDir in Directory.GetDirectories(dir))
stack.Push(subDir);
}

return dirs;
}

public static void DeleteDirectory(string path)
{
foreach (string subPath in Directory.EnumerateDirectories(path))
DeleteDirectory(subPath);

foreach (string filePath in Directory.EnumerateFiles(path))
{
FileInfo file = new(filePath) { Attributes = FileAttributes.Normal };
file.Delete();
}
Directory.Delete(path);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;

namespace Core.CrossCuttingConcerns.Helpers
{
public static class PlatformHelper
Expand Down Expand Up @@ -30,4 +31,3 @@ public static string GetDirectoryHeader()
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Core.CodeGen.Code.CSharp;
using Core.CodeGen.File;
using Core.CodeGen.TemplateEngine;
using Core.CrossCuttingConcerns.Helpers;
using Core.CrossCuttingConcerns.Helpers;
using Domain.Constants;
using Domain.ValueObjects;
using MediatR;
Expand Down Expand Up @@ -39,7 +39,15 @@ [EnumeratorCancellation] CancellationToken cancellationToken
)
{
await _businessRules.FileShouldNotBeExists(
PlatformHelper.SecuredPathJoin(request.ProjectPath, "Application", "features", request.FeatureName.ToPascalCase(), "Commands", request.CommandName, $"{request.CommandName}Command.cs")
PlatformHelper.SecuredPathJoin(
request.ProjectPath,
"Application",
"features",
request.FeatureName.ToPascalCase(),
"Commands",
request.CommandName,
$"{request.CommandName}Command.cs"
)
);

GeneratedCommandResponse response = new();
Expand Down Expand Up @@ -83,7 +91,12 @@ private async Task<ICollection<string>> generateApplicationCodes(
CommandTemplateData commandTemplateData
)
{
string templateDir = PlatformHelper.SecuredPathJoin(DirectoryHelper.AssemblyDirectory, Templates.Paths.Command, "Folders", "Application");
string templateDir = PlatformHelper.SecuredPathJoin(
DirectoryHelper.AssemblyDirectory,
Templates.Paths.Command,
"Folders",
"Application"
);
return await generateFolderCodes(
templateDir,
outputDir: PlatformHelper.SecuredPathJoin(projectPath, "Application"),
Expand All @@ -97,9 +110,21 @@ private async Task<ICollection<string>> injectOperationClaims(
CommandTemplateData commandTemplateData
)
{
string featureOperationClaimFilePath = PlatformHelper.SecuredPathJoin(projectPath, "Application", "Features", featureName, "Constants", $"{featureName}OperationClaims.cs");
string featureOperationClaimFilePath = PlatformHelper.SecuredPathJoin(
projectPath,
"Application",
"Features",
featureName,
"Constants",
$"{featureName}OperationClaims.cs"
);
string[] commandOperationClaimPropertyTemplateCodeLines = await File.ReadAllLinesAsync(
PlatformHelper.SecuredPathJoin(DirectoryHelper.AssemblyDirectory, Templates.Paths.Command, "Lines", "CommandOperationClaimProperty.cs.sbn")
PlatformHelper.SecuredPathJoin(
DirectoryHelper.AssemblyDirectory,
Templates.Paths.Command,
"Lines",
"CommandOperationClaimProperty.cs.sbn"
)
);
string[] commandOperationClaimPropertyCodeLines = await Task.WhenAll(
commandOperationClaimPropertyTemplateCodeLines.Select(
Expand All @@ -111,13 +136,23 @@ await CSharpCodeInjector.AddCodeLinesAsPropertyAsync(
commandOperationClaimPropertyCodeLines
);

string operationClaimsEntityConfigurationFilePath = PlatformHelper.SecuredPathJoin(projectPath, "Persistence", "EntityConfigurations", "OperationClaimConfiguration.cs");
string operationClaimsEntityConfigurationFilePath = PlatformHelper.SecuredPathJoin(
projectPath,
"Persistence",
"EntityConfigurations",
"OperationClaimConfiguration.cs"
);

if (!File.Exists(operationClaimsEntityConfigurationFilePath))
if (!File.Exists(operationClaimsEntityConfigurationFilePath))
return new[] { featureOperationClaimFilePath };

string[] commandOperationClaimSeedTemplateCodeLines = await File.ReadAllLinesAsync(
PlatformHelper.SecuredPathJoin(DirectoryHelper.AssemblyDirectory, Templates.Paths.Command, "Lines", "CommandOperationClaimSeed.cs.sbn")
PlatformHelper.SecuredPathJoin(
DirectoryHelper.AssemblyDirectory,
Templates.Paths.Command,
"Lines",
"CommandOperationClaimSeed.cs.sbn"
)
);
string[] commandOperationClaimSeedCodeLines = await Task.WhenAll(
commandOperationClaimSeedTemplateCodeLines.Select(
Expand Down Expand Up @@ -171,10 +206,20 @@ private async Task<ICollection<string>> injectWebApiEndpoint(
CommandTemplateData commandTemplateData
)
{
string controllerFilePath = PlatformHelper.SecuredPathJoin(projectPath, "WebAPI", "Controllers", $"{featureName}Controller.cs");
string controllerFilePath = PlatformHelper.SecuredPathJoin(
projectPath,
"WebAPI",
"Controllers",
$"{featureName}Controller.cs"
);

string[] controllerEndPointMethodTemplateCodeLines = await File.ReadAllLinesAsync(
PlatformHelper.SecuredPathJoin(DirectoryHelper.AssemblyDirectory, Templates.Paths.Command, "Lines", "ControllerEndPointMethod.cs.sbn")
PlatformHelper.SecuredPathJoin(
DirectoryHelper.AssemblyDirectory,
Templates.Paths.Command,
"Lines",
"ControllerEndPointMethod.cs.sbn"
)
);
string[] controllerEndPointMethodRenderedCodeLines = await Task.WhenAll(
controllerEndPointMethodTemplateCodeLines.Select(
Expand All @@ -189,7 +234,12 @@ await CSharpCodeInjector.AddMethodToClass(
);

string[] commandUsingNameSpaceTemplateCodeLines = await File.ReadAllLinesAsync(
PlatformHelper.SecuredPathJoin(DirectoryHelper.AssemblyDirectory, Templates.Paths.Command, "Lines", "CommandUsingNameSpaces.cs.sbn")
PlatformHelper.SecuredPathJoin(
DirectoryHelper.AssemblyDirectory,
Templates.Paths.Command,
"Lines",
"CommandUsingNameSpaces.cs.sbn"
)
);
string[] commandUsingNameSpaceRenderedCodeLines = await Task.WhenAll(
commandUsingNameSpaceTemplateCodeLines.Select(
Expand Down
Loading

0 comments on commit 514b865

Please sign in to comment.