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
|
||||
*.DS_Store
|
||||
**/*.Production.json
|
||||
Logs/
|
||||
**/*.log
|
@ -42,10 +42,10 @@ public static class Extensions
|
||||
|
||||
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 minor = Convert.ToInt32(version[1]);
|
||||
var patch = Convert.ToInt32(version[2].Split('-')[0]);
|
||||
return new Version(major, minor, patch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using TUI.Engine;
|
||||
using TUI.Engine.Attributes;
|
||||
using TUI.Engine.Components;
|
||||
using TUI.Engine.Theme;
|
||||
using TUI.Logs;
|
||||
using static TUI.Engine.Symbols;
|
||||
|
||||
namespace TUI.Controls.Components;
|
||||
@ -19,12 +20,13 @@ public class PanelComponent : ComponentBase, IComponent
|
||||
|
||||
private static void RenderTopLine(StringBuilder builder, Size size, string title)
|
||||
{
|
||||
var halfWidth = (size.Width - title.GetWidth() - (int)Indentation.BorderWidth * 2 -
|
||||
(int)Indentation.Default * 2) / 2;
|
||||
var availableWidth = (size.Width - title.GetWidth() - (int)Indentation.BorderWidth * 2 -
|
||||
(int)Indentation.Default * 2);
|
||||
var halfWidth = availableWidth/ 2;
|
||||
builder.Append(Angles.LeftTop);
|
||||
builder.Append(Lines.Horizontal.Repeat(halfWidth));
|
||||
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(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 TUI.Logs;
|
||||
|
||||
namespace TUI.Pages;
|
||||
|
||||
@ -6,17 +7,18 @@ public abstract class PageBase : IPage
|
||||
{
|
||||
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();
|
||||
Initial();
|
||||
Render();
|
||||
}
|
||||
|
||||
|
||||
public abstract void Load();
|
||||
|
||||
|
||||
public abstract void Initial();
|
||||
|
||||
|
||||
public abstract void Render();
|
||||
|
||||
|
||||
public abstract void Bind();
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
using TUI.Pages;
|
||||
using TUI.Logs;
|
||||
using TUI.Pages;
|
||||
|
||||
|
||||
Console.Clear();
|
||||
Console.CursorVisible = false;
|
||||
|
||||
Log.Info("Run application.");
|
||||
|
||||
var welcomePage = WelcomePage.Instance;
|
||||
welcomePage.Open();
|
||||
Thread.Sleep(500);
|
||||
@ -21,9 +24,11 @@ do
|
||||
{
|
||||
case ConsoleKey.Q:
|
||||
waitCommand = false;
|
||||
Log.Trace("Run command quit.");
|
||||
break;
|
||||
case ConsoleKey.R:
|
||||
key = null;
|
||||
Log.Trace("Run command load deps.");
|
||||
currentPage.Load();
|
||||
break;
|
||||
case ConsoleKey.D1:
|
||||
@ -44,5 +49,6 @@ do
|
||||
}
|
||||
} while (waitCommand);
|
||||
|
||||
Log.Info("Quit application.");
|
||||
Console.Clear();
|
||||
Console.CursorVisible = true;
|
@ -1,6 +1,7 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using TUI.Domain;
|
||||
using TUI.Logs;
|
||||
using YamlDotNet.Serialization;
|
||||
using YamlDotNet.Serialization.NamingConventions;
|
||||
|
||||
@ -9,7 +10,7 @@ namespace TUI.Providers.Dependencies;
|
||||
public class DependencyRepository
|
||||
{
|
||||
private DependenciesDto? _dependenciesDto;
|
||||
|
||||
|
||||
private DependenciesDto DependenciesDto
|
||||
{
|
||||
get
|
||||
@ -18,18 +19,18 @@ public class DependencyRepository
|
||||
{
|
||||
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> ReadConventions(string stackName)
|
||||
{
|
||||
return DependenciesDto.Stacks
|
||||
@ -41,70 +42,69 @@ public class DependencyRepository
|
||||
return new Dependency(convention.Version, brand);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<Project> ReadProjects(string stackName)
|
||||
{
|
||||
var projects = new List<Project>();
|
||||
|
||||
|
||||
var hubs = DependenciesDto.Stacks
|
||||
.Single(stack => stack.Name == stackName)
|
||||
.Hubs;
|
||||
|
||||
|
||||
foreach (var hub in hubs)
|
||||
{
|
||||
projects.AddRange(hub
|
||||
.Projects
|
||||
.Select(proj => new Project(proj.Id, proj.Name, proj.Tags, new Hub(hub.Origin, hub.Type))));
|
||||
}
|
||||
|
||||
|
||||
return projects;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public IEnumerable<Dependency> ReadActual(Project project)
|
||||
{
|
||||
var dependencies = new List<Dependency>();
|
||||
|
||||
|
||||
if (project.Hub.Type == "gitlab")
|
||||
{
|
||||
var endpoint = GetGitlabEndpoint(project.Hub.Origin, project.Id);
|
||||
using HttpClient client = new();
|
||||
var json = client.GetStringAsync(endpoint).GetAwaiter().GetResult();
|
||||
|
||||
var packageJson = JsonSerializer.Deserialize<PackageJson>(json);
|
||||
|
||||
Log.Debug($"Fetch dependencies for project {project.Name}.");
|
||||
dependencies.AddRange(Map(packageJson?.Dependencies));
|
||||
dependencies.AddRange(Map(packageJson?.DevDependencies));
|
||||
dependencies.AddRange(Map(packageJson?.Engines));
|
||||
}
|
||||
|
||||
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
|
||||
private static string GetGitlabEndpoint(string origin, int projectId)
|
||||
{
|
||||
var token = Environment.GetEnvironmentVariable("TLD_GITLAB_PAT");
|
||||
return $"{origin}/api/v4/projects/{projectId}/repository/files/package.json/raw?" +
|
||||
$"private_token={token}&ref=dev";
|
||||
}
|
||||
|
||||
|
||||
private static IEnumerable<Dependency> Map(JsonObject? dependencies)
|
||||
{
|
||||
if (dependencies is null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
|
||||
foreach (var dependency in dependencies)
|
||||
{
|
||||
var actualVersion = dependency.Value?.ToString();
|
||||
var brand = new Brand(dependency.Key);
|
||||
|
||||
|
||||
if (actualVersion is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
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 = "";
|
||||
// if (Packages.TryGetValue(endpoint, out var downloadPackage)) return downloadPackage;
|
||||
//
|
||||
//
|
||||
// using HttpClient client = new();
|
||||
// var json = client.GetStringAsync(endpoint).GetAwaiter().GetResult();
|
||||
//
|
||||
//
|
||||
// Packages.Add(endpoint, package);
|
||||
// return package;
|
||||
// }
|
||||
|
@ -3,6 +3,7 @@ using TUI.Controls.Components;
|
||||
using TUI.Domain;
|
||||
using TUI.Engine;
|
||||
using TUI.Engine.Theme;
|
||||
using TUI.Logs;
|
||||
using TUI.Providers.Dependencies;
|
||||
|
||||
namespace TUI.Store;
|
||||
@ -26,6 +27,7 @@ public class DependenciesStore
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Log.Error("Fail load actual deps for project " +project.Name + ". " + ex.Message);
|
||||
Debugger.Log(0, "error", ex.Message);
|
||||
SpeakerComponent.Instance.Shout(Symbols.Error.Error(), $"Fetch failed for project{project.Name}");
|
||||
return new List<Dependency>();
|
||||
@ -34,10 +36,18 @@ public class DependenciesStore
|
||||
|
||||
public void Bind()
|
||||
{
|
||||
SpeakerComponent.Instance.Shout("🤔", "Prepare javascript conventions");
|
||||
ConventionDependencies = Repository.ReadConventions("javascript");
|
||||
try
|
||||
{
|
||||
SpeakerComponent.Instance.Shout("🤔", "Prepare javascript conventions");
|
||||
ConventionDependencies = Repository.ReadConventions("javascript");
|
||||
|
||||
SpeakerComponent.Instance.Shout("🤩", "Prepare javascript projects");
|
||||
Projects = Repository.ReadProjects("javascript");
|
||||
SpeakerComponent.Instance.Shout("🤩", "Prepare javascript projects");
|
||||
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