diff --git a/src/IntelliTect.Coalesce.CodeGeneration/Analysis/MsBuild/Targets/build/IntelliTect.Coalesce.CodeGeneration.Analysis.MsBuild.targets b/src/IntelliTect.Coalesce.CodeGeneration/Analysis/MsBuild/Targets/build/IntelliTect.Coalesce.CodeGeneration.Analysis.MsBuild.targets
index f15cd15f3..f02e88bc7 100644
--- a/src/IntelliTect.Coalesce.CodeGeneration/Analysis/MsBuild/Targets/build/IntelliTect.Coalesce.CodeGeneration.Analysis.MsBuild.targets
+++ b/src/IntelliTect.Coalesce.CodeGeneration/Analysis/MsBuild/Targets/build/IntelliTect.Coalesce.CodeGeneration.Analysis.MsBuild.targets
@@ -39,7 +39,7 @@ Outputs the Project Information needed for CodeGeneration to a file.
-
+
diff --git a/src/IntelliTect.Coalesce.CodeGeneration/Analysis/NpmDependencyAnalayzer.cs b/src/IntelliTect.Coalesce.CodeGeneration/Analysis/NpmDependencyAnalayzer.cs
new file mode 100644
index 000000000..1d38d4beb
--- /dev/null
+++ b/src/IntelliTect.Coalesce.CodeGeneration/Analysis/NpmDependencyAnalayzer.cs
@@ -0,0 +1,42 @@
+using IntelliTect.Coalesce.CodeGeneration.Generation;
+using Microsoft.Extensions.Logging;
+using System;
+using System.IO;
+using System.Text.Json;
+using System.Threading.Tasks;
+
+#nullable enable
+
+namespace IntelliTect.Coalesce.CodeGeneration.Analysis
+{
+ internal class NpmDependencyAnalayzer(GenerationContext context, ILogger logger)
+ {
+ public async Task GetNpmPackageVersion(string packageName)
+ {
+ var packageLockPath = Path.Combine(context.WebProject.ProjectPath, "package-lock.json");
+ var fileInfo = new FileInfo(packageLockPath);
+ if (!fileInfo.Exists)
+ {
+ logger.LogDebug("Unable to determine installed coalesce-vue version: package-lock.json not found.");
+ return null;
+ }
+
+ try
+ {
+ var content = await JsonSerializer.DeserializeAsync(fileInfo.OpenRead());
+ var version = content
+ .GetProperty("packages")
+ .GetProperty("node_modules/" + packageName)
+ .GetProperty("version")
+ .GetString();
+
+ return version;
+ }
+ catch (Exception ex)
+ {
+ logger.LogDebug(ex, "Unable to determine installed coalesce-vue version");
+ return null;
+ }
+ }
+ }
+}
diff --git a/src/IntelliTect.Coalesce.CodeGeneration/Generation/GenerationExecutor.cs b/src/IntelliTect.Coalesce.CodeGeneration/Generation/GenerationExecutor.cs
index b10feb273..087d317ff 100644
--- a/src/IntelliTect.Coalesce.CodeGeneration/Generation/GenerationExecutor.cs
+++ b/src/IntelliTect.Coalesce.CodeGeneration/Generation/GenerationExecutor.cs
@@ -1,23 +1,19 @@
using IntelliTect.Coalesce.CodeGeneration.Analysis;
using IntelliTect.Coalesce.CodeGeneration.Analysis.Base;
-using IntelliTect.Coalesce.CodeGeneration.Analysis.MsBuild;
using IntelliTect.Coalesce.CodeGeneration.Analysis.Roslyn;
using IntelliTect.Coalesce.CodeGeneration.Configuration;
using IntelliTect.Coalesce.CodeGeneration.Templating.Resolution;
using IntelliTect.Coalesce.CodeGeneration.Utilities;
using IntelliTect.Coalesce.TypeDefinition;
using IntelliTect.Coalesce.Validation;
-using Microsoft.DotNet.Cli.Utils;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
-using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
-using System.Threading;
using System.Threading.Tasks;
namespace IntelliTect.Coalesce.CodeGeneration.Generation
@@ -42,6 +38,7 @@ public GenerationExecutor(CoalesceConfiguration config, LogLevel logLevel)
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
+ services.AddSingleton();
services.AddTransient();
ServiceProvider = services.BuildServiceProvider();
}
@@ -93,6 +90,7 @@ public async Task GenerateAsync(Type rootGenerator)
await LoadProjects(Logger, genContext);
var locator = genContext.DataProject.TypeLocator as RoslynTypeLocator;
+ var npmPackageVersionTask = ServiceProvider.GetRequiredService().GetNpmPackageVersion("coalesce-vue");
Logger.LogInformation("Gathering Types");
var types = locator.GetAllTypes();
@@ -155,6 +153,23 @@ public async Task GenerateAsync(Type rootGenerator)
Logger.LogInformation("Generation Complete");
+
+ var generatorVersion = GetCodeGenVersion();
+ var npmPackageVersion = await npmPackageVersionTask;
+ if (npmPackageVersion is not null && npmPackageVersion != generatorVersion)
+ {
+ Logger.LogWarning($"Running Coalesce CLI {generatorVersion}, but NPM package `coalesce-vue` version is {npmPackageVersion}");
+ }
+ }
+
+ private string GetCodeGenVersion()
+ {
+ var generatorAssembly = Assembly.GetEntryAssembly();
+ return FileVersionInfo
+ .GetVersionInfo(generatorAssembly.Location)
+ .ProductVersion
+ // SourceLink will append the commit hash to the version, using '+' as a delimiter.
+ .Split('+').First();
}
private async Task LoadProjects(ILogger logger, GenerationContext genContext)
@@ -196,12 +211,7 @@ async Task TryLoadProject(ProjectConfiguration config)
.GroupBy(r => new { r.Name, r.Version }).Select(g => g.First())
.ToList();
- var generationVersion = FileVersionInfo
- .GetVersionInfo(Assembly.GetExecutingAssembly().Location)
- .ProductVersion
- // SourceLink will append the commit hash to the version, using '+' as a delimiter.
- .Split('+').First();
-
+ var generationVersion = GetCodeGenVersion();
foreach (var coalescePkg in coalescePackages)
{
if (coalescePkg.Version != generationVersion)
diff --git a/src/IntelliTect.Coalesce.CodeGeneration/Utilities/SimpleConsoleLogger.cs b/src/IntelliTect.Coalesce.CodeGeneration/Utilities/SimpleConsoleLogger.cs
index 70104c45d..e0d78d910 100644
--- a/src/IntelliTect.Coalesce.CodeGeneration/Utilities/SimpleConsoleLogger.cs
+++ b/src/IntelliTect.Coalesce.CodeGeneration/Utilities/SimpleConsoleLogger.cs
@@ -60,8 +60,16 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except
Console.Write($"{ApplicationTimer.Stopwatch.ElapsedMilliseconds / 1000d:0.000}");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write("] ");
- Console.ResetColor();
+ if (logLevel == LogLevel.Information)
+ {
+ Console.ResetColor();
+ }
+ else
+ {
+ Console.ForegroundColor = colorLevelMap[logLevel];
+ }
Console.WriteLine(formatter(state, exception));
+ Console.ResetColor();
Console.Out.Flush();
}
}