diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs index 2a8542d640..43437c9523 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs @@ -20,7 +20,7 @@ namespace Volo.Abp.Cli.Commands; public class NewCommand : ProjectCreationCommandBase, IConsoleCommand, ITransientDependency { public const string Name = "new"; - + public ILogger Logger { get; set; } protected TemplateProjectBuilder TemplateProjectBuilder { get; } @@ -79,6 +79,7 @@ public class NewCommand : ProjectCreationCommandBase, IConsoleCommand, ITransien Logger.LogInformation($"'{projectName}' has been successfully created to '{projectArgs.OutputFolder}'"); RunGraphBuildForMicroserviceServiceTemplate(projectArgs); + RunInstallLibsForAppTemplate(projectArgs); OpenRelatedWebPage(projectArgs, template, isTiered, commandLineArgs); } @@ -139,4 +140,4 @@ public class NewCommand : ProjectCreationCommandBase, IConsoleCommand, ITransien return "Generate a new solution based on the ABP startup templates."; } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs index 84a575a024..d309536fe0 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs @@ -284,7 +284,7 @@ public abstract class ProjectCreationCommandBase { return DatabaseProvider.NotSpecified; } - + if (optionValue.Equals("ef", StringComparison.InvariantCultureIgnoreCase) || optionValue.Equals("entityframeworkcore", StringComparison.InvariantCultureIgnoreCase)) { return DatabaseProvider.EntityFrameworkCore; @@ -305,7 +305,16 @@ public abstract class ProjectCreationCommandBase CmdHelper.RunCmd("dotnet build /graphbuild", projectArgs.OutputFolder); } } - + + protected virtual void RunInstallLibsForAppTemplate(ProjectBuildArgs projectArgs) + { + if (AppTemplateBase.IsAppTemplate(projectArgs.TemplateName) || + AppNoLayersTemplateBase.IsAppNoLayersTemplate(projectArgs.TemplateName)) + { + CmdHelper.RunCmd("abp install-libs", projectArgs.OutputFolder); + } + } + protected virtual DatabaseManagementSystem GetDatabaseManagementSystem(CommandLineArgs commandLineArgs) { var optionValue = commandLineArgs.Options.GetOrNull(Options.DatabaseManagementSystem.Short, Options.DatabaseManagementSystem.Long); @@ -358,7 +367,7 @@ public abstract class ProjectCreationCommandBase } var optionValue = commandLineArgs.Options.GetOrNull(Options.UiFramework.Short, Options.UiFramework.Long); - + switch (optionValue) { case null: @@ -465,4 +474,4 @@ public abstract class ProjectCreationCommandBase public const string Long = "preview"; } } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/LIbs/InstallLibsService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/LIbs/InstallLibsService.cs index 663cfc2f3c..cd01f895ae 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/LIbs/InstallLibsService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/LIbs/InstallLibsService.cs @@ -16,6 +16,15 @@ namespace Volo.Abp.Cli.LIbs; public class InstallLibsService : IInstallLibsService, ITransientDependency { + private readonly static List ExcludeDirectory = new List() + { + "node_modules", + ".git", + ".idea", + Path.Combine("bin", "debug"), + Path.Combine("obj", "debug") + }; + public ICmdHelper CmdHelper { get; } public const string LibsDirectory = "./wwwroot/libs"; @@ -32,17 +41,10 @@ public class InstallLibsService : IInstallLibsService, ITransientDependency public async Task InstallLibsAsync(string directory) { - var projectFiles = Directory.GetFiles(directory, "*.csproj"); - if (!projectFiles.Any()) + var projectPaths = FindAllProjects(directory); + if (!projectPaths.Any()) { - Logger.LogError("No project file found in the directory."); - return; - } - - if (!await CanInstallLibs(directory)) - { - Logger.LogWarning( - "abp install-libs command is available for MVC, Razor Page, and Blazor-Server UI types"); + Logger.LogError("No project found in the directory."); return; } @@ -52,16 +54,62 @@ public class InstallLibsService : IInstallLibsService, ITransientDependency return; } - if (IsYarnAvailable()) + foreach (var projectPath in projectPaths) { - RunYarn(directory); + Logger.LogInformation($"Found {projectPath}"); } - else + + foreach (var projectPath in projectPaths) { - RunNpmInstall(directory); + var projectDirectory = Path.GetDirectoryName(projectPath); + + // angular + if (projectPath.EndsWith("angular.json")) + { + if (IsYarnAvailable()) + { + RunYarn(projectDirectory); + } + else + { + RunNpmInstall(projectDirectory); + } + } + + // MVC or BLAZOR SERVER + if (projectPath.EndsWith("csproj")) + { + if (IsYarnAvailable()) + { + RunYarn(projectDirectory); + } + else + { + RunNpmInstall(projectDirectory); + } + + await CleanAndCopyResources(projectDirectory); + } } + } - await CleanAndCopyResources(directory); + private List FindAllProjects(string directory) + { + return Directory.GetFiles(directory, "*.csproj", SearchOption.AllDirectories) + .Union(Directory.GetFiles(directory, "angular.json", SearchOption.AllDirectories)) + .Where(file => ExcludeDirectory.All(x => file.IndexOf(x, StringComparison.OrdinalIgnoreCase) == -1)) + .Where(file => + { + if (file.EndsWith("csproj")) + { + using (var reader = File.OpenText(file)) + { + return reader.ReadToEnd().Contains("Microsoft.NET.Sdk.Web"); + } + } + return true; + }) + .ToList(); } private async Task CleanAndCopyResources(string fileDirectory) @@ -129,18 +177,6 @@ public class InstallLibsService : IInstallLibsService, ITransientDependency } } - private async Task CanInstallLibs(string fileDirectory) - { - var projectFiles = Directory.GetFiles(fileDirectory, "*.csproj"); - - using (var reader = File.OpenText(projectFiles[0])) - { - var projectFileContent = await reader.ReadToEndAsync(); - - return projectFileContent.Contains("Microsoft.NET.Sdk.Web"); - } - } - private void CleanDirsAndFiles(string directory, ResourceMapping resourceMapping) { var files = FindFiles(directory, resourceMapping.Clean.ToArray()); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppNoLayersTemplateBase.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppNoLayersTemplateBase.cs index b9714d9408..e1279a775b 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppNoLayersTemplateBase.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppNoLayersTemplateBase.cs @@ -12,6 +12,12 @@ public abstract class AppNoLayersTemplateBase : AppTemplateBase } + public static bool IsAppNoLayersTemplate(string templateName) + { + return templateName == AppNoLayersTemplate.TemplateName || + templateName == AppNoLayersProTemplate.TemplateName; + } + public override IEnumerable GetCustomSteps(ProjectBuildContext context) { var steps = new List();