Browse Source

Merge pull request #14955 from abpframework/issues/14949

Cli: add missing steps when angular module added to app template
pull/14964/head
Alper Ebiçoğlu 3 years ago
committed by GitHub
parent
commit
8a96982886
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 49
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/AngularSourceCodeAdder.cs
  2. 5
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/SolutionModuleAdder.cs

49
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<string> 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<List<string>> CopyAndGetNamesOfAngularProjectsAsync(string solutionFilePath,
string angularProjectsPath)
{
@ -305,7 +352,7 @@ public class AngularSourceCodeAdder : ITransientDependency
return projects;
}
private async Task<string> GetProjectPackageNameAsync(string angularProjectsPath, string project)
{
var packageJsonPath = Path.Combine(angularProjectsPath, project, "package.json");

5
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)

Loading…
Cancel
Save