-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #144 check dependency versions when running codegen
- Loading branch information
Showing
4 changed files
with
72 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/IntelliTect.Coalesce.CodeGeneration/Analysis/NpmDependencyAnalayzer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NpmDependencyAnalayzer> logger) | ||
{ | ||
public async Task<string?> 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<JsonElement>(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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters