Skip to content

Commit

Permalink
pse/adds component only projects (#109)
Browse files Browse the repository at this point in the history
Adds component only projects
  • Loading branch information
PascalSenn authored Jul 19, 2023
1 parent d1cbefe commit 4e9fd4e
Show file tree
Hide file tree
Showing 32 changed files with 141 additions and 143 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ private static class FieldNames
public const string ComponentProviders = "componentProviders";
public const string ConfigurationFiles = "configurationFiles";
public const string Subprojects = "subprojects";
public const string ProjectType = "type";
}

public ProjectConfiguration(
Expand All @@ -28,6 +29,7 @@ public ProjectConfiguration(
IReadOnlyList<ComponentProviderConfiguration>? componentProviders,
IReadOnlyList<ConfigurationFileConfiguration>? configurationFiles,
IReadOnlyList<ProjectConfiguration>? subprojects,
string? projectType,
IReadOnlyList<JsonFile> sourceFiles)
{
Name = name;
Expand All @@ -38,6 +40,7 @@ public ProjectConfiguration(
ComponentProviders = componentProviders;
ConfigurationFiles = configurationFiles;
Subprojects = subprojects;
ProjectType = projectType;
SourceFiles = sourceFiles;
}

Expand All @@ -59,6 +62,8 @@ public ProjectConfiguration(

public IReadOnlyList<JsonFile> SourceFiles { get; }

public string? ProjectType { get; }

public static ProjectConfiguration Parse(JsonNode? node)
=> Parse(node, Array.Empty<JsonFile>());

Expand Down Expand Up @@ -118,6 +123,10 @@ public static ProjectConfiguration Parse(JsonNode? node, IReadOnlyList<JsonFile>
.Select(Parse)
.ToArray();

var projectType = obj
.MaybeProperty(FieldNames.ProjectType)
?.ExpectValue<string>();

return new ProjectConfiguration(
name,
environments,
Expand All @@ -127,6 +136,7 @@ public static ProjectConfiguration Parse(JsonNode? node, IReadOnlyList<JsonFile>
componentProviders,
configurationFiles,
subprojects,
projectType,
sourceFiles);
}

Expand Down Expand Up @@ -163,6 +173,8 @@ public ProjectConfiguration Merge(ProjectConfiguration? other)

var sourceFiles = SourceFiles.Concat(other.SourceFiles).ToArray();

var projectType = other.ProjectType ?? ProjectType;

return new ProjectConfiguration(
name,
environments,
Expand All @@ -172,6 +184,7 @@ public ProjectConfiguration Merge(ProjectConfiguration? other)
componentProviders,
configurationFiles,
subprojects,
projectType,
sourceFiles);
}

Expand All @@ -188,5 +201,5 @@ public ProjectConfiguration Merge(ProjectConfiguration? other)
}

public static ProjectConfiguration Empty { get; } =
new(null, null, null, null, null, null, null, null, Array.Empty<JsonFile>());
new(null, null, null, null, null, null, null, null, null, Array.Empty<JsonFile>());
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public ProjectDefinition(
IReadOnlyList<ComponentProviderDefinition> componentProviders,
IReadOnlyList<ConfigurationFileDefinition> configurationFiles,
IReadOnlyList<ProjectDefinition> subprojects,
ProjectType projectType,
DirectoryInfo? directory)
{
Name = name;
Expand All @@ -26,6 +27,7 @@ public ProjectDefinition(
ComponentProviders = componentProviders;
ConfigurationFiles = configurationFiles;
Subprojects = subprojects;
ProjectType = projectType;
Directory = directory;
}

Expand All @@ -45,6 +47,8 @@ public ProjectDefinition(

public IReadOnlyList<ProjectDefinition> Subprojects { get; }

public ProjectType ProjectType { get; }

[JsonIgnore]
public DirectoryInfo? Directory { get; }

Expand Down Expand Up @@ -84,6 +88,12 @@ public static ProjectDefinition From(ProjectConfiguration configuration)
var subprojects = configuration.Subprojects?.Select(From).ToArray() ??
Array.Empty<ProjectDefinition>();

var projectType = configuration.ProjectType switch
{
"component" => ProjectType.Component,
_ => ProjectType.Default
};

return new ProjectDefinition(
name,
environments,
Expand All @@ -93,6 +103,7 @@ public static ProjectDefinition From(ProjectConfiguration configuration)
componentProviders,
configurationFiles,
subprojects,
projectType,
lastConfigurationFile?.File.Directory);
}

Expand All @@ -105,5 +116,6 @@ public static ProjectDefinition From(ProjectConfiguration configuration)
Array.Empty<ComponentProviderDefinition>(),
Array.Empty<ConfigurationFileDefinition>(),
Array.Empty<ProjectDefinition>(),
ProjectType.Default,
null);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Confix.Tool.Abstractions;

public enum ProjectType
{
Default,
Component
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Confix.Tool.Abstractions;
using Confix.Tool.Commands.Component;
using Confix.Tool.Commands.Logging;
using Confix.Tool.Commands.Temp;
Expand Down Expand Up @@ -32,10 +33,23 @@ public async Task InvokeAsync(IMiddlewareContext context, MiddlewareDelegate nex
await pipeline.ExecuteAsync(componentContext);
}

await next(context);
if (!project.IsOnlyComponents() && !context.IsOnlyComponents())
{
await next(context);
}
}
}

file static class Extensions
{
public static bool IsOnlyComponents(this IMiddlewareContext context)
=> context.Parameter.TryGet(OnlyComponentsOption.Instance, out bool onlyComponents) &&
onlyComponents;

public static bool IsOnlyComponents(this ProjectDefinition project)
=> project.ProjectType == ProjectType.Component;
}

file static class Log
{
public static void LogComponentDetected(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Confix.Tool.Common.Pipelines;

namespace Confix.Tool.Middlewares.Project;

public static class BuildComponentsOfProjectExtensions
{
public static IPipelineDescriptor UseBuildComponentsOfProject(
this IPipelineDescriptor descriptor)
{
descriptor.Use<BuildComponentsOfProjectMiddleware>();
descriptor.AddOption(OnlyComponentsOption.Instance);
return descriptor;
}
}
16 changes: 16 additions & 0 deletions src/Confix.Tool/src/Confix.Tool/Options/OnlyComponentsOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.CommandLine;

namespace Confix.Tool;

public sealed class OnlyComponentsOption : Option<bool>
{
public OnlyComponentsOption() : base(
"--only-components",
"If you specify this option, only the components will be built.")
{
IsRequired = false;
Arity = ArgumentArity.ZeroOrOne;
}

public static OnlyComponentsOption Instance { get; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected override void Configure(IPipelineDescriptor builder)
.Use<LoadConfigurationMiddleware>()
.UseReadConfigurationFiles()
.UseEnvironment()
.Use<BuildComponentsOfProjectMiddleware>()
.UseBuildComponentsOfProject()
.UseCompleteWhenNoConfigurationFiles()
.Use<VariableMiddleware>()
.Use<BuildProjectMiddleware>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected override void Configure(IPipelineDescriptor builder)
.Use<LoadConfigurationMiddleware>()
.UseReadConfigurationFiles()
.UseEnvironment()
.Use<BuildComponentsOfProjectMiddleware>()
.UseBuildComponentsOfProject()
.UseCompleteWhenNoConfigurationFiles()
.Use<VariableMiddleware>()
.Use<BuildProjectMiddleware>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public async Task Should_Copy_VariableFromOneProviderToTheOther()
// Arrange
using var cli = _cli;
const string beforeValue = "test";
await _first.SetAsync("a.b", beforeValue, CancellationToken.None);
var node = (JsonNode?)beforeValue;
await _first.SetAsync("a.b", node!, CancellationToken.None);

cli.Directories.Home.CreateConfixRc(_confixRc);

Expand All @@ -123,7 +124,8 @@ public async Task Should_Copy_VariableFromOneProviderToTheOther_When_DifferentEn
// Arrange
using var cli = _cli;
const string beforeValue = "test";
await _first.SetAsync("a.b", beforeValue, CancellationToken.None);
var node = (JsonNode?)beforeValue;
await _first.SetAsync("a.b", node!, CancellationToken.None);

cli.Directories.Home.CreateConfixRc(_confixRc);

Expand All @@ -143,7 +145,8 @@ public async Task Should_Fail_When_Environment_DoesNotExists()
// Arrange
using var cli = _cli;
const string beforeValue = "test";
await _first.SetAsync("a.b", beforeValue, CancellationToken.None);
var node = (JsonNode?)beforeValue;
await _first.SetAsync("a.b", node!, CancellationToken.None);

cli.Directories.Home.CreateConfixRc(_confixRc);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public void Merge_Should_ReturnOriginalConfiguration_When_OtherConfigurationIsNu
new List<ComponentProviderConfiguration>(),
new List<ConfigurationFileConfiguration>(),
new List<ProjectConfiguration>(),
null,
Array.Empty<JsonFile>()
);

Expand Down Expand Up @@ -215,8 +216,10 @@ public void Merge_Should_ReturnMergedConfiguration_When_OtherConfigurationIsNotN
null,
null,
null,
null,
Array.Empty<JsonFile>())
},
null,
Array.Empty<JsonFile>());
var other = new ProjectConfiguration(
"MergedProject",
Expand Down Expand Up @@ -257,8 +260,10 @@ public void Merge_Should_ReturnMergedConfiguration_When_OtherConfigurationIsNotN
null,
null,
null,
null,
Array.Empty<JsonFile>()),
},
null,
Array.Empty<JsonFile>()
);

