|
|
|
@ -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"); |
|
|
|
|