Browse Source

Enhanced install-libs command.

Resolve #8528
pull/11540/head
maliming 5 years ago
parent
commit
c2730e1408
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 5
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs
  2. 17
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs
  3. 90
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/LIbs/InstallLibsService.cs
  4. 6
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppNoLayersTemplateBase.cs

5
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<NewCommand> 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.";
}
}
}

17
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";
}
}
}
}

90
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<string> ExcludeDirectory = new List<string>()
{
"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<string> 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<bool> 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());

6
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<ProjectBuildPipelineStep> GetCustomSteps(ProjectBuildContext context)
{
var steps = new List<ProjectBuildPipelineStep>();

Loading…
Cancel
Save