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. 1
      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. 1
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs
  6. 12
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs
  7. 6
      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. * **`logout`**: Logouts from your computer if you've authenticated before.
* **`bundle`**: Generates script and style references for ABP Blazor and MAUI Blazor project. * **`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. * **`install-libs`**: Install NPM Packages for MVC / Razor Pages and Blazor Server UI types.
* **`clear-download-cache`** Clears the templates download cache.
### help ### 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. * `--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. * `--no-random-port`: Uses template's default ports.
* `--skip-installing-libs` or `-sib`: Skip installing client side packages. * `--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. * `--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. 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`**: 在你的计算机注销认证. * **`logout`**: 在你的计算机注销认证.
* **`bundle`**: 为 ABP Blazor 和 MAUI Blazor 项目生成引用的脚本和样式. * **`bundle`**: 为 ABP Blazor 和 MAUI Blazor 项目生成引用的脚本和样式.
* **`install-libs`**: 为 MVC / Razor Pages 和 Blazor Server UI 类型安装NPM包. * **`install-libs`**: 为 MVC / Razor Pages 和 Blazor Server UI 类型安装NPM包.
* **`clear-download-cache`** 删除下载的模版缓存.
### help ### help
@ -142,6 +143,7 @@ abp new Acme.BookStore
* `--create-solution-folder` 或者 `-csf`: 指定项目是在输出文件夹中的新文件夹中还是直接在输出文件夹中. * `--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)进行更改(创建解决方案之后). * `--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包引用. * `--local-framework-ref --abp-path`: 使用对项目的本地引用,而不是替换为NuGet包引用.
* `--skip-cache` or `-sc`: 从服务器下载最新的模版并更新本地模版缓存.
### update ### update

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

@ -64,6 +64,7 @@ public class AbpCliCoreModule : AbpModule
options.Commands[InstallLibsCommand.Name] = typeof(InstallLibsCommand); options.Commands[InstallLibsCommand.Name] = typeof(InstallLibsCommand);
options.Commands[CleanCommand.Name] = typeof(CleanCommand); options.Commands[CleanCommand.Name] = typeof(CleanCommand);
options.Commands[CliCommand.Name] = typeof(CliCommand); 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.Pro");
options.DisabledModulesToAddToSolution.Add("Volo.Abp.LeptonXTheme.Lite"); 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.";
}
}

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

@ -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("--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("-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("-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("");
sb.AppendLine("Examples:"); sb.AppendLine("Examples:");
sb.AppendLine(""); sb.AppendLine("");

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

@ -225,6 +225,8 @@ public abstract class ProjectCreationCommandBase
var theme = uiFramework == UiFramework.None ? (Theme?)null : GetThemeByTemplateOrNull(commandLineArgs, template); var theme = uiFramework == UiFramework.None ? (Theme?)null : GetThemeByTemplateOrNull(commandLineArgs, template);
var themeStyle = theme.HasValue ? GetThemeStyleOrNull(commandLineArgs, theme.Value) : (ThemeStyle?)null; 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( return new ProjectBuildArgs(
solutionName, solutionName,
template, template,
@ -242,7 +244,8 @@ public abstract class ProjectCreationCommandBase
connectionString, connectionString,
pwa, pwa,
theme, theme,
themeStyle themeStyle,
skipCache
); );
} }
@ -790,6 +793,13 @@ public abstract class ProjectCreationCommandBase
public const string Long = "skip-bundling"; 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 static class Tiered
{ {
public const string Long = "tiered"; public const string Long = "tiered";

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

@ -59,7 +59,8 @@ public class AbpIoSourceCodeStore : ISourceCodeStore, ITransientDependency
string type, string type,
string version = null, string version = null,
string templateSource = null, string templateSource = null,
bool includePreReleases = false) bool includePreReleases = false,
bool skipCache = false)
{ {
DirectoryHelper.CreateIfNotExists(CliPaths.TemplateCache); DirectoryHelper.CreateIfNotExists(CliPaths.TemplateCache);
var latestVersion = version ?? await GetLatestSourceCodeVersionAsync(name, type, null, includePreReleases); var latestVersion = version ?? await GetLatestSourceCodeVersionAsync(name, type, null, includePreReleases);
@ -111,7 +112,7 @@ public class AbpIoSourceCodeStore : ISourceCodeStore, ITransientDependency
} }
#endif #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); Logger.LogInformation("Using cached " + type + ": " + name + ", version: " + version);
return new TemplateFile(File.ReadAllBytes(localCacheFile), version, latestVersion, nugetVersion); return new TemplateFile(File.ReadAllBytes(localCacheFile), version, latestVersion, nugetVersion);
@ -132,6 +133,7 @@ public class AbpIoSourceCodeStore : ISourceCodeStore, ITransientDependency
if (Options.CacheTemplates && templateSource.IsNullOrWhiteSpace()) if (Options.CacheTemplates && templateSource.IsNullOrWhiteSpace())
{ {
File.Delete(localCacheFile);
File.WriteAllBytes(localCacheFile, fileContent); File.WriteAllBytes(localCacheFile, fileContent);
} }

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

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

Loading…
Cancel
Save