diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/AngularSourceCodeAdder.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/AngularSourceCodeAdder.cs index 84e995f1fd..48413da847 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/AngularSourceCodeAdder.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/AngularSourceCodeAdder.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -66,6 +67,12 @@ public class AngularSourceCodeAdder : ITransientDependency } } + public async Task AddModuleConfigurationAsync(string angularPath, string moduleName) + { + await AddProjectToEnvironmentTsAsync(angularPath, moduleName); + await AddProjectToAppModuleTsAsync(angularPath, moduleName); + } + private async Task AddProjectsToAngularJsonAsync(string angularPath, List projects) { var angularJsonFilePath = Path.Combine(angularPath, "angular.json"); @@ -229,6 +236,46 @@ public class AngularSourceCodeAdder : ITransientDependency File.WriteAllText(tsConfigPath, tsConfigAsJson.ToString(Formatting.Indented)); } + private async Task AddProjectToEnvironmentTsAsync(string angularPath, string moduleName) + { + var filePath = Path.Combine(angularPath, "src", "environments", "environment.ts"); + + if (!File.Exists(filePath)) + { + 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 + + " },"); + + File.WriteAllText(filePath, fileContent); + } + + private async Task AddProjectToAppModuleTsAsync(string angularPath, string moduleName) + { + var filePath = Path.Combine(angularPath, "src", "app", "app.module.ts"); + + if (!File.Exists(filePath)) + { + return; + } + + var fileContent = File.ReadAllText(filePath); + + fileContent = "import { "+moduleName.Split(".").Last()+"Module } from '@"+moduleName.Split(".").Last().ToKebabCase()+"/config';" + Environment.NewLine + fileContent; + + fileContent = Regex.Replace(fileContent, "imports\\s*:\\s*\\[", + "imports: ["+ Environment.NewLine + + " " + moduleName.Split(".").Last() + "Module.forRoot(),"); + + File.WriteAllText(filePath, fileContent); + } + private async Task> CopyAndGetNamesOfAngularProjectsAsync(string solutionFilePath, string angularProjectsPath) { @@ -305,7 +352,7 @@ public class AngularSourceCodeAdder : ITransientDependency return projects; } - + private async Task GetProjectPackageNameAsync(string angularProjectsPath, string project) { var packageJsonPath = Path.Combine(angularProjectsPath, project, "package.json"); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/SolutionModuleAdder.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/SolutionModuleAdder.cs index 7f2831351a..f36ea2abdc 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/SolutionModuleAdder.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/SolutionModuleAdder.cs @@ -428,6 +428,11 @@ public class SolutionModuleAdder : ITransientDependency await PublishEventAsync(9, $"Adding angular source code"); await AngularSourceCodeAdder.AddFromModuleAsync(solutionFilePath, angularPath); + + if (newTemplate) + { + await AngularSourceCodeAdder.AddModuleConfigurationAsync(angularPath, moduleName); + } } private static void DeleteAngularDirectoriesInModulesFolder(string modulesFolderInSolution)