Browse Source

Merge pull request #16657 from abpframework/ClearDownloadCacheCommand

Add `ClearDownloadCacheCommand`.
pull/16676/head
liangshiwei 3 years ago
committed by GitHub
parent
commit
d39b2a5bdb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      docs/en/CLI.md
  2. 2
      docs/zh-Hans/CLI.md
  3. 3
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs
  4. 59
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ClearDownloadCacheCommand.cs
  5. 37
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs
  6. 38
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs
  7. 12
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/AbpIoSourceCodeStore.cs
  8. 3
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ISourceCodeStore.cs
  9. 6
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ProjectBuildArgs.cs

2
docs/en/CLI.md

@ -48,6 +48,7 @@ Here, is the list of all available commands before explaining their details:
* **`logout`**: Logouts from your computer if you've authenticated before.
* **`bundle`**: Generates script and style references for ABP Blazor and MAUI Blazor project.
* **`install-libs`**: Install NPM Packages for MVC / Razor Pages and Blazor Server UI types.
* **`clear-download-cache`** Clears the templates download cache.
### help
@ -165,6 +166,7 @@ For more samples, go to [ABP CLI Create Solution Samples](CLI-New-Command-Sample
* `--local-framework-ref --abp-path`: Uses local projects references to the ABP framework instead of using the NuGet packages. This can be useful if you download the ABP Framework source code and have a local reference to the framework from your application.
* `--no-random-port`: Uses template's default ports.
* `--skip-installing-libs` or `-sib`: Skip installing client side packages.
* `--skip-cache` or `-sc`: Always download the latest from our server and refresh their templates folder cache.
* `--with-public-website`: **Public Website** is a front-facing website for describing your project, listing your products and doing SEO for marketing purposes. Users can login and register on your website with this website.
See some [examples for the new command](CLI-New-Command-Samples.md) here.

2
docs/zh-Hans/CLI.md

@ -44,6 +44,7 @@ dotnet tool update -g Volo.Abp.Cli
* **`logout`**: 在你的计算机注销认证.
* **`bundle`**: 为 ABP Blazor 和 MAUI Blazor 项目生成引用的脚本和样式.
* **`install-libs`**: 为 MVC / Razor Pages 和 Blazor Server UI 类型安装NPM包.
* **`clear-download-cache`** 删除下载的模版缓存.
### help
@ -142,6 +143,7 @@ abp new Acme.BookStore
* `--create-solution-folder` 或者 `-csf`: 指定项目是在输出文件夹中的新文件夹中还是直接在输出文件夹中.
* `--connection-string` 或者 `-cs`: 重写所有 `appsettings.json` 文件的默认连接字符串. 默认连接字符串是 `Server=localhost;Database=MyProjectName;Trusted_Connection=True`. 默认的数据库提供程序是 `SQL Server`. 如果你使用EF Core但需要更改DBMS,可以按[这里所述](Entity-Framework-Core-Other-DBMS.md)进行更改(创建解决方案之后).
* `--local-framework-ref --abp-path`: 使用对项目的本地引用,而不是替换为NuGet包引用.
* `--skip-cache` or `-sc`: 从服务器下载最新的模版并更新本地模版缓存.
### update

3
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/AbpCliCoreModule.cs

@ -64,7 +64,8 @@ public class AbpCliCoreModule : AbpModule
options.Commands[InstallLibsCommand.Name] = typeof(InstallLibsCommand);
options.Commands[CleanCommand.Name] = typeof(CleanCommand);
options.Commands[CliCommand.Name] = typeof(CliCommand);
options.Commands[ClearDownloadCacheCommand.Name] = typeof(ClearDownloadCacheCommand);
options.DisabledModulesToAddToSolution.Add("Volo.Abp.LeptonXTheme.Pro");
options.DisabledModulesToAddToSolution.Add("Volo.Abp.LeptonXTheme.Lite");
});

59
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ClearDownloadCacheCommand.cs

