Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support installer declarations #100

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a21f519
add install config definitions
Lordfirespeed Feb 14, 2024
5133b24
add install config to encompassing config
Lordfirespeed Feb 14, 2024
d5386ae
allow config providers to provide install config
Lordfirespeed Feb 14, 2024
f482371
add base implementation of GetInstallConfig
Lordfirespeed Feb 14, 2024
fa553fa
add InstallData member to ThunderstoreProject
Lordfirespeed Feb 14, 2024
e78e738
initialize Install data from parameterless ctor
Lordfirespeed Feb 14, 2024
2f48028
Initialize Install data from Config instance
Lordfirespeed Feb 14, 2024
477927e
override GetInstallConfig in ProjectFileConfig (provider)
Lordfirespeed Feb 14, 2024
a579ec7
add installer declarations field to package manifest definition
Lordfirespeed Feb 14, 2024
3344202
Write install config from `Config` instance to `PackageManifestV1` wh…
Lordfirespeed Feb 14, 2024
9b61bc4
remove unused 'using' directives
Lordfirespeed Feb 14, 2024
577b6af
to expression-bodied properties
Lordfirespeed Feb 14, 2024
bb8f07c
implement GetInstallConfig for default config provider
Lordfirespeed Feb 14, 2024
6f57fbc
update to language version 12
Lordfirespeed Feb 14, 2024
a7ec319
use collection expressions
Lordfirespeed Feb 14, 2024
96b2969
standardise fluent-chaining newlines
Lordfirespeed Feb 14, 2024
8899748
remove redundant empty parameters `()`
Lordfirespeed Feb 14, 2024
cd9a6d1
remove redundant null-forgiving
Lordfirespeed Feb 14, 2024
1b3bcb6
remove inaccurate nullable return type annotations
Lordfirespeed Feb 14, 2024
9dddd68
add JsonIgnore attribute to computed FullName property
Lordfirespeed Feb 15, 2024
05a142e
extract MergeConfigFromProvider method
Lordfirespeed Feb 15, 2024
7010ed5
add BlankConfig and DefaultConfig getters
Lordfirespeed Feb 15, 2024
db7ed25
use default config for `tcli init` command
Lordfirespeed Feb 15, 2024
20e6bcc
move default values out of ThunderstoreProject into DefaultConfig
Lordfirespeed Feb 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ThunderstoreCLI/API/ApiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

