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 ce106626bf..a8c9994340 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 @@ -111,7 +111,7 @@ public class NewCommand : ProjectCreationCommandBase, IConsoleCommand, ITransien await RunGraphBuildForMicroserviceServiceTemplate(projectArgs); await CreateInitialMigrationsAsync(projectArgs); - await ConfigureAngularLibraryAfterMicroserviceServiceCreatedAsync(projectArgs, template); + await ConfigureAngularAfterMicroserviceServiceCreatedAsync(projectArgs, template); var skipInstallLibs = commandLineArgs.Options.ContainsKey(Options.SkipInstallingLibs.Long) || commandLineArgs.Options.ContainsKey(Options.SkipInstallingLibs.Short); if (!skipInstallLibs) 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 15556c8394..cd4c80ac23 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 @@ -1,13 +1,12 @@ using System; using System.IO; +using System.Text; using System.Linq; using System.Threading.Tasks; using ICSharpCode.SharpZipLib.Core; using ICSharpCode.SharpZipLib.Zip; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -using NuGet.Versioning; -using NUglify.Helpers; using Volo.Abp.Cli.ProjectModification; using Volo.Abp.Cli.Args; using Volo.Abp.Cli.Bundling; @@ -749,7 +748,7 @@ public abstract class ProjectCreationCommandBase } } - protected virtual async Task ConfigureAngularLibraryAfterMicroserviceServiceCreatedAsync(ProjectBuildArgs projectArgs, string template) + protected virtual async Task ConfigureAngularAfterMicroserviceServiceCreatedAsync(ProjectBuildArgs projectArgs, string template) { if (!MicroserviceServiceTemplateBase.IsMicroserviceServiceTemplate(projectArgs.TemplateName)) { @@ -767,33 +766,39 @@ public abstract class ProjectCreationCommandBase Logger.LogInformation("Setting up the angular library..."); var libraryName = projectArgs.SolutionName.ProjectName.ToKebabCase(); - var angularAppPath = Path.Combine(rootPath, "apps", "angular"); - var angularLibraryPath = Path.Combine(angularAppPath, "projects", libraryName); - await GenerateAngularLibraryForNewMicroserviceAsync(libraryName, angularAppPath); + var result = await CreateAngularLibraryAsync(libraryName, angularAppPath); + + Logger.LogInformation(result); + } - try + protected virtual async Task CreateAngularLibraryAsync( + string libraryName, + string workingDirectory, + bool isSecondaryEndpoint = false, + bool isModuleTemplate = true, + bool isOverride = true) + { + //TODO: Can we improve this validations ? + if (string.IsNullOrWhiteSpace(libraryName)) { - Directory.Delete(angularLibraryPath, true); - await MoveLibraryToHostAppAsync(projectArgs.OutputFolder, libraryName, angularLibraryPath); + throw new CliUsageException("Angular library name can not be empty"); } - catch (Exception e) + + if (string.IsNullOrWhiteSpace(workingDirectory)) { - Logger.LogError(e.Message); + throw new CliUsageException("Angular project path can not be empty"); } - } - protected virtual async Task GenerateAngularLibraryForNewMicroserviceAsync(string libraryName, string workingDirectory) - { - var result = CmdHelper.RunCmdAndGetOutput($"npx ng g library {libraryName}", workingDirectory); - return await Task.FromResult(result); - } + var commandBuilder = new StringBuilder($"npx ng g @abp/ng.schematics:create-lib --package-name {libraryName}"); - protected virtual async Task MoveLibraryToHostAppAsync(string outputFolder, string libraryName, string angularLibraryPath) - { - var currentAngularLibPath = Path.Combine(outputFolder, "angular", libraryName); - Directory.Move(currentAngularLibPath, angularLibraryPath); + commandBuilder.Append($" --is-secondary-entrypoint {(isSecondaryEndpoint ? "true" : "false")} "); + commandBuilder.Append($" --is-module-template {(isModuleTemplate ? "true" : "false")} "); + commandBuilder.Append($" --override {(isOverride ? "true" : "false")} "); + + var result = CmdHelper.RunCmdAndGetOutput(commandBuilder.ToString(), workingDirectory); + return await Task.FromResult(result); } public static class Options