mirror of
https://github.com/dnwSilver/tld.git
synced 2024-11-25 16:42:07 +00:00
✨ Create dependencies repository.
This commit is contained in:
parent
99fe793c16
commit
11e9fee9c3
24
src/TUI.Engine/SymbolExtensions.cs
Normal file
24
src/TUI.Engine/SymbolExtensions.cs
Normal 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" },
|
||||
};
|
||||
}
|
@ -1,6 +1,3 @@
|
||||
using Pastel;
|
||||
using TUI.Engine.Theme;
|
||||
|
||||
namespace TUI.Engine;
|
||||
|
||||
public static class Symbols
|
||||
@ -36,23 +33,3 @@ public static class Symbols
|
||||
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" },
|
||||
};
|
||||
}
|
@ -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);
|
||||
|
@ -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();
|
||||
|
49
src/TUI/Controls/Containers/DependenciesContainer.cs
Normal file
49
src/TUI/Controls/Containers/DependenciesContainer.cs
Normal 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;
|
||||
}
|
@ -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
8
src/TUI/Domain/Brand.cs
Normal 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);
|
||||
};
|
5
src/TUI/Domain/Dependency.cs
Normal file
5
src/TUI/Domain/Dependency.cs
Normal file
@ -0,0 +1,5 @@
|
||||
using TUI.Controls.Components;
|
||||
|
||||
namespace TUI.Domain;
|
||||
|
||||
public record Dependency(string Version, Brand Brand);
|
@ -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; }
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
11
src/TUI/Providers/Dependencies/DependenciesDto.cs
Normal file
11
src/TUI/Providers/Dependencies/DependenciesDto.cs
Normal 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; }
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
using System.Runtime.Serialization;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
|
||||
namespace TUI.Settings;
|
||||
namespace TUI.Providers.Dependencies;
|
||||
|
||||
[DataContract]
|
||||
[YamlSerializable]
|
43
src/TUI/Providers/Dependencies/DependencyRepository.cs
Normal file
43
src/TUI/Providers/Dependencies/DependencyRepository.cs
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
15
src/TUI/Providers/Dependencies/HubDto.cs
Normal file
15
src/TUI/Providers/Dependencies/HubDto.cs
Normal 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; }
|
||||
}
|
@ -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
|
||||
{
|
16
src/TUI/Providers/Dependencies/ProjectDto.cs
Normal file
16
src/TUI/Providers/Dependencies/ProjectDto.cs
Normal 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; }
|
||||
}
|
17
src/TUI/Providers/Dependencies/StackDto.cs
Normal file
17
src/TUI/Providers/Dependencies/StackDto.cs
Normal 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; }
|
||||
}
|
@ -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; }
|
||||
}
|
@ -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 "";
|
||||
}
|
||||
}
|
@ -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>
|
||||
|
@ -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" }
|
||||
};
|
||||
}
|
@ -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++)
|
||||
{
|
||||
|
@ -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));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user