Skip to content

Commit

Permalink
cleanup, fix configuration migration for v5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kentico-ericd committed Sep 27, 2024
1 parent a1426ef commit 09ebc94
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/Commands/Base/AbstractCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public virtual Task PreExecute(ToolProfile? profile, string? action)


/// <summary>
/// A handler which can be assigned to <see cref="Process.ErrorDataReceived"/> to handler errors.
/// A handler which can be assigned to <see cref="Process.ErrorDataReceived"/> to handle errors.
/// </summary>
protected void ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
Expand All @@ -80,7 +80,7 @@ protected void LogError(string message, Process? process = null)
}


protected void PrintCurrentProfile(ToolProfile? profile)
protected static void PrintCurrentProfile(ToolProfile? profile)
{
AnsiConsole.Write(new Rule("Current profile:") { Justification = Justify.Left });
AnsiConsole.MarkupLineInterpolated($"Name: [{Constants.EMPHASIS_COLOR}]{profile?.ProjectName ?? "None"}[/]");
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/SettingsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private async Task<bool> TryUpdateHeadlessOption(CmsHeadlessConfiguration headle
}


private string? Truncate(string? value, int maxLength, string truncationSuffix = "...") => value?.Length > maxLength
private static string? Truncate(string? value, int maxLength, string truncationSuffix = "...") => value?.Length > maxLength
? value[..maxLength] + truncationSuffix
: value;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Services/AppSettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public async Task SetKeyValue(ToolProfile? profile, string keyName, object value
}


private string GetAppSettingsPath(ToolProfile profile) => $"{profile.WorkingDirectory}/appsettings.json";
private static string GetAppSettingsPath(ToolProfile profile) => $"{profile.WorkingDirectory}/appsettings.json";


private Task<JObject> LoadSettings(ToolProfile? profile)
private static Task<JObject> LoadSettings(ToolProfile? profile)
{
if (profile is null)
{
Expand All @@ -92,7 +92,7 @@ private Task<JObject> LoadSettings(ToolProfile? profile)
}


private async Task<JObject> LoadSettingsInternal(ToolProfile profile)
private static async Task<JObject> LoadSettingsInternal(ToolProfile profile)
{
string settingsPath = GetAppSettingsPath(profile);
if (!File.Exists(settingsPath))
Expand All @@ -106,7 +106,7 @@ private async Task<JObject> LoadSettingsInternal(ToolProfile profile)
}


private Task WriteAppSettings(ToolProfile? profile, JObject appSettings)
private static Task WriteAppSettings(ToolProfile? profile, JObject appSettings)
{
if (profile is null)
{
Expand All @@ -117,7 +117,7 @@ private Task WriteAppSettings(ToolProfile? profile, JObject appSettings)
}


private async Task WriteAppSettingsInternal(ToolProfile profile, JObject appSettings)
private static async Task WriteAppSettingsInternal(ToolProfile profile, JObject appSettings)
{
string settingsPath = GetAppSettingsPath(profile);

Expand Down
7 changes: 4 additions & 3 deletions src/Services/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using Xperience.Manager.Configuration;
using Xperience.Manager.Options;

Expand Down Expand Up @@ -139,9 +140,9 @@ private async Task MigrateConfig(Version toolVersion)
string text = await File.ReadAllTextAsync(Constants.CONFIG_FILENAME);
var json = JsonConvert.DeserializeObject<JObject>(text) ??
throw new InvalidOperationException("Unable to read configuration file for migration.");
if ((config.Version?.ToString().Equals("4.0.0.0") ?? false) && toolVersion.ToString().Equals("4.1.0.0"))
if ((config.Version?.ToString().Equals("4.0.0.0") ?? false) && toolVersion.ToString().Equals("5.0.0.0"))
{
Migrate40To41(json, config);
Migrate40To50(json, config);
}

config.Version = toolVersion;
Expand Down Expand Up @@ -176,7 +177,7 @@ private static Task WriteConfig(ToolConfiguration config) =>
File.WriteAllTextAsync(Constants.CONFIG_FILENAME, JsonConvert.SerializeObject(config, Formatting.Indented));


private static void Migrate40To41(JObject oldConfig, ToolConfiguration newConfig)
private static void Migrate40To50(JObject oldConfig, ToolConfiguration newConfig)
{
var oldInstallOptions = oldConfig["DefaultInstallOptions"];

Expand Down
4 changes: 4 additions & 0 deletions src/Services/ScriptBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,13 @@ public enum ScriptType
/// </summary>
ResignMacros,


/// <summary>
/// The script which generates code files for Xperience objects.
/// </summary>
GenerateCode,


/// <summary>
/// The script which deletes a local folder and its contents.
/// </summary>
Expand All @@ -293,11 +295,13 @@ public enum ScriptType
/// </summary>
ExecuteSql,


/// <summary>
/// The script which uninstalls the Kentico.Xperience.DbManager global tool.
/// </summary>
UninstallDatabaseTool,


/// <summary>
/// The script which installs the Kentico.Xperience.DbManager global tool.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Wizards/Base/IWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public interface IWizard<TOptions> where TOptions : IWizardOptions
/// Initializes the <see cref="Steps"/> with the <see cref="Step{T}"/>s required to
/// populate the <see cref="Options"/>.
/// </summary>
/// <param name="args">Optional arguments to pass to the step initialization.
/// <param name="args">Optional arguments to pass to the step initialization.</param>
public Task InitSteps(params string[] args);


/// <summary>
/// Requests user input to generate the <see cref="Options"/>.
/// </summary>
/// <param name="args">Optional arguments to pass to the wizard.
/// <param name="args">Optional arguments to pass to the wizard.</param>
public Task<TOptions> Run(params string[] args);
}
}

0 comments on commit 09ebc94

Please sign in to comment.