minor fixes across the aspire scaffolders (#2910)

This commit is contained in:
Deep Choudhery 2024-08-07 14:54:17 -07:00 коммит произвёл GitHub
Родитель c31d207549
Коммит d00021a82d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
9 изменённых файлов: 43 добавлений и 17 удалений

Просмотреть файл

@ -22,12 +22,13 @@ public class CodeModificationStep : ScaffoldStep
//.csproj path for the .NET project
public required string ProjectPath { get; set; }
//properties to be injected into the CodeModifierConfig.CodeFile.Method.CodeSnippet's Blocks/Parents/CheckBlock
public required IDictionary<string, string> CodeModifierProperties { get; set; }
public IDictionary<string, string> CodeModifierProperties { get; }
private readonly ILogger _logger;
public CodeModificationStep(ILogger<CodeModificationStep> logger)
{
_logger = logger;
CodeModifierProperties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
public override async Task<bool> ExecuteAsync(ScaffolderContext context, CancellationToken cancellationToken = default)

Просмотреть файл

@ -22,7 +22,7 @@ internal static class GlobalToolFileFinder
var codeModificationConfigFolder = Path.Combine(toolsFolderPath, "CodeModificationConfigs");
if (Directory.Exists(codeModificationConfigFolder))
{
var files = Directory.EnumerateFiles(codeModificationConfigFolder, "*.json");
var files = Directory.EnumerateFiles(codeModificationConfigFolder, "*.json", SearchOption.AllDirectories);
return files.FirstOrDefault(x => Path.GetFileName(x).Equals(fileName, StringComparison.OrdinalIgnoreCase));
}

Просмотреть файл

@ -89,7 +89,7 @@ internal static class CachingScaffolderBuilderExtensions
commandSettingsObj is CommandSettings commandSettings)
{
var configName = commandSettings.Type.Equals("redis-with-output-caching", StringComparison.OrdinalIgnoreCase) ? "redis-webapp-oc.json" : "redis-webapp.json";
var codeModificationFilePath = GlobalToolFileFinder.FindCodeModificationConfigFile("redis-apphost.json", System.Reflection.Assembly.GetExecutingAssembly());
var codeModificationFilePath = GlobalToolFileFinder.FindCodeModificationConfigFile(configName, System.Reflection.Assembly.GetExecutingAssembly());
if (string.IsNullOrEmpty(codeModificationFilePath))
{
step.SkipStep = true;
@ -97,8 +97,7 @@ internal static class CachingScaffolderBuilderExtensions
}
step.CodeModifierConfigPath = codeModificationFilePath;
step.CodeModifierProperties = new Dictionary<string, string>();
step.ProjectPath = commandSettings.AppHostProject;
step.ProjectPath = commandSettings.Project;
step.CodeChangeOptions = [];
}
else

Просмотреть файл

@ -78,7 +78,11 @@ internal static class DatabaseScaffolderBuilderExtensions
var step = config.Step;
var codeModifierProperties = GetAppHostProperties(commandSettings);
step.CodeModifierConfigPath = codeModificationFilePath;
step.CodeModifierProperties = codeModifierProperties;
foreach (var kvp in codeModifierProperties)
{
step.CodeModifierProperties.TryAdd(kvp.Key, kvp.Value);
}
step.ProjectPath = commandSettings.AppHostProject;
step.CodeChangeOptions = [];
}
@ -94,7 +98,12 @@ internal static class DatabaseScaffolderBuilderExtensions
{
step.CodeModifierConfigPath = codeModificationFilePath;
step.CodeModifierProperties = GetApiProjectProperties(commandSettings);
var codeModifierProperties = GetApiProjectProperties(commandSettings);
foreach (var kvp in codeModifierProperties)
{
step.CodeModifierProperties.TryAdd(kvp.Key, kvp.Value);
}
step.ProjectPath = commandSettings.Project;
step.CodeChangeOptions = [];
}

Просмотреть файл

@ -72,7 +72,11 @@ internal static class StorageScaffolderBuilderExtensions
var step = config.Step;
var codeModifierProperties = GetAppHostProperties(commandSettings);
step.CodeModifierConfigPath = codeModificationFilePath;
step.CodeModifierProperties = codeModifierProperties;
foreach (var kvp in codeModifierProperties)
{
step.CodeModifierProperties.TryAdd(kvp.Key, kvp.Value);
}
step.ProjectPath = commandSettings.AppHostProject;
step.CodeChangeOptions = [];
}
@ -87,7 +91,12 @@ internal static class StorageScaffolderBuilderExtensions
{
var step = config.Step;
step.CodeModifierConfigPath = codeModificationFilePath;
step.CodeModifierProperties = GetApiProjectProperties(commandSettings);
var codeModifierProperties = GetApiProjectProperties(commandSettings);
foreach (var kvp in codeModifierProperties)
{
step.CodeModifierProperties.TryAdd(kvp.Key, kvp.Value);
}
step.ProjectPath = commandSettings.Project;
step.CodeChangeOptions = [];
}
@ -102,7 +111,7 @@ internal static class StorageScaffolderBuilderExtensions
if (StorageConstants.StoragePropertiesDict.TryGetValue(commandSettings.Type, out var storageProperties) && storageProperties is not null)
{
codeModifierProperties.Add("$(StorageVariableName)", storageProperties.VariableName);
codeModifierProperties.Add("$(AddStorageMethodName)", storageProperties.AddClientMethodName);
codeModifierProperties.Add("$(AddStorageMethodName)", storageProperties.AddMethodName);
}
return codeModifierProperties;

