Skip to content

Commit

Permalink
📝 Chore(i18n): Available to execute XamlMLE through cheese
Browse files Browse the repository at this point in the history
  • Loading branch information
Dynesshely committed Jun 26, 2024
1 parent 75ebf40 commit 601f75b
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 77 deletions.
46 changes: 46 additions & 0 deletions .cheese/scripts/i18n.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Diagnostics;
using Common.BasicHelper.Core.Shell;
using Common.BasicHelper.Utils.Extensions;
using Spectre.Console;

var utilsToLaunch = AnsiConsole.Prompt(
new MultiSelectionPrompt<string>()
.Title("Which [green]i18n utils[/] are to be launched ?")
.NotRequired()
.PageSize(10)
.MoreChoicesText("[grey](Move up and down to reveal more utils)[/]")
.InstructionsText("[grey](Press [blue]<space>[/] to toggle a i18n util, [green]<enter>[/] to accept)[/]")
.AddChoices(
new[] {
"KitX Dashboard (XamlMLE)"
}
)
);

var baseDir = PathHelper.Instance.BaseSlnDir;

foreach (var util in utilsToLaunch)
{
AnsiConsole.MarkupLine($"@ Launching {util}");

switch (util)
{
case "KitX Dashboard (XamlMLE)":
var xamlMleDir = $"{baseDir}/KitX SDK/Reference/XamlMultiLanguageEditor".GetFullPath();
var scriptPath = $"{xamlMleDir}/run.ps1".GetFullPath();

var args = new StringBuilder()
.Append($" -WorkingDirectory \"{xamlMleDir}\"")
.Append($" -Command \"& '{scriptPath}'\"")
.ToString()
;

Console.WriteLine(args);

var result = "pwsh".ExecuteAsCommand(args: args, findInPath: true);

Console.WriteLine(result);

break;
}
}
155 changes: 78 additions & 77 deletions .cheese/scripts/publish.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
AnsiConsole.Write(
new FigletText("KitX Publisher")
.Centered()
.Color(Color.Blue));
.Color(Color.Blue)
);

PathHelper.Instance.AssertInSlnDirectory(out _);

Expand Down Expand Up @@ -42,111 +43,111 @@

const string prompt = "[white]>>>[/]";

