Skip to content

Commit

Permalink
v0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
CypherPotato committed Apr 10, 2024
1 parent 20a7873 commit 7e9367a
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 24 deletions.
5 changes: 3 additions & 2 deletions tool/Cascadium-Utility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
<AssemblyName>cascadium</AssemblyName>
<InvariantGlobalization>true</InvariantGlobalization>

<AssemblyVersion>0.1.2.4</AssemblyVersion>
<FileVersion>0.1.2.4</FileVersion>
<AssemblyVersion>0.4</AssemblyVersion>
<FileVersion>0.4</FileVersion>
<RootNamespace>cascadiumtool</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CypherPotato.LightJson" Version="0.5.6" />
<PackageReference Include="Spectre.Console" Version="0.48.0" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 4 additions & 3 deletions tool/CommandLineParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Spectre.Console;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -194,11 +195,11 @@ public static void PrintHelp
string part = parts[i];
if (i == 0)
{
Console.WriteLine("{0," + startTrailingSpace + "}{1,-" + (biggestOptionLength + optionGutter) + "}{2}", "", opKp.opText, part);
AnsiConsole.MarkupLine("{0," + startTrailingSpace + "}[grey63]{1,-" + (biggestOptionLength + optionGutter) + "}[/][silver]{2}[/]", "", opKp.opText, part);
}
else
{
Console.WriteLine("{0}{1}", new String(' ', biggestOptionLength + optionGutter + startTrailingSpace), part);
AnsiConsole.MarkupLine("{0}[silver]{1}[/]", new String(' ', biggestOptionLength + optionGutter + startTrailingSpace), part);
}
}

Expand Down
22 changes: 13 additions & 9 deletions tool/Compiler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Cascadium;
using Microsoft.VisualBasic;
using Spectre.Console;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down Expand Up @@ -129,11 +130,13 @@ await Parallel.ForEachAsync(inputFiles,
}
catch (CascadiumException cex)
{
Console.WriteLine($"error at file {file.Substring(smallInputLength + 1)}, line {cex.Line}, col. {cex.Column}:");
Console.WriteLine();
Console.WriteLine($"\t{cex.LineText}");
Console.WriteLine($"\t{new string(' ', cex.Column - 1)}^");
Console.WriteLine($"\t{cex.Message}");
string linePadText = cex.Line + ".";
AnsiConsole.MarkupLine($"[grey]cascadium[/] [silver]{DateTime.Now:T}[/] [indianred_1]error[/] at file [white]{file.Substring(smallInputLength + 1)}[/], line [deepskyblue3_1]{cex.Line}[/], col. [deepskyblue3_1]{cex.Column}[/]:");
AnsiConsole.WriteLine();
AnsiConsole.MarkupLine($"\t[deepskyblue3_1]{linePadText}[/] [silver]{cex.LineText}[/]");
AnsiConsole.MarkupLine($"\t[lightpink4]{new string(' ', cex.Column + linePadText.Length)}^[/]");
AnsiConsole.MarkupLine($"\t[mistyrose3]{cex.Message}[/]");
AnsiConsole.WriteLine();
errorCanceller.Cancel();
}

Expand All @@ -145,17 +148,18 @@ await Parallel.ForEachAsync(inputFiles,
;
}

string css = string.Join(options.Pretty ? "\n" : "", resultCss);
if (outputFile != null)
{
string css = string.Join(options.Pretty ? "\n" : "", resultCss);
{
File.WriteAllText(outputFile, css);

compiledLength = new FileInfo(outputFile).Length;
Log.Info($"{inputFiles.Count} file(s) -> {Path.GetFileName(args.OutputFile)} ({PathUtils.FileSize(compiledLength)}) in {sw.ElapsedMilliseconds:N0}ms");
if (!Program.IsWatch)
Log.Info($"{inputFiles.Count} file(s) -> {Path.GetFileName(args.OutputFile)} ({PathUtils.FileSize(compiledLength)}) in {sw.ElapsedMilliseconds:N0}ms");
}
else
{
Console.Write(resultCss.ToString());
Console.Write(css);
}
}
}
Expand Down
17 changes: 15 additions & 2 deletions tool/Log.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Spectre.Console;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -14,6 +15,7 @@ public static int ErrorKill(string message)
Write("error", message);
return 1;
}