private static string SerializeFileData(string filePath)
{
return new FileData()
return new FileData

Check warning on line 111 in ThunderstoreCLI/API/ApiHelper.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/API/ApiHelper.cs#L111

Added line #L111 was not covered by tests
{
Filename = Path.GetFileName(filePath),
Filesize = new FileInfo(filePath).Length
Expand Down
9 changes: 7 additions & 2 deletions ThunderstoreCLI/Commands/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,19 @@
public static string SerializeManifest(Config config)
{
var dependencies = config.PackageConfig.Dependencies ?? new Dictionary<string, string>();
var manifest = new PackageManifestV1()
IEnumerable<InstallerDeclaration>? installerDeclarations = config.InstallConfig.InstallerDeclarations;

Check warning on line 297 in ThunderstoreCLI/Commands/BuildCommand.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Commands/BuildCommand.cs#L297

Added line #L297 was not covered by tests
installerDeclarations ??= Array.Empty<InstallerDeclaration>();
var manifest = new PackageManifestV1

Check warning on line 299 in ThunderstoreCLI/Commands/BuildCommand.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Commands/BuildCommand.cs#L299

Added line #L299 was not covered by tests
{
Namespace = config.PackageConfig.Namespace,
Name = config.PackageConfig.Name,
Description = config.PackageConfig.Description,
VersionNumber = config.PackageConfig.VersionNumber,
WebsiteUrl = config.PackageConfig.WebsiteUrl,
Dependencies = dependencies.Select(x => $"{x.Key}-{x.Value}").ToArray()
Dependencies = dependencies.Select(x => $"{x.Key}-{x.Value}").ToArray(),
Installers = installerDeclarations
.Select(x => new PackageManifestV1.InstallerDeclaration { Identifier = x.Identifier })
.ToArray()

Check warning on line 309 in ThunderstoreCLI/Commands/BuildCommand.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Commands/BuildCommand.cs#L306-L309

Added lines #L306 - L309 were not covered by tests
};

return manifest.Serialize(BaseJson.IndentedSettings);
Expand Down
2 changes: 1 addition & 1 deletion ThunderstoreCLI/Commands/InitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{
Write.Line($"Project configuration already exists, overwriting");
}
File.WriteAllText(path, new ThunderstoreProject(true).Serialize());
File.WriteAllText(path, new ThunderstoreProject(Config.DefaultConfig).Serialize());

Check warning on line 41 in ThunderstoreCLI/Commands/InitCommand.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Commands/InitCommand.cs#L41

Added line #L41 was not covered by tests

var iconPath = config.GetPackageIconPath();
if (File.Exists(iconPath))
Expand Down
1 change: 0 additions & 1 deletion ThunderstoreCLI/Commands/InstallCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Diagnostics;
using System.IO.Compression;
using System.Net.Http.Headers;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using ThunderstoreCLI.Configuration;
Expand Down
2 changes: 1 addition & 1 deletion ThunderstoreCLI/Commands/PublishCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
throw new PublishCommandException();
}

return new CompletedUpload.CompletedPartData()
return new CompletedUpload.CompletedPartData

Check warning on line 256 in ThunderstoreCLI/Commands/PublishCommand.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Commands/PublishCommand.cs#L256

Added line #L256 was not covered by tests
{
ETag = response.Headers.ETag.Tag,
PartNumber = part.PartNumber
Expand Down
1 change: 0 additions & 1 deletion ThunderstoreCLI/Commands/RunCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using ThunderstoreCLI.Configuration;
using ThunderstoreCLI.Game;
using ThunderstoreCLI.Utils;
Expand Down
22 changes: 11 additions & 11 deletions ThunderstoreCLI/Configuration/CLIParameterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public override GeneralConfig GetGeneralConfig()
{
return new GeneralConfig()
return new GeneralConfig

Check warning on line 14 in ThunderstoreCLI/Configuration/CLIParameterConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/CLIParameterConfig.cs#L14

Added line #L14 was not covered by tests
{
TcliConfig = options.TcliDirectory,
Repository = options.Repository
Expand All @@ -29,7 +29,7 @@
{
if (options == null)
return null;
return new PackageConfig()
return new PackageConfig

Check warning on line 32 in ThunderstoreCLI/Configuration/CLIParameterConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/CLIParameterConfig.cs#L32

Added line #L32 was not covered by tests
{
ProjectConfigPath = options.ConfigPath,
Namespace = options.Namespace,
Expand All @@ -45,7 +45,7 @@

public override InitConfig GetInitConfig()
{
return new InitConfig()
return new InitConfig

Check warning on line 48 in ThunderstoreCLI/Configuration/CLIParameterConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/CLIParameterConfig.cs#L48

Added line #L48 was not covered by tests
{
Overwrite = options.Overwrite
};
Expand All @@ -63,15 +63,15 @@

public override PublishConfig GetPublishConfig()
{
return new PublishConfig()
return new PublishConfig

Check warning on line 66 in ThunderstoreCLI/Configuration/CLIParameterConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/CLIParameterConfig.cs#L66

Added line #L66 was not covered by tests
{
File = options.File
};
}

public override AuthConfig GetAuthConfig()
{
return new AuthConfig()
return new AuthConfig

Check warning on line 74 in ThunderstoreCLI/Configuration/CLIParameterConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/CLIParameterConfig.cs#L74

Added line #L74 was not covered by tests
{
AuthToken = options.Token
};
Expand All @@ -82,9 +82,9 @@
{
public ModManagementCommandConfig(ModManagementOptions options) : base(options) { }

public override ModManagementConfig? GetModManagementConfig()
public override ModManagementConfig GetModManagementConfig()
{
return new ModManagementConfig()
return new ModManagementConfig

Check warning on line 87 in ThunderstoreCLI/Configuration/CLIParameterConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/CLIParameterConfig.cs#L87

Added line #L87 was not covered by tests
{
GameIdentifer = options.GameName,
ProfileName = options.Profile,
Expand All @@ -97,9 +97,9 @@
{
public GameImportCommandConfig(GameImportOptions options) : base(options) { }

public override GameImportConfig? GetGameImportConfig()
public override GameImportConfig GetGameImportConfig()
{
return new GameImportConfig()
return new GameImportConfig

Check warning on line 102 in ThunderstoreCLI/Configuration/CLIParameterConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/CLIParameterConfig.cs#L102

Added line #L102 was not covered by tests
{
ExePath = options.ExePath,
GameId = options.GameId,
Expand All @@ -111,9 +111,9 @@
{
public RunGameCommandConfig(RunGameOptions options) : base(options) { }

public override RunGameConfig? GetRunGameConfig()
public override RunGameConfig GetRunGameConfig()
{
return new RunGameConfig()
return new RunGameConfig

Check warning on line 116 in ThunderstoreCLI/Configuration/CLIParameterConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/CLIParameterConfig.cs#L116

Added line #L116 was not covered by tests
{
GameName = options.GameName,
ProfileName = options.Profile,
Expand Down
75 changes: 52 additions & 23 deletions ThunderstoreCLI/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public required InitConfig InitConfig { get; init; }
public required BuildConfig BuildConfig { get; init; }
public required PublishConfig PublishConfig { get; init; }
public required InstallConfig InstallConfig { get; init; }

Check warning on line 16 in ThunderstoreCLI/Configuration/Config.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/Config.cs#L16

Added line #L16 was not covered by tests
public required AuthConfig AuthConfig { get; init; }
public required ModManagementConfig ModManagementConfig { get; init; }
public required GameImportConfig GameImportConfig { get; init; }
Expand All @@ -30,6 +31,23 @@
api = new Lazy<ApiHelper>(() => new ApiHelper(this));
cache = new Lazy<DownloadCache>(() => new DownloadCache(Path.Combine(GeneralConfig!.TcliConfig, "ModCache")));
}

private static Config BlankConfig => new()
{
GeneralConfig = new GeneralConfig(),
PackageConfig = new PackageConfig(),
InitConfig = new InitConfig(),
BuildConfig = new BuildConfig(),
PublishConfig = new PublishConfig(),
InstallConfig = new InstallConfig(),
AuthConfig = new AuthConfig(),
ModManagementConfig = new ModManagementConfig(),
GameImportConfig = new GameImportConfig(),
RunGameConfig = new RunGameConfig(),
};

Check warning on line 47 in ThunderstoreCLI/Configuration/Config.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/Config.cs#L35-L47

Added lines #L35 - L47 were not covered by tests

public static Config DefaultConfig => MergeConfigFromProvider(BlankConfig, new DefaultConfig(), true);

Check warning on line 49 in ThunderstoreCLI/Configuration/Config.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/Config.cs#L49

Added line #L49 was not covered by tests

public static Config FromCLI(IConfigProvider cliConfig)
{
List<IConfigProvider> providers = new();
Expand Down Expand Up @@ -99,7 +117,7 @@

public PackageUploadMetadata GetUploadMetadata(string fileUuid)
{
return new PackageUploadMetadata()
return new PackageUploadMetadata
{
AuthorName = PackageConfig.Namespace,
Categories = PublishConfig.Categories!.GetOrDefault("") ?? Array.Empty<string>(),
Expand All @@ -114,34 +132,30 @@

public static Config Parse(IConfigProvider[] configProviders)
{
Config result = new()
{
GeneralConfig = new GeneralConfig(),
PackageConfig = new PackageConfig(),
InitConfig = new InitConfig(),
BuildConfig = new BuildConfig(),
PublishConfig = new PublishConfig(),
AuthConfig = new AuthConfig(),
ModManagementConfig = new ModManagementConfig(),
GameImportConfig = new GameImportConfig(),
RunGameConfig = new RunGameConfig(),
};
var result = BlankConfig;

Check warning on line 135 in ThunderstoreCLI/Configuration/Config.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/Config.cs#L135

Added line #L135 was not covered by tests
foreach (var provider in configProviders)
{
provider.Parse(result);
Merge(result.GeneralConfig, provider.GetGeneralConfig(), false);
Merge(result.PackageConfig, provider.GetPackageMeta(), false);
Merge(result.InitConfig, provider.GetInitConfig(), false);
Merge(result.BuildConfig, provider.GetBuildConfig(), false);
Merge(result.PublishConfig, provider.GetPublishConfig(), false);
Merge(result.AuthConfig, provider.GetAuthConfig(), false);
Merge(result.ModManagementConfig, provider.GetModManagementConfig(), false);
Merge(result.GameImportConfig, provider.GetGameImportConfig(), false);
Merge(result.RunGameConfig, provider.GetRunGameConfig(), false);
MergeConfigFromProvider(result, provider, false);

Check warning on line 138 in ThunderstoreCLI/Configuration/Config.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/Config.cs#L138

Added line #L138 was not covered by tests
}
return result;
}

public static Config MergeConfigFromProvider(Config target, IConfigProvider provider, bool overwrite)
{
provider.Parse(target);
Merge(target.GeneralConfig, provider.GetGeneralConfig(), overwrite);
Merge(target.PackageConfig, provider.GetPackageMeta(), overwrite);
Merge(target.InitConfig, provider.GetInitConfig(), overwrite);
Merge(target.BuildConfig, provider.GetBuildConfig(), overwrite);
Merge(target.PublishConfig, provider.GetPublishConfig(), overwrite);
Merge(target.InstallConfig, provider.GetInstallConfig(), overwrite);
Merge(target.AuthConfig, provider.GetAuthConfig(), overwrite);
Merge(target.ModManagementConfig, provider.GetModManagementConfig(), overwrite);
Merge(target.GameImportConfig, provider.GetGameImportConfig(), overwrite);
Merge(target.RunGameConfig, provider.GetRunGameConfig(), overwrite);
return target;
}

Check warning on line 157 in ThunderstoreCLI/Configuration/Config.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/Config.cs#L144-L157

Added lines #L144 - L157 were not covered by tests

public static void Merge<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(T target, T source, bool overwrite)
{
if (source == null)
Expand Down Expand Up @@ -218,6 +232,21 @@
public Dictionary<string, string[]>? Categories { get; set; }
}

public struct InstallerDeclaration
{
public readonly string Identifier;

public InstallerDeclaration(string identifier)
{
Identifier = identifier;
}

Check warning on line 242 in ThunderstoreCLI/Configuration/Config.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/Config.cs#L240-L242

Added lines #L240 - L242 were not covered by tests
}

public class InstallConfig
{
public List<InstallerDeclaration>? InstallerDeclarations { get; set; }

Check warning on line 247 in ThunderstoreCLI/Configuration/Config.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/Config.cs#L247

Added line #L247 was not covered by tests
}

public class AuthConfig
{
public string? AuthToken { get; set; }
Expand Down
35 changes: 22 additions & 13 deletions ThunderstoreCLI/Configuration/DefaultConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,68 @@

class DefaultConfig : EmptyConfig
{
public override GeneralConfig? GetGeneralConfig()
public override GeneralConfig GetGeneralConfig()
{
return new GeneralConfig()
return new GeneralConfig

Check warning on line 7 in ThunderstoreCLI/Configuration/DefaultConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/DefaultConfig.cs#L7

Added line #L7 was not covered by tests
{
Repository = Defaults.REPOSITORY_URL
};
}

public override PackageConfig GetPackageMeta()
{
return new PackageConfig()
return new PackageConfig

Check warning on line 15 in ThunderstoreCLI/Configuration/DefaultConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/DefaultConfig.cs#L15

Added line #L15 was not covered by tests
{
ProjectConfigPath = Defaults.PROJECT_CONFIG_PATH,
Namespace = "AuthorName",
Name = "PackageName",
VersionNumber = "0.0.1",
Description = "Example mod description",
WebsiteUrl = "",
WebsiteUrl = "https://thunderstore.io",

Check warning on line 22 in ThunderstoreCLI/Configuration/DefaultConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/DefaultConfig.cs#L22

Added line #L22 was not covered by tests
ContainsNsfwContent = false,
Dependencies = new()
{
{ "Example-Dependency", "1.0.0" }
{ "AuthorName-PackageName", "0.0.1" }

Check warning on line 26 in ThunderstoreCLI/Configuration/DefaultConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/DefaultConfig.cs#L26

Added line #L26 was not covered by tests
}
};
}

public override InitConfig GetInitConfig()
{
return new InitConfig()
return new InitConfig

Check warning on line 33 in ThunderstoreCLI/Configuration/DefaultConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/DefaultConfig.cs#L33

Added line #L33 was not covered by tests
{
Overwrite = false
};
}

public override BuildConfig GetBuildConfig()
{
return new BuildConfig()
return new BuildConfig

Check warning on line 41 in ThunderstoreCLI/Configuration/DefaultConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/DefaultConfig.cs#L41

Added line #L41 was not covered by tests
{
IconPath = "./icon.png",
ReadmePath = "./README.md",
OutDir = "./build",
CopyPaths = new()
{
{ new("./dist", "") }
}
CopyPaths = [new("./dist", "")]

Check warning on line 46 in ThunderstoreCLI/Configuration/DefaultConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/DefaultConfig.cs#L46

Added line #L46 was not covered by tests
};
}

public override PublishConfig GetPublishConfig()
{
return new PublishConfig()
return new PublishConfig
{
File = null,
Communities = ["riskofrain2"],
Categories = new Dictionary<string, string[]> {
{ "riskofrain2", ["items", "skills", ] },
}
};
}

Check warning on line 60 in ThunderstoreCLI/Configuration/DefaultConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/DefaultConfig.cs#L52-L60

Added lines #L52 - L60 were not covered by tests

public override InstallConfig GetInstallConfig()
{
return new InstallConfig

Check warning on line 64 in ThunderstoreCLI/Configuration/DefaultConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/DefaultConfig.cs#L63-L64

Added lines #L63 - L64 were not covered by tests
{
File = null
InstallerDeclarations = [new InstallerDeclaration("foo-installer")]

Check warning on line 66 in ThunderstoreCLI/Configuration/DefaultConfig.cs

View check run for this annotation

Codecov / codecov/patch

ThunderstoreCLI/Configuration/DefaultConfig.cs#L66

Added line #L66 was not covered by tests
};
}
}
Loading
Loading