Expand Down Expand Up @@ -366,7 +371,7 @@ await File.WriteAllTextAsync(confixRcPath,

var files = new List<JsonFile>
{
await JsonFile.FromFile(new(confixRcPath), default)
await JsonFile.FromFile(new(confixRcPath), default)
};
// Act
var result = ProjectConfiguration.LoadFromFiles(files);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@
}
],
"Subprojects": null,
"SourceFiles": []
"SourceFiles": [],
"ProjectType": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"ComponentProviders": null,
"ConfigurationFiles": null,
"Subprojects": null,
"SourceFiles": []
"SourceFiles": [],
"ProjectType": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"ComponentProviders": null,
"ConfigurationFiles": null,
"Subprojects": null,
"SourceFiles": []
"SourceFiles": [],
"ProjectType": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"ComponentProviders": null,
"ConfigurationFiles": null,
"Subprojects": null,
"SourceFiles": []
"SourceFiles": [],
"ProjectType": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"ComponentProviders": null,
"ConfigurationFiles": null,
"Subprojects": null,
"SourceFiles": []
"SourceFiles": [],
"ProjectType": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"ComponentProviders": null,
"ConfigurationFiles": null,
"Subprojects": null,
"SourceFiles": []
"SourceFiles": [],
"ProjectType": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"ComponentProviders": null,
"ConfigurationFiles": null,
"Subprojects": null,
"SourceFiles": []
"SourceFiles": [],
"ProjectType": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public void Merge_Should_ReturnMergedConfiguration_When_OtherConfigurationIsNotN
null,
null,
null,
null,
Array.Empty<JsonFile>()),
new ComponentConfiguration("MergedComponent",
new List<ComponentInputConfiguration>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void Merge_Should_ReturnMergedConfiguration_When_OtherConfigurationIsNotN
null,
null,
null,
null,
Array.Empty<JsonFile>()),
new ComponentConfiguration("MergedComponent",
new List<ComponentInputConfiguration>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"ComponentProviders": null,
"ConfigurationFiles": null,
"Subprojects": null,
"SourceFiles": []
"SourceFiles": [],
"ProjectType": null
},
"Encryption": {
"Provider": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"ComponentProviders": null,
"ConfigurationFiles": null,
"Subprojects": null,
"SourceFiles": []
"SourceFiles": [],
"ProjectType": null
},
"SourceFiles": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static CommandLineBuilder AddTestService<T>(
{
builder.AddMiddleware(x =>
{
T cache = default(T);
var cache = default(T);
x.BindingContext.AddService(sp => cache ??= factory(sp));
},
MiddlewareOrder.Configuration + 10);
Expand Down
Loading

0 comments on commit 4e9fd4e

Please sign in to comment.