@ -0,0 +1,59 @@
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Cli.Args;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Cli.Commands;
public class ClearDownloadCacheCommand : IConsoleCommand, ITransientDependency
{
public const string Name = "clear-download-cache";
public ILogger<ClearDownloadCacheCommand> Logger { get; set; }
public ClearDownloadCacheCommand()
{
Logger = NullLogger<ClearDownloadCacheCommand>.Instance;
}
public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
{
Logger.LogInformation("Clearing the templates download cache...");
foreach (var cacheFile in Directory.GetFiles(CliPaths.TemplateCache, "*.zip"))
{
Logger.LogInformation($"Deleting {cacheFile}");
try
{
File.Delete(cacheFile);
}
catch (Exception e)
{
Logger.LogError(e, $"Could not delete {cacheFile}");
}
}
Logger.LogInformation("Done.");
await Task.CompletedTask;
}
public string GetUsageInfo()
{
var sb = new StringBuilder();
sb.AppendLine("");
sb.AppendLine("Usage:");
sb.AppendLine(" abp clear-download-cache");
sb.AppendLine("");
sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI");
return sb.ToString();
}
public string GetShortDescription()
{
return "Clears the templates download cache.";
}
}

37
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs

@ -24,40 +24,40 @@ namespace Volo.Abp.Cli.Commands;
public class NewCommand : ProjectCreationCommandBase, IConsoleCommand, ITransientDependency
{
public const string Name = "new";
protected TemplateProjectBuilder TemplateProjectBuilder { get; }
public ITemplateInfoProvider TemplateInfoProvider { get; }
public NewCommand(
ConnectionStringProvider connectionStringProvider,
ConnectionStringProvider connectionStringProvider,
SolutionPackageVersionFinder solutionPackageVersionFinder,
ICmdHelper cmdHelper,
IInstallLibsService installLibsService,
IInstallLibsService installLibsService,
CliService cliService,
AngularPwaSupportAdder angularPwaSupportAdder,
AngularPwaSupportAdder angularPwaSupportAdder,
InitialMigrationCreator initialMigrationCreator,
ThemePackageAdder themePackageAdder,
ILocalEventBus eventBus,
ThemePackageAdder themePackageAdder,
ILocalEventBus eventBus,
IBundlingService bundlingService,
ITemplateInfoProvider templateInfoProvider,
ITemplateInfoProvider templateInfoProvider,
TemplateProjectBuilder templateProjectBuilder,
AngularThemeConfigurer angularThemeConfigurer) :
base(connectionStringProvider,
solutionPackageVersionFinder,
cmdHelper,
installLibsService,
cliService,
solutionPackageVersionFinder,
cmdHelper,
installLibsService,
cliService,
angularPwaSupportAdder,
initialMigrationCreator,
themePackageAdder,
eventBus,
themePackageAdder,
eventBus,
bundlingService,
angularThemeConfigurer)
{
TemplateInfoProvider = templateInfoProvider;
TemplateProjectBuilder = templateProjectBuilder;
}
public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
{
var projectName = NamespaceHelper.NormalizeNamespace(commandLineArgs.Target);
@ -100,20 +100,20 @@ public class NewCommand : ProjectCreationCommandBase, IConsoleCommand, ITransien
ConfigureNpmPackagesForTheme(projectArgs);
await RunGraphBuildForMicroserviceServiceTemplate(projectArgs);
await CreateInitialMigrationsAsync(projectArgs);
var skipInstallLibs = commandLineArgs.Options.ContainsKey(Options.SkipInstallingLibs.Long) || commandLineArgs.Options.ContainsKey(Options.SkipInstallingLibs.Short);
if (!skipInstallLibs)
{
await RunInstallLibsForWebTemplateAsync(projectArgs);
ConfigureAngularJsonForThemeSelection(projectArgs);
}
var skipBundling = commandLineArgs.Options.ContainsKey(Options.SkipBundling.Long) || commandLineArgs.Options.ContainsKey(Options.SkipBundling.Short);
if (!skipBundling)
{
await RunBundleForBlazorWasmOrMauiBlazorTemplateAsync(projectArgs);
}
await ConfigurePwaSupportForAngular(projectArgs);
OpenRelatedWebPage(projectArgs, template, isTiered, commandLineArgs);
@ -149,6 +149,7 @@ public class NewCommand : ProjectCreationCommandBase, IConsoleCommand, ITransien
sb.AppendLine("--local-framework-ref --abp-path <your-local-abp-repo-path> (keeps local references to projects instead of replacing with NuGet package references)");
sb.AppendLine("-sib|--skip-installing-libs (Doesn't run `abp install-libs` command after project creation)");
sb.AppendLine("-sb|--skip-bundling (Doesn't run `abp bundle` command after Blazor Wasm project creation)");
sb.AppendLine("-sc|--skip-cache (Always download the latest from our server and refresh their templates folder cache)");
sb.AppendLine("");
sb.AppendLine("Examples:");
sb.AppendLine("");

38
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs

@ -39,7 +39,7 @@ public abstract class ProjectCreationCommandBase
public ILogger<NewCommand> Logger { get; set; }
public ThemePackageAdder ThemePackageAdder { get; }
public AngularThemeConfigurer AngularThemeConfigurer { get; }
public ProjectCreationCommandBase(
@ -52,7 +52,7 @@ public abstract class ProjectCreationCommandBase
InitialMigrationCreator initialMigrationCreator,
ThemePackageAdder themePackageAdder,
ILocalEventBus eventBus,
IBundlingService bundlingService,
IBundlingService bundlingService,
AngularThemeConfigurer angularThemeConfigurer)
{
_bundlingService = bundlingService;
@ -221,10 +221,12 @@ public abstract class ProjectCreationCommandBase
}
commandLineArgs.Options.Add(CliConsts.Command, commandLineArgs.Command);
var theme = uiFramework == UiFramework.None ? (Theme?)null : GetThemeByTemplateOrNull(commandLineArgs, template);
var themeStyle = theme.HasValue ? GetThemeStyleOrNull(commandLineArgs, theme.Value) : (ThemeStyle?)null;
var skipCache = commandLineArgs.Options.ContainsKey(Options.SkipCache.Long) || commandLineArgs.Options.ContainsKey(Options.SkipCache.Short);
return new ProjectBuildArgs(
solutionName,
template,
@ -242,7 +244,8 @@ public abstract class ProjectCreationCommandBase
connectionString,
pwa,
theme,
themeStyle
themeStyle,
skipCache
);
}
@ -417,7 +420,7 @@ public abstract class ProjectCreationCommandBase
protected async Task RunBundleForBlazorWasmOrMauiBlazorTemplateAsync(ProjectBuildArgs projectArgs)
{
if ((AppTemplateBase.IsAppTemplate(projectArgs.TemplateName) || AppNoLayersTemplateBase.IsAppNoLayersTemplate(projectArgs.TemplateName))
if ((AppTemplateBase.IsAppTemplate(projectArgs.TemplateName) || AppNoLayersTemplateBase.IsAppNoLayersTemplate(projectArgs.TemplateName))
&& projectArgs.UiFramework is UiFramework.Blazor or UiFramework.MauiBlazor)
{
var isWebassembly = projectArgs.UiFramework == UiFramework.Blazor;
@ -432,7 +435,7 @@ public abstract class ProjectCreationCommandBase
var directory = Path.GetDirectoryName(
Directory.GetFiles(projectArgs.OutputFolder, isWebassembly? "*.Blazor.csproj" :"*.MauiBlazor.csproj", SearchOption.AllDirectories).First()
);
await _bundlingService.BundleAsync(directory, true, projectType: isWebassembly ? BundlingConsts.WebAssembly : BundlingConsts.MauiBlazor);
}
}
@ -584,10 +587,10 @@ public abstract class ProjectCreationCommandBase
{
// null or "leptonx-lite" => Theme.LeptonXLite,
"basic" => Theme.Basic,
_ => Theme.LeptonXLite
_ => Theme.LeptonXLite
};
}
Theme GetAppProTheme()
{
return theme switch
@ -600,16 +603,16 @@ public abstract class ProjectCreationCommandBase
}
}
protected virtual ThemeStyle? GetThemeStyleOrNull(CommandLineArgs commandLineArgs, Theme theme)
protected virtual ThemeStyle? GetThemeStyleOrNull(CommandLineArgs commandLineArgs, Theme theme)
{
if(theme != Theme.LeptonX)
if(theme != Theme.LeptonX)
{
return null;
}
var themeStyle = commandLineArgs.Options.GetOrNull(Options.ThemeStyle.Long)?.ToLower();
return themeStyle switch
return themeStyle switch
{
"system" or null => ThemeStyle.System,
"dim" => ThemeStyle.Dim,
@ -660,7 +663,7 @@ public abstract class ProjectCreationCommandBase
ThemePackageAdder.AddAngularPackage(projectArgs.OutputFolder, "@abp/ng.theme.basic", projectArgs.Version);
}
}
private void ConfigureNpmPackagesForLeptonTheme(ProjectBuildArgs projectArgs)
{
if (projectArgs.UiFramework is not UiFramework.None or UiFramework.Angular)
@ -686,7 +689,7 @@ public abstract class ProjectCreationCommandBase
{
return;
}
if (projectArgs.Theme.HasValue && projectArgs.UiFramework == UiFramework.Angular)
{
var angularFolderPath = projectArgs.TemplateName == MicroserviceProTemplate.TemplateName
@ -790,6 +793,13 @@ public abstract class ProjectCreationCommandBase
public const string Long = "skip-bundling";
}
public static class SkipCache
{
public const string Short = "sc";
public const string Long = "skip-cache";
}
public static class Tiered
{
public const string Long = "tiered";

12
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/AbpIoSourceCodeStore.cs

@ -59,7 +59,8 @@ public class AbpIoSourceCodeStore : ISourceCodeStore, ITransientDependency
string type,
string version = null,
string templateSource = null,
bool includePreReleases = false)
bool includePreReleases = false,
bool skipCache = false)
{
DirectoryHelper.CreateIfNotExists(CliPaths.TemplateCache);
var latestVersion = version ?? await GetLatestSourceCodeVersionAsync(name, type, null, includePreReleases);
@ -111,7 +112,7 @@ public class AbpIoSourceCodeStore : ISourceCodeStore, ITransientDependency
}
#endif
if (Options.CacheTemplates && File.Exists(localCacheFile) && templateSource.IsNullOrWhiteSpace())
if (Options.CacheTemplates && !skipCache && File.Exists(localCacheFile) && templateSource.IsNullOrWhiteSpace())
{
Logger.LogInformation("Using cached " + type + ": " + name + ", version: " + version);
return new TemplateFile(File.ReadAllBytes(localCacheFile), version, latestVersion, nugetVersion);
@ -132,6 +133,7 @@ public class AbpIoSourceCodeStore : ISourceCodeStore, ITransientDependency
if (Options.CacheTemplates && templateSource.IsNullOrWhiteSpace())
{
File.Delete(localCacheFile);
File.WriteAllBytes(localCacheFile, fileContent);
}
@ -218,7 +220,7 @@ public class AbpIoSourceCodeStore : ISourceCodeStore, ITransientDependency
var result = await response.Content.ReadAsStringAsync();
var versions = JsonSerializer.Deserialize<GithubReleaseVersions>(result);
return templateName.Contains("LeptonX") ?
return templateName.Contains("LeptonX") ?
versions.LeptonXVersions.Any(v => v.Name == version) :
versions.FrameworkAndCommercialVersions.Any(v => v.Name == version);
}
@ -335,7 +337,7 @@ public class AbpIoSourceCodeStore : ISourceCodeStore, ITransientDependency
public class GithubReleaseVersions
{
public List<GithubRelease> FrameworkAndCommercialVersions { get; set; }
public List<GithubRelease> LeptonXVersions { get; set; }
}
}
}

3
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ISourceCodeStore.cs

@ -10,6 +10,7 @@ public interface ISourceCodeStore
string type,
[CanBeNull] string version = null,
[CanBeNull] string templateSource = null,
bool includePreReleases = false
bool includePreReleases = false,
bool skipCache = false
);
}

6
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/ProjectBuildArgs.cs

@ -46,6 +46,8 @@ public class ProjectBuildArgs
public ThemeStyle? ThemeStyle { get; set; }
public bool SkipCache { get; set; }
[NotNull]
public Dictionary<string, string> ExtraProperties { get; set; }
@ -66,7 +68,8 @@ public class ProjectBuildArgs
[CanBeNull] string connectionString = null,
bool pwa = false,
Theme? theme = null,
ThemeStyle? themeStyle = null)
ThemeStyle? themeStyle = null,
bool skipCache = false)
{
SolutionName = Check.NotNull(solutionName, nameof(solutionName));
TemplateName = templateName;
@ -85,5 +88,6 @@ public class ProjectBuildArgs
Pwa = pwa;
Theme = theme;
ThemeStyle = themeStyle;
SkipCache = skipCache;
}
}

Loading…
Cancel
Save