AnsiConsole.Progress()
.Columns(new ProgressColumn[]
AnsiConsole
.Progress()
.Columns(
new ProgressColumn[]
{
new TaskDescriptionColumn(),
new ProgressBarColumn(),
new PercentageColumn(),
// new RemainingTimeColumn(),
new SpinnerColumn(),
})
.Start(ctx =>
{
var genTask = ctx.AddTask("[green]Publishing[/]");
var packTask = ctx.AddTask("[blue]Packing[/]");
{
AnsiConsole.Write(new Rule($"[blue]Begin Generating[/]"));
AnsiConsole.MarkupLine($"{prompt} Found {files.Length} profiles");
AnsiConsole.Markup($"{prompt} Generating logs at: \"{Path.GetRelativePath(baseDir, log)}\"");
AnsiConsole.WriteLine();
packTask.IsIndeterminate = true;
}
)
.Start(ctx =>
{
var genTask = ctx.AddTask("[green]Publishing[/]");
var packTask = ctx.AddTask("[blue]Packing[/]");
foreach (var item in files)
{
var index = executingThreadIndex++;
var filename = Path.GetFileName(item);
const string cmd = "dotnet";
var arg = $"publish \"{(path + "/KitX.Dashboard.csproj").GetFullPath()}\" \"/p:PublishProfile={item}\"";
AnsiConsole.MarkupLine($"{prompt} 📄 [white]{filename}[/]: [gray]{cmd} {arg}[/]");
{
AnsiConsole.Write(new Rule($"[blue]Begin Generating[/]"));
var process = new Process();
var psi = new ProcessStartInfo()
{
FileName = cmd,
Arguments = arg,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
process.StartInfo = psi;
process.Start();
AnsiConsole.MarkupLine($"{prompt} Found {files.Length} profiles");
AnsiConsole.Markup($"{prompt} Generating logs at: \"{Path.GetRelativePath(baseDir, log)}\"");
AnsiConsole.WriteLine();
while (!process.StandardOutput.EndOfStream)
{
var line = process.StandardOutput.ReadLine();
packTask.IsIndeterminate = true;
File.AppendAllText(log, Environment.NewLine + line);
}
foreach (var item in files)
{
var index = executingThreadIndex++;
var filename = Path.GetFileName(item);
const string cmd = "dotnet";
var arg = $"publish \"{(path + "/KitX.Dashboard.csproj").GetFullPath()}\" \"/p:PublishProfile={item}\"";
// Thread.Sleep(700);
AnsiConsole.MarkupLine($"{prompt} 📄 [white]{filename}[/]: [gray]{cmd} {arg}[/]");
process.WaitForExit();
var process = new Process();
var psi = new ProcessStartInfo()
{
FileName = cmd,
Arguments = arg,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
process.StartInfo = psi;
process.Start();
while (!process.StandardOutput.EndOfStream)
{
var line = process.StandardOutput.ReadLine();
++finishedThreads;
File.AppendAllText(log, Environment.NewLine + line);
}
genTask.Increment((1.0 / files.Length) * 100);
process.WaitForExit();
AnsiConsole.MarkupLine($"{prompt} Finished task_{index}, still {files.Length - finishedThreads} tasks waiting");
++finishedThreads;
AnsiConsole.Write(new Rule($"[red]Finished task-{index}[/]"));
}
genTask.Increment((1.0 / files.Length) * 100);
AnsiConsole.MarkupLine($"{prompt} All tasks done.");
AnsiConsole.MarkupLine($"{prompt} Finished task_{index}, still {files.Length - finishedThreads} tasks waiting");
genTask.StopTask();
AnsiConsole.Write(new Rule($"[red]Finished task-{index}[/]"));
}
{
AnsiConsole.MarkupLine($"{prompt} Begin packing.");
AnsiConsole.MarkupLine($"{prompt} All tasks done.");
packTask.IsIndeterminate = false;
genTask.StopTask();
}
var ignoredDirectories = JsonSerializer.Deserialize<List<string>>(File.ReadAllText(packIgnore));
{
AnsiConsole.MarkupLine($"{prompt} Begin packing.");
var folders = new DirectoryInfo(publishDir).GetDirectories().ToList();
packTask.IsIndeterminate = false;
folders.RemoveAll(f => ignoredDirectories.Contains(f.Name));
var ignoredDirectories = JsonSerializer.Deserialize<List<string>>(File.ReadAllText(packIgnore));
foreach (var folder in folders)
{
var name = folder.Name;
var zipFileName = $"{publishDir}/{name}.zip";
var folders = new DirectoryInfo(publishDir).GetDirectories().ToList();
AnsiConsole.MarkupLine($"{prompt} Packing 📂 [yellow]{name}[/]");
folders.RemoveAll(f => ignoredDirectories.Contains(f.Name));
if (File.Exists(zipFileName))
File.Delete(zipFileName);
foreach (var folder in folders)
{
var name = folder.Name;
var zipFileName = $"{publishDir}/{name}.zip";
ZipFile.CreateFromDirectory(
folder.FullName,
zipFileName,
CompressionLevel.SmallestSize,
true
);
AnsiConsole.MarkupLine($"{prompt} Packing 📂 [yellow]{name}[/]");
AnsiConsole.MarkupLine($" Packed to {Path.GetRelativePath(baseDir, zipFileName)}");
if (File.Exists(zipFileName))
File.Delete(zipFileName);
packTask.Increment((1.0 / folders.Count) * 100);
}
ZipFile.CreateFromDirectory(
folder.FullName,
zipFileName,
CompressionLevel.SmallestSize,
true
);
AnsiConsole.MarkupLine($"{prompt} Packing done.");
AnsiConsole.MarkupLine($" Packed to {Path.GetRelativePath(baseDir, zipFileName)}");
packTask.StopTask();
packTask.Increment((1.0 / folders.Count) * 100);
}
});
AnsiConsole.MarkupLine($"{prompt} Packing done.");
packTask.StopTask();
}
});

0 comments on commit 601f75b

Please sign in to comment.