diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/ChangeThemeStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/ChangeThemeStep.cs index f3b0fed914a..08aafba89a2 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/ChangeThemeStep.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/ChangeThemeStep.cs @@ -31,9 +31,9 @@ public override void Execute(ProjectBuildContext context) protected void ChangeToBasicTheme(ProjectBuildContext context) { var defaultThemeName = context.BuildArgs.TemplateName is AppTemplate.TemplateName or AppNoLayersTemplate.TemplateName - ? "LeptonXLite" + ? "LeptonXLite" : "LeptonX"; - + #region MVC Projects ChangeThemeToBasicForMvcProjects(context, defaultThemeName); @@ -41,14 +41,14 @@ protected void ChangeToBasicTheme(ProjectBuildContext context) #endregion #region MyCompanyName.MyProjectName.Blazor - + ReplacePackageReferenceWithProjectReference( context, "/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj", $"Volo.Abp.AspNetCore.Components.WebAssembly.{defaultThemeName}Theme", @"..\..\..\..\..\modules\basic-theme\src\Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme\Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme.csproj" ); - + ChangeNamespaceAndKeyword( context, "/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs", @@ -58,31 +58,40 @@ protected void ChangeToBasicTheme(ProjectBuildContext context) "AbpAspNetCoreComponentsWebAssemblyBasicThemeModule" ); + ChangeNamespaceAndKeyword( + context, + "/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs", + $"Volo.Abp.AspNetCore.Components.Web.{defaultThemeName}Theme.Themes.{defaultThemeName}", + "Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic", + $"AbpAspNetCoreComponentsWebAssembly{defaultThemeName}ThemeModule", + "AbpAspNetCoreComponentsWebAssemblyBasicThemeModule" + ); + ChangeNamespace( context, "/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs", $"Volo.Abp.AspNetCore.Components.Web.{defaultThemeName}Theme.Components", "Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic" ); - + #endregion #region Blazor.Server Projects ChangeThemeToBasicForBlazorProjects(context, defaultThemeName); - + #endregion #region Angular var angularPackageName = context.BuildArgs.TemplateName is AppTemplate.TemplateName or AppNoLayersTemplate.TemplateName - ? "@abp/ng.theme.lepton-x" + ? "@abp/ng.theme.lepton-x" : "@volosoft/abp.ng.theme.lepton-x"; - + ReplaceImportPackage( - context, + context, "/angular/src/app/app.module.ts", - angularPackageName, + angularPackageName, "@abp/ng.theme.basic" ); @@ -98,7 +107,7 @@ protected void ChangeToBasicTheme(ProjectBuildContext context) "ThemeLeptonXModule", "ThemeBasicModule" ); - + RemoveLinesByStatement( context, "/angular/angular.json", @@ -113,7 +122,7 @@ protected void ChangeToBasicTheme(ProjectBuildContext context) "HttpErrorComponent, ", "" ); - + ChangeModuleImportBetweenStatements( context, "/angular/src/app/app.module.ts", @@ -128,11 +137,11 @@ protected void ChangeToBasicTheme(ProjectBuildContext context) protected void ChangeToLeptonTheme(ProjectBuildContext context) { - #region Common - + #region Common + RenameLeptonXFolders(context, folderName: "Lepton"); AddLeptonThemeManagementReferenceToProjects(context); - + #endregion #region MVC Projects @@ -140,16 +149,16 @@ protected void ChangeToLeptonTheme(ProjectBuildContext context) ChangeThemeToLeptonForMvcProjects(context); #endregion - + #region MyCompanyName.MyProjectName.Blazor - + ReplacePackageReferenceWithProjectReference( context, "/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj", "Volo.Abp.AspNetCore.Components.WebAssembly.LeptonXTheme", @"..\..\..\..\..\lepton-theme\src\Volo.Abp.AspNetCore.Components.WebAssembly.LeptonTheme\Volo.Abp.AspNetCore.Components.WebAssembly.LeptonTheme.csproj" ); - + ChangeNamespaceAndKeyword( context, "/MyCompanyName.MyProjectName.Blazor/MyProjectNameBlazorModule.cs", @@ -168,7 +177,7 @@ protected void ChangeToLeptonTheme(ProjectBuildContext context) #endregion - #region MyCompanyName.MyProjectName.Blazor.Server && MyCompanyName.MyProjectName.Blazor.Server.Tiered + #region MyCompanyName.MyProjectName.Blazor.Server && MyCompanyName.MyProjectName.Blazor.Server.Tiered ChangeThemeToLeptonForBlazorServerProjects(context); @@ -177,9 +186,9 @@ protected void ChangeToLeptonTheme(ProjectBuildContext context) #region Angular ReplaceImportPackage( - context, + context, "/angular/src/app/app.module.ts", - "@volosoft/abp.ng.theme.lepton-x", + "@volosoft/abp.ng.theme.lepton-x", "@volo/abp.ng.theme.lepton" ); @@ -195,7 +204,7 @@ protected void ChangeToLeptonTheme(ProjectBuildContext context) "ThemeLeptonXModule", "ThemeLeptonModule" ); - + RemoveLinesByStatement( context, "/angular/angular.json", @@ -214,7 +223,7 @@ protected void ChangeToLeptonTheme(ProjectBuildContext context) #region MyCompanyName.MyProjectName.Blazor.Server && MyCompanyName.MyProjectName.Blazor.Server.Mongo - (app-nolayers) ChangeThemeToLeptonForNoLayersBlazorServerProjects(context); - + #endregion } @@ -233,7 +242,7 @@ private void ConfigureLeptonManagementPackagesForNoLayersMvc(ProjectBuildContext { continue; } - + AddProjectReference(file, $@"..\..\..\..\lepton-theme\src\Volo.Abp.LeptonTheme.Management.{projectName}\Volo.Abp.LeptonTheme.Management.{projectName}.csproj"); AddModuleDependency(moduleFile, projectName, $"LeptonThemeManagement{ConvertProjectNameToModuleName($"{projectName}")}Module"); } @@ -241,12 +250,12 @@ private void ConfigureLeptonManagementPackagesForNoLayersMvc(ProjectBuildContext private void ChangeThemeToLeptonForMvcProjects(ProjectBuildContext context) { - var projectNames = new[] + var projectNames = new[] { - ".Web", ".HttpApi.Host", ".AuthServer", + ".Web", ".HttpApi.Host", ".AuthServer", "" //for app-nolayers-mvc }; - + foreach (var projectName in projectNames) { var projectPath = $"/MyCompanyName.MyProjectName{projectName}/MyCompanyName.MyProjectName{projectName}.csproj"; @@ -255,20 +264,20 @@ private void ChangeThemeToLeptonForMvcProjects(ProjectBuildContext context) { continue; } - + var moduleFile = ConvertProjectFileToModuleFile(context, projectFile); if (moduleFile == null) { continue; } - + ReplacePackageReferenceWithProjectReference( context, projectFile.Name, "Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonX", @"..\..\..\..\..\lepton-theme\src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Lepton\Volo.Abp.AspNetCore.Mvc.UI.Theme.Lepton.csproj" ); - + ChangeNamespaceAndKeyword( context, moduleFile.Name, @@ -277,7 +286,7 @@ private void ChangeThemeToLeptonForMvcProjects(ProjectBuildContext context) "LeptonXThemeBundles.Styles.Global", "LeptonThemeBundles.Styles.Global" ); - + ChangeNamespaceAndKeyword( context, moduleFile.Name, @@ -286,7 +295,7 @@ private void ChangeThemeToLeptonForMvcProjects(ProjectBuildContext context) "AbpAspNetCoreMvcUiLeptonXThemeModule", "AbpAspNetCoreMvcUiLeptonThemeModule" ); - + RemoveLinesByStatement( context, moduleFile.Name, @@ -294,10 +303,10 @@ private void ChangeThemeToLeptonForMvcProjects(ProjectBuildContext context) ); } } - + private void AddLeptonThemeManagementReferenceToProjects(ProjectBuildContext context) { - var projects = new Dictionary + var projects = new Dictionary { {"Domain", "MyCompanyName.MyProjectName.Domain.csproj"}, {"Domain.Shared", "MyCompanyName.MyProjectName.Domain.Shared.csproj"}, @@ -306,9 +315,9 @@ private void AddLeptonThemeManagementReferenceToProjects(ProjectBuildContext con {"HttpApi", "MyCompanyName.MyProjectName.HttpApi.csproj"}, {"HttpApi.Client", "MyCompanyName.MyProjectName.HttpApi.Client.csproj"} }; - + AddUiProjectToProjects(projects, context); - + foreach (var project in projects) { AddLeptonThemeManagementReference(context, project); @@ -324,7 +333,7 @@ private void AddLeptonThemeManagementReferenceToProjects(ProjectBuildContext con {"HttpApi.Client", "MyCompanyName.MyProjectName.AdministrationService.HttpApi.Client.csproj"}, {"Web", "MyCompanyName.MyProjectName.AdministrationService.Web.csproj"} }; - + foreach (var microserviceServiceProject in microserviceServiceProjects) { AddLeptonThemeManagementReference(context, microserviceServiceProject); @@ -337,7 +346,7 @@ private void AddUiProjectToProjects(Dictionary projects, Project { return; } - + switch (context.BuildArgs.UiFramework) { case UiFramework.Mvc: @@ -352,8 +361,8 @@ private void AddUiProjectToProjects(Dictionary projects, Project break; } } - - private void AddLeptonThemeManagementReference(ProjectBuildContext context, KeyValuePair projectInfo) + + private void AddLeptonThemeManagementReference(ProjectBuildContext context, KeyValuePair projectInfo) { var reference = $@"..\..\..\..\..\lepton-theme\src\Volo.Abp.LeptonTheme.Management.{projectInfo.Key}\Volo.Abp.LeptonTheme.Management.{projectInfo.Key}.csproj"; var projectFile = context.Files.FirstOrDefault(f => !f.Name.Contains("Test") && f.Name.Contains(projectInfo.Value) && f.Name.Contains(".csproj")); @@ -367,7 +376,7 @@ private void AddLeptonThemeManagementReference(ProjectBuildContext context, KeyV { return; } - + AddProjectReference(projectFile, reference); AddModuleDependency(moduleFile, projectInfo.Key, $"LeptonThemeManagement{ConvertProjectNameToModuleName(projectInfo.Key)}Module", @@ -391,12 +400,12 @@ private void AddModuleDependency(FileEntry moduleFile, string projectName, strin lines[i - 2] = lines[i - 2] + "," + Environment.NewLine + $"\ttypeof({dependency})"; } } - + moduleFile.SetLines(lines); } - protected void ReplacePackageReferenceWithProjectReference( - ProjectBuildContext context, + protected void ReplacePackageReferenceWithProjectReference( + ProjectBuildContext context, string targetProjectFilePath, string packageReference, string projectReference) @@ -406,16 +415,16 @@ protected void ReplacePackageReferenceWithProjectReference( { return; } - + file.NormalizeLineEndings(); - + var lines = file.GetLines(); var lineIndex = lines.FindIndex(line => line.Contains("PackageReference") && line.Contains(packageReference)); if (lineIndex == -1) { return; } - + lines[lineIndex] = lines[lineIndex].Replace(lines[lineIndex], $"\t"); file.SetLines(lines); } @@ -498,13 +507,13 @@ protected void ReplaceImportPackage( { return; } - + lines[lineIndex] = lines[lineIndex].Replace(oldImportPackage, newImportPackage); file.SetLines(lines); } protected void RemoveLinesByStatement( - ProjectBuildContext context, + ProjectBuildContext context, string filePath, string statement) { @@ -515,7 +524,7 @@ protected void RemoveLinesByStatement( } file.NormalizeLineEndings(); - + var lines = file.GetLines(); for (var i = 0; i < lines.Length; i++) { @@ -529,7 +538,7 @@ protected void RemoveLinesByStatement( } private void ChangeModuleImportBetweenStatements( - ProjectBuildContext context, + ProjectBuildContext context, string filePath, string firstStatement, string lastStatement, @@ -542,7 +551,7 @@ private void ChangeModuleImportBetweenStatements( } file.NormalizeLineEndings(); - + var lines = file.GetLines(); var firstLineIndex = lines.FindIndex(line => line.Contains(firstStatement)); var lastLineIndex = lines.FindIndex(line => line.Contains(lastStatement)); @@ -551,7 +560,7 @@ private void ChangeModuleImportBetweenStatements( { return; } - + lines[firstLineIndex] = newStatement; for (var i = firstLineIndex + 1; i <= lastLineIndex; i++) @@ -564,7 +573,7 @@ private void ChangeModuleImportBetweenStatements( } protected void ReplaceMethodNames( - ProjectBuildContext context, + ProjectBuildContext context, string filePath, string oldMethodName, string newMethodName) @@ -576,7 +585,7 @@ protected void ReplaceMethodNames( } file.NormalizeLineEndings(); - + var lines = file.GetLines(); for (var i = 0; i < lines.Length; i++) { @@ -585,17 +594,17 @@ protected void ReplaceMethodNames( lines[i] = lines[i].Replace(oldMethodName, newMethodName); } } - + file.SetLines(lines); } - + private static void AddProjectReference(FileEntry file, string reference) { if (!file.Name.Contains(".csproj")) { return; } - + var doc = new XmlDocument() { PreserveWhitespace = true }; using (var stream = StreamHelper.GenerateStreamFromString(file.Content)) { @@ -647,19 +656,19 @@ private static void AddProjectReference(FileEntry file, string reference) file.SetContent(doc.OuterXml); } } - + private static FileEntry ConvertProjectFileToModuleFile(ProjectBuildContext context, FileEntry projectFile) { var splittedProjectFileName = projectFile.Name.RemovePostFix("/").Split("/"); - + splittedProjectFileName = splittedProjectFileName.Take(splittedProjectFileName.Length - 1).ToArray(); - + var fileName = splittedProjectFileName?.Last(); if (fileName == null) { return null; } - + fileName = fileName .Replace("MyCompanyName.", "") .Replace(".csproj", "Module") @@ -667,12 +676,12 @@ private static FileEntry ConvertProjectFileToModuleFile(ProjectBuildContext cont return context.Files.FirstOrDefault(f => f.Name.Contains(splittedProjectFileName.Last() + "/" + fileName) && f.Name.EndsWith("Module.cs")); } - + private static string ConvertProjectNameToModuleName(string moduleName) { return moduleName.Replace(".", ""); } - + private static void RenameLeptonXFolders(ProjectBuildContext context, string folderName) { var leptonXFiles = context.Files.Where(x => x.Name.Contains("LeptonX") && x.IsDirectory); @@ -700,7 +709,7 @@ private void ChangeThemeToBasicForMvcProjects(ProjectBuildContext context, strin $"Volo.Abp.AspNetCore.Mvc.UI.Theme.{defaultThemeName}", @"..\..\..\..\..\modules\basic-theme\src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic\Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.csproj" ); - + ChangeNamespaceAndKeyword( context, $"/MyCompanyName.MyProjectName{project.Key}/{project.Value}.cs", @@ -720,7 +729,7 @@ private void ChangeThemeToBasicForMvcProjects(ProjectBuildContext context, strin ); } } - + private void ChangeThemeToBasicForBlazorProjects(ProjectBuildContext context, string defaultThemeName) { var projects = new Dictionary @@ -964,4 +973,4 @@ private void ChangeThemeToLeptonForNoLayersBlazorServerProjects(ProjectBuildCont ); } } -} \ No newline at end of file +}