|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
@ -71,6 +72,7 @@ public class AngularSourceCodeAdder : ITransientDependency
|
|
|
|
|
{
|
|
|
|
|
await AddProjectToEnvironmentTsAsync(angularPath, moduleName);
|
|
|
|
|
await AddProjectToAppModuleTsAsync(angularPath, moduleName);
|
|
|
|
|
await AddProjectToAppRoutingTsAsync(angularPath, moduleName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task AddProjectsToAngularJsonAsync(string angularPath, List<string> projects)
|
|
|
|
@ -244,15 +246,15 @@ public class AngularSourceCodeAdder : ITransientDependency
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fileContent = File.ReadAllText(filePath);
|
|
|
|
|
|
|
|
|
|
fileContent = Regex.Replace(fileContent, @"apis\s*:\s*{",
|
|
|
|
|
"apis: {"+ Environment.NewLine +
|
|
|
|
|
" " + moduleName.Split(".").Last() + ": {"+ Environment.NewLine +
|
|
|
|
|
" rootNamespace: '" + moduleName + "',"+ Environment.NewLine +
|
|
|
|
|
fileContent = Regex.Replace(fileContent, @"apis\s*:\s*{",
|
|
|
|
|
"apis: {" + Environment.NewLine +
|
|
|
|
|
" " + moduleName.Split(".").Last() + ": {" + Environment.NewLine +
|
|
|
|
|
" rootNamespace: '" + moduleName + "'," + Environment.NewLine +
|
|
|
|
|
" },");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File.WriteAllText(filePath, fileContent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -264,23 +266,56 @@ public class AngularSourceCodeAdder : ITransientDependency
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fileContent = File.ReadAllText(filePath);
|
|
|
|
|
|
|
|
|
|
var moduleNameAsConfigPath = moduleName.ToKebabCase();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (moduleName.Contains("."))
|
|
|
|
|
{
|
|
|
|
|
var moduleNameSplited = moduleName.Split(".");
|
|
|
|
|
moduleNameAsConfigPath = moduleNameSplited.Take(moduleNameSplited.Length-1).JoinAsString(".").ToKebabCase() + "/" + moduleNameSplited.Last().ToKebabCase();
|
|
|
|
|
moduleNameAsConfigPath = moduleNameSplited.Take(moduleNameSplited.Length - 1).JoinAsString(".").ToKebabCase() + "/" + moduleNameSplited.Last().ToKebabCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fileContent = "import { "+moduleName.Split(".").Last()+"ConfigModule } from '@"+moduleNameAsConfigPath+"/config';" + Environment.NewLine + fileContent;
|
|
|
|
|
|
|
|
|
|
fileContent = Regex.Replace(fileContent, "imports\\s*:\\s*\\[",
|
|
|
|
|
"imports: ["+ Environment.NewLine +
|
|
|
|
|
fileContent = "import { " + moduleName.Split(".").Last() + "ConfigModule } from '@" + moduleNameAsConfigPath + "/config';" + Environment.NewLine + fileContent;
|
|
|
|
|
|
|
|
|
|
fileContent = Regex.Replace(fileContent, "imports\\s*:\\s*\\[",
|
|
|
|
|
"imports: [" + Environment.NewLine +
|
|
|
|
|
" " + moduleName.Split(".").Last() + "ConfigModule.forRoot(),");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File.WriteAllText(filePath, fileContent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task AddProjectToAppRoutingTsAsync(string angularPath, string moduleName)
|
|
|
|
|
{
|
|
|
|
|
string filePath = Path.Combine(angularPath, "src", "app", "app-routing.module.ts");
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(filePath))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string fileContent = File.ReadAllText(filePath);
|
|
|
|
|
string moduleNameAsConfigPath = moduleName.ToKebabCase();
|
|
|
|
|
string path = moduleName.ToKebabCase();
|
|
|
|
|
|
|
|
|
|
if (moduleName.Contains("."))
|
|
|
|
|
{
|
|
|
|
|
var moduleNameSplitted = moduleName.Split(".");
|
|
|
|
|
moduleNameAsConfigPath = moduleNameSplitted.Take(moduleNameSplitted.Length - 1).JoinAsString(".").ToKebabCase() + "/" + moduleNameSplitted.Last().ToKebabCase();
|
|
|
|
|
path = $"{moduleNameSplitted.Last().ToKebabCase()}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string pattern = "Routes\\s*=\\s*\\[";
|
|
|
|
|
string newContent = $@"Routes = [
|
|
|
|
|
{{
|
|
|
|
|
path: '{path}',
|
|
|
|
|
loadChildren: () => import('@{moduleNameAsConfigPath}')
|
|
|
|
|
.then(m => m.{(moduleName.Split(".").Length > 1 ? moduleName.Split(".")[1] : moduleName)}Module.forLazy())
|
|
|
|
|
}},
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
fileContent = Regex.Replace(fileContent, pattern, newContent);
|
|
|
|
|
File.WriteAllText(filePath, fileContent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -311,7 +346,7 @@ public class AngularSourceCodeAdder : ITransientDependency
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(vscodeFolder, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var projectsInFolder = Directory.GetDirectories(folder);
|
|
|
|
|
|
|
|
|
|
if (projectsInFolder.Length == 1 && Path.GetFileName(projectsInFolder[0]) == "projects")
|
|
|
|
@ -360,7 +395,7 @@ public class AngularSourceCodeAdder : ITransientDependency
|
|
|
|
|
|
|
|
|
|
return projects;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<string> GetProjectPackageNameAsync(string angularProjectsPath, string project)
|
|
|
|
|
{
|
|
|
|
|
var packageJsonPath = Path.Combine(angularProjectsPath, project, "package.json");
|
|
|
|
|