Create dependencies repository.

This commit is contained in:
Kolosov Alexandr 2024-03-22 01:06:32 +05:00
parent 99fe793c16
commit 11e9fee9c3
24 changed files with 259 additions and 155 deletions

View File

@ -0,0 +1,24 @@
using Pastel;
using TUI.Engine.Theme;
namespace TUI.Engine;
public static class SymbolExtensions
{
public static string Colorized(this string symbol) =>
!SymbolColors.ContainsKey(symbol) ? symbol.Hint() : symbol.Pastel(SymbolColors[symbol]);
private static readonly Dictionary<string, string> SymbolColors = new()
{
{ Symbols.Git, "F14E32" },
{ Symbols.Site, "BF40BF" },
{ Symbols.GitLab, "E24329" },
{ Symbols.GitHub, "ADBAC7" },
{ Symbols.NetworkPublic, "00FFFF" },
{ Symbols.Api, "7F52FF" },
{ Symbols.DockerImage, "086DD7" },
{ Symbols.NpmPackage, "CB0000" },
{ Symbols.SEO, "4285F4" },
{ Symbols.Auth, "FFD700" },
};
}

View File

@ -1,6 +1,3 @@
using Pastel;
using TUI.Engine.Theme;
namespace TUI.Engine;
public static class Symbols
@ -35,24 +32,4 @@ public static class Symbols
public const string LeftTop = "┌";
public const string RightBottom = "┘";
}
}
public static class CharExtensions
{
public static string Colorized(this string symbol) =>
!SymbolColors.ContainsKey(symbol) ? symbol.Hint() : symbol.Pastel(SymbolColors[symbol]);
private static readonly Dictionary<string, string> SymbolColors = new()
{
{ Symbols.Git, "F14E32" },
{ Symbols.Site, "BF40BF" },
{ Symbols.GitLab, "E24329" },
{ Symbols.GitHub, "ADBAC7" },
{ Symbols.NetworkPublic, "00FFFF" },
{ Symbols.Api, "7F52FF" },
{ Symbols.DockerImage, "086DD7" },
{ Symbols.NpmPackage, "CB0000" },
{ Symbols.SEO, "4285F4" },
{ Symbols.Auth, "FFD700" },
};
}

View File

