mirror of
https://github.com/dnwSilver/tld.git
synced 2025-01-19 09:22:08 +00:00
🔊 Add logs.
This commit is contained in:
parent
d01491f5cd
commit
dd339130b8
2
.gitignore
vendored
2
.gitignore
vendored
@ -342,4 +342,4 @@ healthchecksdb
|
|||||||
*.DotSettings
|
*.DotSettings
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
**/*.Production.json
|
**/*.Production.json
|
||||||
Logs/
|
**/*.log
|
@ -42,10 +42,10 @@ public static class Extensions
|
|||||||
|
|
||||||
public static Version ToVersion(this string textVersion)
|
public static Version ToVersion(this string textVersion)
|
||||||
{
|
{
|
||||||
var version = textVersion.Replace("^", "").Replace("~", "").Split(".");
|
var version = textVersion.Replace("^", "").Replace("v", "").Replace("~", "").Split(".");
|
||||||
var major = Convert.ToInt32(version[0]);
|
var major = Convert.ToInt32(version[0]);
|
||||||
var minor = Convert.ToInt32(version[1]);
|
var minor = Convert.ToInt32(version[1]);
|
||||||
var patch = Convert.ToInt32(version[2].Split('-')[0]);
|
var patch = Convert.ToInt32(version[2].Split('-')[0]);
|
||||||
return new Version(major, minor, patch);
|
return new Version(major, minor, patch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ using TUI.Engine;
|
|||||||
using TUI.Engine.Attributes;
|
using TUI.Engine.Attributes;
|
||||||
using TUI.Engine.Components;
|
using TUI.Engine.Components;
|
||||||
using TUI.Engine.Theme;
|
using TUI.Engine.Theme;
|
||||||
|
using TUI.Logs;
|
||||||
using static TUI.Engine.Symbols;
|
using static TUI.Engine.Symbols;
|
||||||
|
|
||||||
namespace TUI.Controls.Components;
|
namespace TUI.Controls.Components;
|
||||||
@ -19,12 +20,13 @@ public class PanelComponent : ComponentBase, IComponent
|
|||||||
|
|
||||||
private static void RenderTopLine(StringBuilder builder, Size size, string title)
|
private static void RenderTopLine(StringBuilder builder, Size size, string title)
|
||||||
{
|
{
|
||||||
var halfWidth = (size.Width - title.GetWidth() - (int)Indentation.BorderWidth * 2 -
|
var availableWidth = (size.Width - title.GetWidth() - (int)Indentation.BorderWidth * 2 -
|
||||||
(int)Indentation.Default * 2) / 2;
|
(int)Indentation.Default * 2);
|
||||||
|
var halfWidth = availableWidth/ 2;
|
||||||
builder.Append(Angles.LeftTop);
|
builder.Append(Angles.LeftTop);
|
||||||
builder.Append(Lines.Horizontal.Repeat(halfWidth));
|
builder.Append(Lines.Horizontal.Repeat(halfWidth));
|
||||||
builder.AppendFormat("{0}{1}{0}", Space.Repeat(Convert.ToInt32(Indentation.Default)), title);
|
builder.AppendFormat("{0}{1}{0}", Space.Repeat(Convert.ToInt32(Indentation.Default)), title);
|
||||||
builder.Append(Lines.Horizontal.Repeat(halfWidth + halfWidth % 2));
|
builder.Append(Lines.Horizontal.Repeat(halfWidth + availableWidth % 2));
|
||||||
builder.Append(Angles.RightTop);
|
builder.Append(Angles.RightTop);
|
||||||
builder.Append(LineBreak);
|
builder.Append(LineBreak);
|
||||||
}
|
}
|
||||||
|
20
src/TUI/Logs/Log.cs
Normal file
20
src/TUI/Logs/Log.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
namespace TUI.Logs;
|
||||||
|
|
||||||
|
public static class Log
|
||||||
|
{
|
||||||
|
private static string Now => DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
|
public static void Trace(string message) => Write("🌚", message);
|
||||||
|
public static void Debug(string message) => Write("🦎", message);
|
||||||
|
public static void Info(string message) => Write("🦋", message);
|
||||||
|
public static void Warning(string message) => Write("🍋", message);
|
||||||
|
public static void Error(string message) => Write("🐞", message);
|
||||||
|
public static void Fatal(string message) => Write("💀", message);
|
||||||
|
|
||||||
|
public static void Write(string icon, string message)
|
||||||
|
{
|
||||||
|
// /tld/src/TUI/file.log
|
||||||
|
var file = "file.log";
|
||||||
|
var line = string.Join('|', Now, icon, message);
|
||||||
|
File.AppendAllText(file, line + Environment.NewLine);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using TUI.Logs;
|
||||||
|
|
||||||
namespace TUI.Pages;
|
namespace TUI.Pages;
|
||||||
|
|
||||||
@ -6,17 +7,18 @@ public abstract class PageBase : IPage
|
|||||||
{
|
{
|
||||||
public void Open()
|
public void Open()
|
||||||
{
|
{
|
||||||
Debugger.Log(0, "Event", $"Open page ${GetType().UnderlyingSystemType.Name}\n");
|
Debugger.Log(0, "Event", $"Open page {GetType().UnderlyingSystemType.Name}\n");
|
||||||
|
Log.Trace($"Open page {GetType().UnderlyingSystemType.Name}.");
|
||||||
Bind();
|
Bind();
|
||||||
Initial();
|
Initial();
|
||||||
Render();
|
Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void Load();
|
public abstract void Load();
|
||||||
|
|
||||||
public abstract void Initial();
|
public abstract void Initial();
|
||||||
|
|
||||||
public abstract void Render();
|
public abstract void Render();
|
||||||
|
|
||||||
public abstract void Bind();
|
public abstract void Bind();
|
||||||
}
|
}
|
@ -1,9 +1,12 @@
|
|||||||
using TUI.Pages;
|
using TUI.Logs;
|
||||||
|
using TUI.Pages;
|
||||||
|
|
||||||
|
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.CursorVisible = false;
|
Console.CursorVisible = false;
|
||||||
|
|
||||||
|
Log.Info("Run application.");
|
||||||
|
|
||||||
var welcomePage = WelcomePage.Instance;
|
var welcomePage = WelcomePage.Instance;
|
||||||
welcomePage.Open();
|
welcomePage.Open();
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(500);
|
||||||
@ -21,9 +24,11 @@ do
|
|||||||
{
|
{
|
||||||
case ConsoleKey.Q:
|
case ConsoleKey.Q:
|
||||||
waitCommand = false;
|
waitCommand = false;
|
||||||
|
Log.Trace("Run command quit.");
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.R:
|
case ConsoleKey.R:
|
||||||
key = null;
|
key = null;
|
||||||
|
Log.Trace("Run command load deps.");
|
||||||
currentPage.Load();
|
currentPage.Load();
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.D1:
|
case ConsoleKey.D1:
|
||||||
@ -44,5 +49,6 @@ do
|
|||||||
}
|
}
|
||||||
} while (waitCommand);
|
} while (waitCommand);
|
||||||
|
|
||||||
|
Log.Info("Quit application.");
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.CursorVisible = true;
|
Console.CursorVisible = true;
|
@ -1,6 +1,7 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
using TUI.Domain;
|
using TUI.Domain;
|
||||||
|
using TUI.Logs;
|
||||||
using YamlDotNet.Serialization;
|
using YamlDotNet.Serialization;
|
||||||
using YamlDotNet.Serialization.NamingConventions;
|
using YamlDotNet.Serialization.NamingConventions;
|
||||||
|
|
||||||
@ -9,7 +10,7 @@ namespace TUI.Providers.Dependencies;
|
|||||||
public class DependencyRepository
|
public class DependencyRepository
|
||||||
{
|
{
|
||||||
private DependenciesDto? _dependenciesDto;
|
private DependenciesDto? _dependenciesDto;
|
||||||
|
|
||||||
private DependenciesDto DependenciesDto
|
private DependenciesDto DependenciesDto
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -18,18 +19,18 @@ public class DependencyRepository
|
|||||||
{
|
{
|
||||||
return _dependenciesDto;
|
return _dependenciesDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
var deserializer = new DeserializerBuilder()
|
var deserializer = new DeserializerBuilder()
|
||||||
.WithNamingConvention(UnderscoredNamingConvention.Instance)
|
.WithNamingConvention(UnderscoredNamingConvention.Instance)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
using var sr = new StreamReader("dependencies.yaml");
|
using var sr = new StreamReader("dependencies.yaml");
|
||||||
_dependenciesDto = deserializer.Deserialize<DependenciesDto>(sr.ReadToEnd());
|
_dependenciesDto = deserializer.Deserialize<DependenciesDto>(sr.ReadToEnd());
|
||||||
|
|
||||||
return _dependenciesDto;
|
return _dependenciesDto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Dependency> ReadConventions(string stackName)
|
public IEnumerable<Dependency> ReadConventions(string stackName)
|
||||||
{
|
{
|
||||||
return DependenciesDto.Stacks
|
return DependenciesDto.Stacks
|
||||||
@ -41,70 +42,69 @@ public class DependencyRepository
|
|||||||
return new Dependency(convention.Version, brand);
|
return new Dependency(convention.Version, brand);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Project> ReadProjects(string stackName)
|
public IEnumerable<Project> ReadProjects(string stackName)
|
||||||
{
|
{
|
||||||
var projects = new List<Project>();
|
var projects = new List<Project>();
|
||||||
|
|
||||||
var hubs = DependenciesDto.Stacks
|
var hubs = DependenciesDto.Stacks
|
||||||
.Single(stack => stack.Name == stackName)
|
.Single(stack => stack.Name == stackName)
|
||||||
.Hubs;
|
.Hubs;
|
||||||
|
|
||||||
foreach (var hub in hubs)
|
foreach (var hub in hubs)
|
||||||
{
|
{
|
||||||
projects.AddRange(hub
|
projects.AddRange(hub
|
||||||
.Projects
|
.Projects
|
||||||
.Select(proj => new Project(proj.Id, proj.Name, proj.Tags, new Hub(hub.Origin, hub.Type))));
|
.Select(proj => new Project(proj.Id, proj.Name, proj.Tags, new Hub(hub.Origin, hub.Type))));
|
||||||
}
|
}
|
||||||
|
|
||||||
return projects;
|
return projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IEnumerable<Dependency> ReadActual(Project project)
|
public IEnumerable<Dependency> ReadActual(Project project)
|
||||||
{
|
{
|
||||||
var dependencies = new List<Dependency>();
|
var dependencies = new List<Dependency>();
|
||||||
|
|
||||||
if (project.Hub.Type == "gitlab")
|
if (project.Hub.Type == "gitlab")
|
||||||
{
|
{
|
||||||
var endpoint = GetGitlabEndpoint(project.Hub.Origin, project.Id);
|
var endpoint = GetGitlabEndpoint(project.Hub.Origin, project.Id);
|
||||||
using HttpClient client = new();
|
using HttpClient client = new();
|
||||||
var json = client.GetStringAsync(endpoint).GetAwaiter().GetResult();
|
var json = client.GetStringAsync(endpoint).GetAwaiter().GetResult();
|
||||||
|
|
||||||
var packageJson = JsonSerializer.Deserialize<PackageJson>(json);
|
var packageJson = JsonSerializer.Deserialize<PackageJson>(json);
|
||||||
|
Log.Debug($"Fetch dependencies for project {project.Name}.");
|
||||||
dependencies.AddRange(Map(packageJson?.Dependencies));
|
dependencies.AddRange(Map(packageJson?.Dependencies));
|
||||||
dependencies.AddRange(Map(packageJson?.DevDependencies));
|
dependencies.AddRange(Map(packageJson?.DevDependencies));
|
||||||
dependencies.AddRange(Map(packageJson?.Engines));
|
dependencies.AddRange(Map(packageJson?.Engines));
|
||||||
}
|
}
|
||||||
|
|
||||||
return dependencies;
|
return dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetGitlabEndpoint(string origin, int projectId)
|
private static string GetGitlabEndpoint(string origin, int projectId)
|
||||||
{
|
{
|
||||||
var token = Environment.GetEnvironmentVariable("TLD_GITLAB_PAT");
|
var token = Environment.GetEnvironmentVariable("TLD_GITLAB_PAT");
|
||||||
return $"{origin}/api/v4/projects/{projectId}/repository/files/package.json/raw?" +
|
return $"{origin}/api/v4/projects/{projectId}/repository/files/package.json/raw?" +
|
||||||
$"private_token={token}&ref=dev";
|
$"private_token={token}&ref=dev";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<Dependency> Map(JsonObject? dependencies)
|
private static IEnumerable<Dependency> Map(JsonObject? dependencies)
|
||||||
{
|
{
|
||||||
if (dependencies is null)
|
if (dependencies is null)
|
||||||
{
|
{
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var dependency in dependencies)
|
foreach (var dependency in dependencies)
|
||||||
{
|
{
|
||||||
var actualVersion = dependency.Value?.ToString();
|
var actualVersion = dependency.Value?.ToString();
|
||||||
var brand = new Brand(dependency.Key);
|
var brand = new Brand(dependency.Key);
|
||||||
|
|
||||||
if (actualVersion is null)
|
if (actualVersion is null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield return new Dependency(actualVersion, brand);
|
yield return new Dependency(actualVersion, brand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,10 +116,10 @@ public class DependencyRepository
|
|||||||
// // var endpoint = projectDto.Tags.Have("gitlab") ? GetGitlabEndpoint(projectDto) : projectDto.Repo;
|
// // var endpoint = projectDto.Tags.Have("gitlab") ? GetGitlabEndpoint(projectDto) : projectDto.Repo;
|
||||||
// var endpoint = "";
|
// var endpoint = "";
|
||||||
// if (Packages.TryGetValue(endpoint, out var downloadPackage)) return downloadPackage;
|
// if (Packages.TryGetValue(endpoint, out var downloadPackage)) return downloadPackage;
|
||||||
//
|
//
|
||||||
// using HttpClient client = new();
|
// using HttpClient client = new();
|
||||||
// var json = client.GetStringAsync(endpoint).GetAwaiter().GetResult();
|
// var json = client.GetStringAsync(endpoint).GetAwaiter().GetResult();
|
||||||
//
|
//
|
||||||
// Packages.Add(endpoint, package);
|
// Packages.Add(endpoint, package);
|
||||||
// return package;
|
// return package;
|
||||||
// }
|
// }
|
||||||
|
@ -3,6 +3,7 @@ using TUI.Controls.Components;
|
|||||||
using TUI.Domain;
|
using TUI.Domain;
|
||||||
using TUI.Engine;
|
using TUI.Engine;
|
||||||
using TUI.Engine.Theme;
|
using TUI.Engine.Theme;
|
||||||
|
using TUI.Logs;
|
||||||
using TUI.Providers.Dependencies;
|
using TUI.Providers.Dependencies;
|
||||||
|
|
||||||
namespace TUI.Store;
|
namespace TUI.Store;
|
||||||
@ -26,6 +27,7 @@ public class DependenciesStore
|
|||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
|
Log.Error("Fail load actual deps for project " +project.Name + ". " + ex.Message);
|
||||||
Debugger.Log(0, "error", ex.Message);
|
Debugger.Log(0, "error", ex.Message);
|
||||||
SpeakerComponent.Instance.Shout(Symbols.Error.Error(), $"Fetch failed for project{project.Name}");
|
SpeakerComponent.Instance.Shout(Symbols.Error.Error(), $"Fetch failed for project{project.Name}");
|
||||||
return new List<Dependency>();
|
return new List<Dependency>();
|
||||||
@ -34,10 +36,18 @@ public class DependenciesStore
|
|||||||
|
|
||||||
public void Bind()
|
public void Bind()
|
||||||
{
|
{
|
||||||
SpeakerComponent.Instance.Shout("🤔", "Prepare javascript conventions");
|
try
|
||||||
ConventionDependencies = Repository.ReadConventions("javascript");
|
{
|
||||||
|
SpeakerComponent.Instance.Shout("🤔", "Prepare javascript conventions");
|
||||||
|
ConventionDependencies = Repository.ReadConventions("javascript");
|
||||||
|
|
||||||
SpeakerComponent.Instance.Shout("🤩", "Prepare javascript projects");
|
SpeakerComponent.Instance.Shout("🤩", "Prepare javascript projects");
|
||||||
Projects = Repository.ReadProjects("javascript");
|
Projects = Repository.ReadProjects("javascript");
|
||||||
|
Log.Info("Loading settings.");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error("Fail Loading settings. " + ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user