|
|
|
@ -6,28 +6,28 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps; |
|
|
|
|
|
|
|
public class CreateAppSettingsSecretsStep : ProjectBuildPipelineStep |
|
|
|
{ |
|
|
|
private const string FileName = "appsettings.secrets.json"; |
|
|
|
private const string AppSettingsFileName = "appsettings.json"; |
|
|
|
private const string AppSettingsPlaceholder = "<!--APPSETTINGS-SECRETS-->"; |
|
|
|
|
|
|
|
public override void Execute(ProjectBuildContext context) |
|
|
|
{ |
|
|
|
var appSettingsFiles = context.Files |
|
|
|
.Where(x => |
|
|
|
x.Name.EndsWith(AppSettingsFileName) && |
|
|
|
NotBlazorWasmProject(x.Name)) |
|
|
|
.Where(x => x.Name.EndsWith(CliConsts.AppSettingsJsonFileName) && NotBlazorWasmProject(x.Name)) |
|
|
|
.ToList(); |
|
|
|
|
|
|
|
var content = context.Template.IsPro() |
|
|
|
? $"{{{Environment.NewLine} \"AbpLicenseCode\": \"<LICENSE_CODE/>\" {Environment.NewLine}}}" |
|
|
|
: $"{{{Environment.NewLine}}}"; |
|
|
|
if (!appSettingsFiles.Any()) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var appsettingsSecretJsonContent = GetAppSettingsSecretJsonContent(context); |
|
|
|
|
|
|
|
foreach (var appSettingsFile in appSettingsFiles) |
|
|
|
{ |
|
|
|
context.Files.Add(new FileEntry( |
|
|
|
appSettingsFile.Name.Replace(AppSettingsFileName, FileName), |
|
|
|
content.GetBytes(), |
|
|
|
false)); |
|
|
|
appSettingsFile.Name.Replace(CliConsts.AppSettingsJsonFileName, CliConsts.AppSettingsSecretJsonFileName), |
|
|
|
appsettingsSecretJsonContent, |
|
|
|
false) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
var projectFiles = context.Files.Where(x => x.Content.Contains(AppSettingsPlaceholder)).ToList(); |
|
|
|
@ -38,6 +38,13 @@ public class CreateAppSettingsSecretsStep : ProjectBuildPipelineStep |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static byte[] GetAppSettingsSecretJsonContent(ProjectBuildContext context) |
|
|
|
{ |
|
|
|
return context.Template.IsPro() |
|
|
|
? $"{{{Environment.NewLine} \"AbpLicenseCode\": \"{CliConsts.LicenseCodePlaceHolder}\" {Environment.NewLine}}}".GetBytes() |
|
|
|
: $"{{{Environment.NewLine}}}".GetBytes(); |
|
|
|
} |
|
|
|
|
|
|
|
private static bool NotBlazorWasmProject(string fileName) |
|
|
|
{ |
|
|
|
return !fileName.Contains("Blazor/wwwroot") && !fileName.Contains("Blazor.Host/wwwroot"); |
|
|
|
@ -45,11 +52,11 @@ public class CreateAppSettingsSecretsStep : ProjectBuildPipelineStep |
|
|
|
|
|
|
|
private static string ReplaceAppSettingsSecretsPlaceholder(string content) |
|
|
|
{ |
|
|
|
var replaceContent = $"<None Remove=\"{FileName}\" />{Environment.NewLine}" + |
|
|
|
$" <Content Include=\"{FileName}\">{Environment.NewLine}" + |
|
|
|
var replaceContent = $"<None Remove=\"{CliConsts.AppSettingsSecretJsonFileName}\" />{Environment.NewLine}" + |
|
|
|
$" <Content Include=\"{CliConsts.AppSettingsSecretJsonFileName}\">{Environment.NewLine}" + |
|
|
|
$" <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>{Environment.NewLine}" + |
|
|
|
$" <CopyToOutputDirectory>Always</CopyToOutputDirectory>{Environment.NewLine}" + |
|
|
|
" </Content>"; |
|
|
|
return content.Replace(AppSettingsPlaceholder, replaceContent); |
|
|
|
} |
|
|
|
} |
|
|
|
} |