@ -9,23 +9,22 @@ public class VersionComponent : ComponentBase
{
private readonly VersionType _type;
private readonly string _version;
private readonly string? _icon;
private readonly Brand? _brand;
public VersionComponent(VersionType type, string version, string? icon = null)
public VersionComponent(VersionType type, string version, Brand? brand)
{
_type = type;
_version = version;
_icon = icon;
_brand = brand;
}
protected override Sketch DrawComponent(Size minSize)
{
var builder = new StringBuilder();
if (_icon is not null)
if (_brand is not null)
{
builder.Append(_icon.Colorized());
builder.Append(Symbols.Space);
builder.Append(_brand.ColorLogo());
}
builder.Append(_version);

View File

@ -2,6 +2,7 @@ using TUI.Controls.Components;
using TUI.Engine.Attributes.Orientations;
using TUI.Engine.Containers;
using TUI.Engine.Nodes;
using TUI.Engine.Theme;
namespace TUI.Controls.Containers;
@ -12,7 +13,8 @@ public class DashboardContainer : ContainerBase
public DashboardContainer()
{
var panel = new PanelComponent("Dependencies");
// var panel = new PanelComponent("Dependencies ".Info() + Symbols.Node.Colorized());
var panel = new PanelComponent("Dependencies".Info());
_content = new ContentContainer();
_content.SetOrientationVertical();
SetOrientationVertical();

View File

@ -0,0 +1,49 @@
using TUI.Controls.Common;
using TUI.Controls.Components;
using TUI.Domain;
using TUI.Engine.Attributes;
using TUI.Engine.Attributes.Alignments;
using TUI.Engine.Attributes.Orientations;
using TUI.Engine.Components;
using TUI.Engine.Containers;
using TUI.Engine.Nodes;
using TUI.Engine.Theme;
namespace TUI.Controls.Containers;
public class DependenciesContainer : ContainerBase
{
private const int VersionColumnWidth = 10;
private const int TitleColumnWidth = 20;
private readonly Nodes _dependencies = new();
public void AddTitleStub()
{
var size = new Size(TitleColumnWidth, 1);
var title = new StubComponent(size);
title.SetPadding(Level.Normal);
_dependencies.Add(title);
}
public void AddTitle(IComponent title)
{
title.SetPadding(Level.Normal);
title.SetFixed(Orientation.Horizontal, TitleColumnWidth);
_dependencies.Add(title);
}
public void AddDependency(Dependency dependency)
{
var version = new VersionComponent(VersionType.Convention, dependency.Version, dependency.Brand);
version.SetPadding(Level.Normal);
version.SetAlignment(Horizontal.Right);
version.SetFixed(Orientation.Horizontal, VersionColumnWidth);
_dependencies.Add(version);
}
public override Nodes GetNodes() => _dependencies;
}

View File

@ -1,29 +0,0 @@
using TUI.Controls.Common;
using TUI.Controls.Components;
using TUI.Engine;
using TUI.Engine.Attributes;
using TUI.Engine.Attributes.Alignments;
using TUI.Engine.Attributes.Orientations;
using TUI.Engine.Containers;
using TUI.Engine.Nodes;
using TUI.Engine.Theme;
namespace TUI.Controls.Containers;
public class DependencyContainer : ContainerBase
{
private const int VersionColumnWidth = 10;
public override Nodes GetNodes()
{
var stub = new StubComponent(new Size(20, 1));
stub.SetPadding(Level.Normal);
var version = new VersionComponent(VersionType.Convention, "10.20.30", Symbols.Site);
version.SetPadding(Level.Normal);
version.SetAlignment(Horizontal.Right);
version.SetFixed(Orientation.Horizontal, VersionColumnWidth);
return new Nodes { stub, version, version, };
}
}

8
src/TUI/Domain/Brand.cs Normal file
View File

@ -0,0 +1,8 @@
using Pastel;
namespace TUI.Controls.Components;
public record Brand(string Name, string Logo, string Color)
{
public string ColorLogo() => Logo.Pastel(Color);
};

View File

@ -0,0 +1,5 @@
using TUI.Controls.Components;
namespace TUI.Domain;
public record Dependency(string Version, Brand Brand);

View File

@ -1,27 +0,0 @@
using System.Runtime.Serialization;
using TUI.Settings;
using YamlDotNet.Serialization;
namespace TUI.Domain;
[DataContract]
[YamlSerializable]
public class ProjectDto
{
[YamlMember]
[DataMember]
public string Icon { get; set; }
[YamlMember]
[DataMember]
public string Name { get; set; }
[YamlMember]
[DataMember]
public DependencyDto[] Dependencies { get; set; }
[YamlMember]
[DataMember]
public IList<SourceDto> Sources { get; set; }
}

View File

@ -1,22 +0,0 @@
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace TUI.Domain;
[YamlSerializable]
public class Settings
{
[YamlMember]
public ProjectDto[] Projects { get; set; }
public static Settings Init()
{
var deserializer = new DeserializerBuilder()
.WithNamingConvention(UnderscoredNamingConvention.Instance)
.Build();
using var sr = new StreamReader("settings.yaml");
return deserializer.Deserialize<Settings>(sr.ReadToEnd());
}
}

View File

@ -2,33 +2,66 @@ using System.Diagnostics;
using TUI.Controls.Containers;
using TUI.Controls.Layouts;
using TUI.Controls.Statics;
using TUI.Domain;
using TUI.Engine.Rendering.Canvas;
using TUI.Providers.Dependencies;
namespace TUI.Pages;
public class DependenciesPage
interface IPage
{
void Open();
void Render();
void Bind();
}
public abstract class PageBase : IPage
{
public void Open()
{
Debugger.Log(0, "Event", "Open page dependencies\n");
Debugger.Log(0, "Event", $"Open page ${GetType().UnderlyingSystemType.Name}\n");
Bind();
Render();
}
public abstract void Render();
public abstract void Bind();
}
public class DependenciesPage : PageBase
{
private IEnumerable<Dependency> ConventionDependencies;
public override void Render()
{
ICanvas canvas = new ConsoleCanvas();
var header = new HeaderContainer();
var copyright = new CopyrightComponent();
var dashboard = new DashboardContainer();
var layout = new DashboardLayout(header, dashboard, copyright);
var dependency = new DependencyContainer();
dashboard.AddChildren(dependency);
dashboard.AddChildren(dependency);
dashboard.AddChildren(dependency);
dashboard.AddChildren(dependency);
var dependenciesHeader = new DependenciesContainer();
dependenciesHeader.AddTitleStub();
foreach (var conventionDependency in ConventionDependencies)
{
dependenciesHeader.AddDependency(conventionDependency);
}
dashboard.AddChildren(dependenciesHeader);
// CommandLine = new CommandLine();
// DependenciesView = new DependenciesView();
var layout = new DashboardLayout(header, dashboard, copyright);
canvas.Draw(layout);
}
public override void Bind()
{
var repo = new DependencyRepository();
ConventionDependencies = repo.Read("javascript");
}
// private bool _commandLineInDisplay;
// private ProjectDto _currentProjectDto;

View File

@ -0,0 +1,11 @@
using System.Runtime.Serialization;
using YamlDotNet.Serialization;
namespace TUI.Providers.Dependencies;
[DataContract]
[YamlSerializable]
public class DependenciesDto
{
[DataMember] [YamlMember] public StackDto[] Stacks { get; set; }
}

View File

@ -1,8 +1,7 @@
using System.Runtime.Serialization;
using YamlDotNet.Serialization;
namespace TUI.Settings;
namespace TUI.Providers.Dependencies;
[DataContract]
[YamlSerializable]

View File

@ -0,0 +1,43 @@
using TUI.Controls.Components;
using TUI.Domain;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace TUI.Providers.Dependencies;
public class DependencyRepository
{
private DependenciesDto? _dependenciesDto;
private DependenciesDto DependenciesDto
{
get
{
if (_dependenciesDto is not null)
{
return _dependenciesDto;
}
var deserializer = new DeserializerBuilder()
.WithNamingConvention(UnderscoredNamingConvention.Instance)
.Build();
using var sr = new StreamReader("dependencies.yaml");
_dependenciesDto = deserializer.Deserialize<DependenciesDto>(sr.ReadToEnd());
return _dependenciesDto;
}
}
public IEnumerable<Dependency> Read(string stackName)
{
return DependenciesDto.Stacks
.Single(stack => stack.Name == stackName)
.Conventions
.Select(convention =>
{
var brand = new Brand(convention.Name, convention.Icon, convention.Color);
return new Dependency(convention.Version, brand);
});
}
}

View File

@ -0,0 +1,15 @@
using System.Runtime.Serialization;
using YamlDotNet.Serialization;
namespace TUI.Providers.Dependencies;
[DataContract]
[YamlSerializable]
public class HubDto
{
[YamlMember] [DataMember] public string Origin { get; set; }
[YamlMember] [DataMember] public string Type { get; set; }
[YamlMember] [DataMember] public IEnumerable<ProjectDto> Projects { get; set; }
}

View File

@ -2,8 +2,7 @@ using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using TUI.Engine;
namespace TUI.Domain;
namespace TUI.Providers.Dependencies;
public class Package
{

View File

@ -0,0 +1,16 @@
using System.Runtime.Serialization;
using YamlDotNet.Serialization;
namespace TUI.Providers.Dependencies;
[YamlSerializable]
public class ProjectDto
{
[DataMember] [YamlMember] public int Id { get; set; }
[DataMember] [YamlMember] public string Name { get; set; }
[DataMember] [YamlMember] public string Deps { get; set; }
[DataMember] [YamlMember] public IEnumerable<string> Tags { get; set; }
}

View File

@ -0,0 +1,17 @@
using System.Runtime.Serialization;
using YamlDotNet.Serialization;
namespace TUI.Providers.Dependencies;
[DataContract]
[YamlSerializable]
public class StackDto
{
[YamlMember] [DataMember] public string Name { get; set; }
[YamlMember] [DataMember] public string Icon { get; set; }
[YamlMember] [DataMember] public DependencyDto[] Conventions { get; set; }
[YamlMember] [DataMember] public IEnumerable<HubDto> Hubs { get; set; }
}

View File

@ -1,20 +0,0 @@
using YamlDotNet.Serialization;
namespace TUI.Settings;
[YamlSerializable]
public class SourceDto
{
[YamlMember]
public string[] Tags { get; set; }
[YamlMember]
public string Name { get; set; }
[YamlMember]
public int ProjectId { get; set; } = 0;
[YamlMember]
public string Repo { get; set; }
}

View File

@ -1,7 +1,5 @@
using System.Text.Json;
using TUI.Domain;
using TUI.Engine;
using TUI.Settings;
using TUI.Providers.Dependencies;
namespace TUI.Store;
@ -9,9 +7,10 @@ public static class DependenciesStore
{
private readonly static Dictionary<string, Package> Packages = new();
private static Package DownloadPackage(SourceDto sourceDto)
private static Package DownloadPackage(ProjectDto projectDto)
{
var endpoint = sourceDto.Tags.Have("gitlab") ? GetGitlabEndpoint(sourceDto) : sourceDto.Repo;
// var endpoint = projectDto.Tags.Have("gitlab") ? GetGitlabEndpoint(projectDto) : projectDto.Repo;
var endpoint = "";
if (Packages.TryGetValue(endpoint, out var downloadPackage)) return downloadPackage;
using HttpClient client = new();
@ -21,10 +20,11 @@ public static class DependenciesStore
return package;
}
private static string GetGitlabEndpoint(SourceDto sourceDto)
private static string GetGitlabEndpoint(ProjectDto projectDto)
{
var token = Environment.GetEnvironmentVariable("TLD_GITLAB_PAT");
return $"{sourceDto.Repo}/api/v4/projects/{sourceDto.ProjectId}/repository/files/package.json/raw?" +
$"private_token={token}&ref=dev";
// return $"{projectDto.Repo}/api/v4/projects/{projectDto.ProjectId}/repository/files/package.json/raw?" +
// $"private_token={token}&ref=dev";
return "";
}
}

View File

@ -14,7 +14,7 @@
</ItemGroup>
<ItemGroup>
<None Update="settings.yaml">
<None Update="dependencies.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
@ -30,5 +30,8 @@
<ItemGroup>
<ProjectReference Include="..\TUI.Engine\TUI.Engine.csproj"/>
</ItemGroup>
<ItemGroup>
<Folder Include="Settings\" />
</ItemGroup>
</Project>

View File

@ -1,3 +1,4 @@
using Pastel;
using TUI.Engine;
@ -7,9 +8,9 @@ public static class Icons
{
public static readonly Dictionary<string, string> Applications = new()
{
{ Symbols.NpmPackage, "package" },
{ Symbols.DockerImage, "image" },
{ Symbols.Site, "site" },
{ Symbols.NpmPackage.Colorized(), "package" },
{ Symbols.DockerImage.Colorized(), "image" },
{ Symbols.Site.Pastel("666666"), "site" },
{ Symbols.Api, "api" }
};
}

View File

@ -1,5 +1,5 @@
using TUI.Engine.Theme;
using TUI.Settings;
using TUI.Providers.Dependencies;
namespace TUI.UserInterface;
@ -15,7 +15,7 @@ public static class Panel
private static int _marginTop;
public static void RenderRows(SourceDto[] sources, int selectedRowNumber)
public static void RenderRows(ProjectDto[] sources, int selectedRowNumber)
{
for (var index = 0; index < sources.Length; index++)
{

View File

@ -16,7 +16,8 @@ namespace TUI.Engine.Tests
[InlineData(VersionType.TooOld, "\u001b[38;2;236;151;6m10.12.33\u001b[0m")]
public void DrawSketchVersionTypes(VersionType versionType, string expected)
{
var version = new VersionComponent(versionType, "10.12.33");
var brand = new Brand("Docker", "󰡨", "#1d63ed");
var version = new VersionComponent(versionType, "10.12.33", brand);
var sketch = (version as IComponent).MakeSketch(new Size(10, 2));