Просмотреть файл

@ -55,7 +55,7 @@ internal static class ValidationHelper
string? appHostProjectValue = context.GetOptionResult<string>(AspireCommandHelpers.AppHostCliOption);
string? workerProjectValue = context.GetOptionResult<string>(AspireCommandHelpers.WorkerProjectCliOption);
bool prereleaseValue = context.GetOptionResult<bool>(AspireCommandHelpers.PrereleaseCliOption);
if (string.IsNullOrEmpty(typeValue) || !AspireCommandHelpers.CachingTypeCustomValues.Contains(typeValue, StringComparer.OrdinalIgnoreCase))
if (string.IsNullOrEmpty(typeValue) || !AspireCommandHelpers.DatabaseTypeCustomValues.Contains(typeValue, StringComparer.OrdinalIgnoreCase))
{
string dbTypeDisplayList = string.Join(", ", AspireCommandHelpers.DatabaseTypeCustomValues.GetRange(0, AspireCommandHelpers.DatabaseTypeCustomValues.Count - 1)) +
(AspireCommandHelpers.DatabaseTypeCustomValues.Count > 1 ? " and " : "") + AspireCommandHelpers.DatabaseTypeCustomValues[AspireCommandHelpers.DatabaseTypeCustomValues.Count - 1];
@ -105,7 +105,7 @@ internal static class ValidationHelper
string? appHostProjectValue = context.GetOptionResult<string>(AspireCommandHelpers.AppHostCliOption);
string? workerProjectValue = context.GetOptionResult<string>(AspireCommandHelpers.WorkerProjectCliOption);
bool prereleaseValue = context.GetOptionResult<bool>(AspireCommandHelpers.PrereleaseCliOption);
if (string.IsNullOrEmpty(typeValue) || !AspireCommandHelpers.CachingTypeCustomValues.Contains(typeValue, StringComparer.OrdinalIgnoreCase))
if (string.IsNullOrEmpty(typeValue) || !AspireCommandHelpers.StorageTypeCustomValues.Contains(typeValue, StringComparer.OrdinalIgnoreCase))
{
string storageTypeDisplayList = string.Join(", ", AspireCommandHelpers.StorageTypeCustomValues.GetRange(0, AspireCommandHelpers.StorageTypeCustomValues.Count - 1)) +
(AspireCommandHelpers.StorageTypeCustomValues.Count > 1 ? " and " : "") + AspireCommandHelpers.StorageTypeCustomValues[AspireCommandHelpers.StorageTypeCustomValues.Count - 1];

Просмотреть файл

@ -24,10 +24,12 @@ internal class AddAspireCodeChangeStep : CodeModificationStep
await AddAutoGenProjectPropertiesAsync(commandSettings);
}
//TODO: analyze the project for these options, use default currently
CodeChangeOptions.Add("IsMinimalApp");
CodeChangeOptions.Add("UseTopLevelStatements");
return await base.ExecuteAsync(context, cancellationToken);
}
internal async Task AddAutoGenProjectPropertiesAsync(CommandSettings commandSettings)
{
var autoGenProjectNames = await AspireHelpers.GetAutoGeneratedProjectNamesAsync(commandSettings.AppHostProject, _logger);
@ -37,5 +39,4 @@ internal class AddAspireCodeChangeStep : CodeModificationStep
CodeModifierProperties.Add(Constants.CodeModifierPropertyConstants.AutoGenProjectName, autoGenProjectName);
}
}
}

Просмотреть файл

@ -111,7 +111,11 @@ internal static class BlazorCrudScaffolderBuilderExtensions
blazorCrudModel is not null)
{
step.CodeModifierConfigPath = codeModificationFilePath;
step.CodeModifierProperties = codeModifierProperties;
foreach (var kvp in codeModifierProperties)
{
step.CodeModifierProperties.TryAdd(kvp.Key, kvp.Value);
}
step.ProjectPath = blazorCrudSettings.Project;
step.CodeChangeOptions = blazorCrudModel.ProjectInfo.CodeChangeOptions ?? [];
}
@ -138,7 +142,6 @@ internal static class BlazorCrudScaffolderBuilderExtensions
!string.IsNullOrEmpty(blazorCodeModifierString))
{
step.CodeModifierConfigJsonText = blazorCodeModifierString;
step.CodeModifierProperties = new Dictionary<string, string>();
step.ProjectPath = blazorCrudSettings.Project;
step.CodeChangeOptions = blazorCrudModel.ProjectInfo.CodeChangeOptions ?? [];
}

Просмотреть файл

@ -37,7 +37,11 @@ internal static class MinimalApiScaffolderBuilderExtensions
minimalApiModel is not null)
{
step.CodeModifierConfigPath = codeModificationFilePath;
step.CodeModifierProperties = codeModifierProperties;
foreach (var kvp in codeModifierProperties)
{
step.CodeModifierProperties.TryAdd(kvp.Key, kvp.Value);
}
step.ProjectPath = minimalApiSettings.Project;
step.CodeChangeOptions = minimalApiModel.ProjectInfo.CodeChangeOptions ?? [];
}