public static int Info(string message, bool force = false)
{
if (!force && !LoggingEnabled) return 0;
Expand All @@ -23,6 +25,17 @@ public static int Info(string message, bool force = false)

private static void Write(string level, string message)
{
Console.WriteLine("{0,-17} {1}", "cascadium [" + level + "]", message);
if (level == "error")
{
AnsiConsole.MarkupLine($"[grey]cascadium[/] [silver]{DateTime.Now:T}[/] [indianred_1]error[/] [white]{message}[/]");
}
else if (level == "info")
{
AnsiConsole.MarkupLine($"[grey]cascadium[/] [silver]{DateTime.Now:T}[/] [darkcyan]info[/] [white]{message}[/]");
}
else if (level == "warn")
{
AnsiConsole.MarkupLine($"[grey]cascadium[/] [silver]{DateTime.Now:T}[/] [darkgoldenrod]info[/] [white]{message}[/]");
}
}
}
4 changes: 3 additions & 1 deletion tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ namespace cascadiumtool;

internal class Program
{
public const string VersionLabel = "v.0.3";
public const string VersionLabel = "v.0.4";
public static string CurrentDirectory { get; set; } = Directory.GetCurrentDirectory();
public static bool HasRootConfiguration { get; private set; }
public static JsonCssCompilerOptions? CompilerOptions { get; set; }
public static Dictionary<string, string> CompilerCache { get; set; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
public static bool IsWatch { get; set; } = false;

[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CommandLineArguments))]
static async Task<int> Main(string[] args)
Expand Down Expand Up @@ -43,6 +44,7 @@ public static async Task<int> RunParsed(CommandLineArguments args)

if (args.Watch)
{
IsWatch = true;
return await Watcher.Watch(args);
}
else
Expand Down
27 changes: 21 additions & 6 deletions tool/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal static class Watcher
private static FileSystemWatcher fsWatcher = new FileSystemWatcher();
private static CommandLineArguments watchArgs = null!;
private static string[] watchingDirectories = Array.Empty<string>();
private static bool IsCompilingFile = false;
private static bool IsRunningCompilation = false;

public static async Task<int> Watch(CommandLineArguments args)
{
Expand Down Expand Up @@ -54,7 +54,12 @@ public static async Task<int> Watch(CommandLineArguments args)

fsWatcher.Path = smallestPath!;
fsWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime | NotifyFilters.FileName;

fsWatcher.Changed += FsWatcher_Changed;
fsWatcher.Renamed += FsWatcher_Changed;
fsWatcher.Deleted += FsWatcher_Changed;
fsWatcher.Created += FsWatcher_Changed;

fsWatcher.Filter = "*.*";
fsWatcher.IncludeSubdirectories = true;
fsWatcher.EnableRaisingEvents = true;
Expand All @@ -69,12 +74,12 @@ public static async Task<int> Watch(CommandLineArguments args)

private static async void FsWatcher_Changed(Object sender, FileSystemEventArgs e)
{
if (IsCompilingFile)
if (IsRunningCompilation)
{
return;
}

IsCompilingFile = true;
IsRunningCompilation = true;

string outFile = PathUtils.ResolvePath(watchArgs.OutputFile);
if (outFile == e.FullPath)
Expand All @@ -99,9 +104,19 @@ private static async void FsWatcher_Changed(Object sender, FileSystemEventArgs e

Program.CompilerCache.Remove(file);

if (e.ChangeType == WatcherChangeTypes.Renamed
|| e.ChangeType == WatcherChangeTypes.Deleted
|| e.ChangeType == WatcherChangeTypes.Created)
{
Log.Info($"Directory structure modified. Clearing cache.");
Program.CompilerCache.Clear();
}

try
{
Thread.Sleep(300); // prevent the below error giving time to the time to write
await Task.Delay(100); // prevent the below error giving time to the time to write
Log.Info($"Detected {e.ChangeType} on {Path.GetFileName(file)}, building...");

await Compiler.RunCompiler(watchArgs);
;
}
Expand All @@ -112,8 +127,8 @@ private static async void FsWatcher_Changed(Object sender, FileSystemEventArgs e
}
finally
{
IsCompilingFile = false;
Thread.Sleep(150);
await Task.Delay(400);
IsRunningCompilation = false;
}
}
}
2 changes: 1 addition & 1 deletion tool/etc/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ dotnet publish "%~dp0/../Cascadium-Utility.csproj" --nologo ^
-p:PublishReadyToRun=true ^
-p:PublishTrimmed=true ^
-p:PublishSingleFile=true ^
-o "%~dp0bin/Build/cascadium-v0.3-%NAME%/"
-o "%~dp0bin/Build/cascadium-v0.4-%NAME%/"

0 comments on commit 7e9367a

Please sign in to comment.