From 34ef6dbe70b2b855f7a132e50c8e8f079b96b7f6 Mon Sep 17 00:00:00 2001 From: Kouji Matsui Date: Tue, 15 Oct 2024 14:10:27 +0900 Subject: [PATCH] Updated package. --- .../RelaxVersioner.Core.Tests.csproj | 1 + .../RelaxVersioner.Core.csproj | 3 +- .../Writers/NpmReplaceProvider.cs | 86 +++++++++++++++++++ .../RelaxVersioner.Tasks.csproj | 2 +- RelaxVersioner/RelaxVersioner.csproj | 2 +- rv-cli/rv-cli.csproj | 4 +- 6 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 RelaxVersioner.Core/Writers/NpmReplaceProvider.cs diff --git a/RelaxVersioner.Core.Tests/RelaxVersioner.Core.Tests.csproj b/RelaxVersioner.Core.Tests/RelaxVersioner.Core.Tests.csproj index 8921292..41393f2 100644 --- a/RelaxVersioner.Core.Tests/RelaxVersioner.Core.Tests.csproj +++ b/RelaxVersioner.Core.Tests/RelaxVersioner.Core.Tests.csproj @@ -11,6 +11,7 @@ + diff --git a/RelaxVersioner.Core/RelaxVersioner.Core.csproj b/RelaxVersioner.Core/RelaxVersioner.Core.csproj index f6b3494..38ca466 100644 --- a/RelaxVersioner.Core/RelaxVersioner.Core.csproj +++ b/RelaxVersioner.Core/RelaxVersioner.Core.csproj @@ -14,9 +14,10 @@ + + Include="RelaxVersioner" Version="3.7.0" PrivateAssets="all" /> diff --git a/RelaxVersioner.Core/Writers/NpmReplaceProvider.cs b/RelaxVersioner.Core/Writers/NpmReplaceProvider.cs new file mode 100644 index 0000000..9151763 --- /dev/null +++ b/RelaxVersioner.Core/Writers/NpmReplaceProvider.cs @@ -0,0 +1,86 @@ +//////////////////////////////////////////////////////////////////////////////////////// +// +// RelaxVersioner - Git tag/branch based, full-automatic version generator. +// Copyright (c) Kouji Matsui (@kozy_kekyo, @kekyo@mastodon.cloud) +// +// Licensed under Apache-v2: https://opensource.org/licenses/Apache-2.0 +// +//////////////////////////////////////////////////////////////////////////////////////// + +#nullable enable + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Text; +using NamingFormatter; +using Newtonsoft.Json; + +namespace RelaxVersioner.Writers; + +internal sealed class NpmReplaceProvider : WriteProviderBase +{ + public override string Language => "NPM"; + + public override void Write( + ProcessorContext context, + Dictionary keyValues, + DateTimeOffset generated) + { + void Replace(TextReader tr, TextWriter tw) + { + var jr = new JsonTextReader(tr); + + + + while (true) + { + var line = tr.ReadLine(); + if (line == null) + { + break; + } + + var formattedLine = Named.Format( + CultureInfo.InvariantCulture, + line, + keyValues, + key => string.Empty, + new(context.BracketStart, context.BracketEnd)); + + tw.WriteLine(formattedLine); + } + + tw.Flush(); + } + + if (!string.IsNullOrWhiteSpace(context.OutputPath)) + { + if (context.IsDryRun) + { + return; + } + + Processor.WriteSafeTransacted( + context.OutputPath, + stream => + { + using var tr = context.ReplaceInputPath is { } rip ? + new StreamReader(rip, Encoding.UTF8, true) : + Console.In; + var tw = new StreamWriter(stream, Encoding.UTF8); + + Replace(tr, tw); + }); + } + else + { + using var tr = context.ReplaceInputPath is { } rip ? + new StreamReader(rip, Encoding.UTF8, true) : + Console.In; + Replace(tr, Console.Out); + } + } +} diff --git a/RelaxVersioner.Tasks/RelaxVersioner.Tasks.csproj b/RelaxVersioner.Tasks/RelaxVersioner.Tasks.csproj index b1a5e97..9ee4507 100644 --- a/RelaxVersioner.Tasks/RelaxVersioner.Tasks.csproj +++ b/RelaxVersioner.Tasks/RelaxVersioner.Tasks.csproj @@ -29,7 +29,7 @@ + Include="RelaxVersioner" Version="3.7.0" PrivateAssets="all" /> diff --git a/RelaxVersioner/RelaxVersioner.csproj b/RelaxVersioner/RelaxVersioner.csproj index fe6b6e2..82214b0 100644 --- a/RelaxVersioner/RelaxVersioner.csproj +++ b/RelaxVersioner/RelaxVersioner.csproj @@ -37,7 +37,7 @@ + Include="RelaxVersioner" Version="3.7.0" PrivateAssets="all" /> diff --git a/rv-cli/rv-cli.csproj b/rv-cli/rv-cli.csproj index 06d725a..3a8b60a 100644 --- a/rv-cli/rv-cli.csproj +++ b/rv-cli/rv-cli.csproj @@ -27,7 +27,7 @@ + Include="RelaxVersioner" Version="3.7.0" PrivateAssets="all" /> @@ -35,7 +35,7 @@ - +