Skip to content

Commit ddbb6e4

Browse files
committed
version update 6.0.3 -> 6.0.4
1 parent 1fd07f5 commit ddbb6e4

File tree

9 files changed

+175
-102
lines changed

9 files changed

+175
-102
lines changed

nuget-dotnetcli/dotnet-typegen.nuspec

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
<?xml version="1.0"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<package>
33
<metadata>
44
<id>dotnet-typegen</id>
5-
<version>6.0.3</version>
5+
<version>6.0.4</version>
66
<authors>Jacek Burzynski</authors>
77
<owners>Jacek Burzynski</owners>
88
<license type="file">LICENSE</license>
99
<projectUrl>https://github.com/jburzynski/TypeGen</projectUrl>
1010
<iconUrl>https://raw.githubusercontent.com/jburzynski/type-gen/master/docs/icon.png</iconUrl>
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1212
<description>TypeGen .NET CLI tool (TypeGen is a single-class-per-file C# to TypeScript generator)</description>
13-
<releaseNotes>
14-
- added TsRequiredAttribute for definite assignment assertion operator (#219)
13+
<releaseNotes>
14+
- fixed incorrect exception handling when using System.CommandLine (#225)
15+
- if the config file path is provided but does not exist, CLI now exits with an error
1516
</releaseNotes>
1617
<tags>code-generator generator code typescript ts csharp cs dotnet cli</tags>
17-
<packageTypes>
18+
<packageTypes>
1819
<packageType name="DotnetTool" />
1920
</packageTypes>
2021
</metadata>

nuget/TypeGen.nuspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<?xml version="1.0"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<package>
33
<metadata>
44
<id>TypeGen</id>
5-
<version>6.0.3</version>
5+
<version>6.0.4</version>
66
<authors>Jacek Burzynski</authors>
77
<owners>Jacek Burzynski</owners>
88
<license type="file">LICENSE</license>
@@ -11,7 +11,8 @@
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1212
<description>TypeGen is a single-class-per-file C# to TypeScript generator</description>
1313
<releaseNotes>
14-
- added TsRequiredAttribute for definite assignment assertion operator (#219)
14+
- fixed incorrect exception handling when using System.CommandLine (#225)
15+
- if the config file path is provided but does not exist, CLI now exits with an error
1516
</releaseNotes>
1617
<tags>code-generator generator code typescript ts csharp cs</tags>
1718
<dependencies>

src/TypeGen/TypeGen.Cli/Application.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,18 @@ public async Task<ExitCode> Run(string[] args)
4242

4343
private RootCommand GetRootCommand()
4444
{
45-
var rootCommand = new RootCommand();
45+
var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version;
46+
var versionOutput = $"{assemblyVersion.Major}.{assemblyVersion.Minor}.{assemblyVersion.Build}";
4647

47-
var versionOption = new Option<string>("--version")
48+
var rootCommand = new RootCommand
4849
{
49-
Description = "Show TypeGen version.",
50-
DefaultValueFactory = x => ApplicationConfig.Version
50+
Description = $"TypeGen {versionOutput}"
5151
};
5252

53-
rootCommand.Options.Add(versionOption);
53+
rootCommand.SetAction((ParseResult parseResult) =>
54+
{
55+
return rootCommand.Parse("--help").InvokeAsync();
56+
});
5457

5558
var generateCommand = new Command("generate", "Generate TypeScript files.");
5659

src/TypeGen/TypeGen.Cli/ApplicationConfig.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/TypeGen/TypeGen.Cli/AssemblyInfo.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44
[assembly: InternalsVisibleTo("TypeGen.FileContentTest")]
55
[assembly: InternalsVisibleTo("TypeGen.Cli.Test")]
66
[assembly: InternalsVisibleTo("TypeGen.Core.Test")]
7-
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
7+
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
8+
[assembly: AssemblyVersion("6.0.4.0")]
9+
[assembly: AssemblyFileVersion("6.0.4.0")]
10+
[assembly: AssemblyInformationalVersion("6.0.4")]

src/TypeGen/TypeGen.Cli/TypeGen.Cli.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
44
<TargetFramework>net9.0</TargetFramework>
5-
<AssemblyVersion>6.0.0.0</AssemblyVersion>
6-
<FileVersion>6.0.0.0</FileVersion>
7-
<Version>6.0.3</Version>
5+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
86
<PackageId>TypeGen</PackageId>
97
<Authors />
108
</PropertyGroup>

src/TypeGen/TypeGen.Core/AssemblyInfo.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55
[assembly: InternalsVisibleTo("TypeGen.FileContentTest")]
66
[assembly: InternalsVisibleTo("TypeGen.Cli.Test")]
77
[assembly: InternalsVisibleTo("TypeGen.Core.Test")]
8-
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
8+
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
9+
[assembly: AssemblyVersion("6.0.4.0")]
10+
[assembly: AssemblyFileVersion("6.0.4.0")]
11+
[assembly: AssemblyInformationalVersion("6.0.4")]

src/TypeGen/TypeGen.Core/TypeGen.Core.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
<TargetFrameworks>netstandard2.0;net9.0</TargetFrameworks>
44
<DocumentationFile>TypeGen.Core.xml</DocumentationFile>
55
<LangVersion>latest</LangVersion>
6-
<AssemblyVersion>6.0.0.0</AssemblyVersion>
7-
<FileVersion>6.0.0.0</FileVersion>
6+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
87
</PropertyGroup>
98
<ItemGroup>
109
<None Remove="Templates\Class.tpl" />

update-version.ps1

Lines changed: 147 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,162 @@
1-
if ($args.Length -eq 0)
2-
{
3-
Write-Host "examples:
4-
./update-version 2.4.9 # changes the current version to 2.4.9"
5-
exit
1+
param(
2+
[Parameter(Mandatory = $true)]
3+
[string]$Version
4+
)
5+
6+
function Abort([string]$msg) {
7+
Write-Error $msg
8+
exit 1
69
}
710

8-
$versionRegex = "^\d+\.\d+\.\d+$"
9-
$newVersion = $args[0]
10-
11-
if (-not ($newVersion -match $versionRegex)) {
12-
Write-Host "Wrong version format. Should be: $($versionRegex)"
13-
exit
14-
}
15-
16-
$oldVersion = (Select-Xml //version "nuget\TypeGen.nuspec")[0].Node.InnerText
17-
$oldVersionMajor = $oldVersion.Split(".")[0]
18-
$oldVersionMinor = $oldVersion.Split(".")[1]
19-
20-
$newVersionMajor = $newVersion.Split(".")[0]
21-
$newVersionMinor = $newVersion.Split(".")[1]
22-
23-
$assemblyOldVersion = "$($oldVersionMajor).$($oldVersionMinor).0.0"
24-
$assemblyNewVersion = "$($newVersionMajor).$($newVersionMinor).0.0"
25-
26-
# replace files' contents
27-
28-
$nuspecPath = "nuget\TypeGen.nuspec"
29-
if (Test-Path $nuspecPath) {
30-
(Get-Content $nuspecPath) `
31-
-Replace "<version>$($oldVersion)</version>", "<version>$($newVersion)</version>" `
32-
| Set-Content $nuspecPath
33-
}
34-
35-
$dotNetCliNuspecPath = "nuget-dotnetcli\dotnet-typegen.nuspec"
36-
if (Test-Path $dotNetCliNuspecPath) {
37-
(Get-Content $dotNetCliNuspecPath) `
38-
-Replace "<version>$($oldVersion)</version>", "<version>$($newVersion)</version>" `
39-
| Set-Content $dotNetCliNuspecPath
11+
if ($Version -notmatch '^\d+\.\d+\.\d+$') {
12+
Abort "Version must be major.minor.build (example: 6.0.4). You passed '$Version'."
4013
}
4114

42-
$appConfigPath = "src\TypeGen\TypeGen.Cli\ApplicationConfig.cs"
43-
if (Test-Path $appConfigPath) {
44-
(Get-Content $appConfigPath) `
45-
-Replace "Version => ""$($oldVersion)""", "Version => ""$($newVersion)""" `
46-
| Set-Content $appConfigPath
15+
$InformationalVersion = $Version
16+
$AssemblyVersion = "$Version.0"
17+
18+
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
19+
20+
$RelativeFiles = @(
21+
"nuget\TypeGen.nuspec",
22+
"nuget-dotnetcli\dotnet-typegen.nuspec",
23+
"src\TypeGen\TypeGen.Cli\AssemblyInfo.cs",
24+
"src\TypeGen\TypeGen.Core\AssemblyInfo.cs"
25+
)
26+
27+
# Resolve absolute paths
28+
$Files = foreach ($rel in $RelativeFiles) {
29+
if ([System.IO.Path]::IsPathRooted($rel)) {
30+
if (Test-Path $rel) { (Resolve-Path $rel).Path }
31+
} else {
32+
$abs = Join-Path $ScriptDir $rel
33+
if (Test-Path $abs) { (Resolve-Path $abs).Path }
34+
}
4735
}
4836

49-
$nugetUpdatePath = "nuget-update.ps1"
50-
if (Test-Path $nugetUpdatePath) {
51-
(Get-Content $nugetUpdatePath) `
52-
-Replace "TypeGen.$($oldVersion)", "TypeGen.$($newVersion)" `
53-
-Replace "dotnet-typegen.$($oldVersion)", "dotnet-typegen.$($newVersion)" `
54-
| Set-Content $nugetUpdatePath
37+
function Backup-File($Path) {
38+
$stamp = (Get-Date).ToString("yyyyMMddHHmmss")
39+
$bak = "$Path.$stamp.bak"
40+
Copy-Item -Path $Path -Destination $bak -Force
41+
Write-Host "Backup created: $bak"
5542
}
5643

57-
$applicationConfigPath = "src\TypeGen\TypeGen.Cli\ApplicationConfig.cs"
58-
if (Test-Path $applicationConfigPath) {
59-
(Get-Content $applicationConfigPath) `
60-
-Replace "Version = ""$($oldVersion)""", "Version = ""$($newVersion)""" `
61-
| Set-Content $applicationConfigPath
44+
function Update-Nuspec($Path, $NewVersion) {
45+
if (-not (Test-Path $Path)) {
46+
Write-Host "WARN: nuspec not found, skipping: $Path"
47+
return
48+
}
49+
50+
try {
51+
# Read raw bytes and decode using BOM-aware reader
52+
$bytes = [System.IO.File]::ReadAllBytes($Path)
53+
# Let .NET detect BOM by using StreamReader with detectEncodingFromByteOrderMarks = $true
54+
$ms = New-Object System.IO.MemoryStream(,$bytes)
55+
$sr = New-Object System.IO.StreamReader($ms, $true)
56+
$raw = $sr.ReadToEnd()
57+
$sr.Close()
58+
$ms.Close()
59+
60+
# Trim leading whitespace and any garbage before first '<'
61+
$firstLt = $raw.IndexOf('<')
62+
if ($firstLt -gt 0) {
63+
$raw = $raw.Substring($firstLt)
64+
}
65+
66+
# Remove leading BOM char if present (U+FEFF)
67+
if ($raw.Length -gt 0 -and $raw[0] -eq [char]0xFEFF) {
68+
$raw = $raw.Substring(1)
69+
}
70+
71+
# Load cleaned XML string into XmlDocument
72+
$xml = New-Object System.Xml.XmlDocument
73+
$xml.PreserveWhitespace = $true
74+
$xml.LoadXml($raw)
75+
76+
# Namespace support
77+
$ns = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
78+
if ($xml.DocumentElement -and $xml.DocumentElement.NamespaceURI) {
79+
$ns.AddNamespace("d", $xml.DocumentElement.NamespaceURI)
80+
}
81+
82+
# Find <version>
83+
$node = $xml.SelectSingleNode("/package/metadata/version", $ns)
84+
if ($node -eq $null -and $ns.HasNamespace("d")) {
85+
$node = $xml.SelectSingleNode("/d:package/d:metadata/d:version", $ns)
86+
}
87+
if ($node -eq $null) { $node = $xml.SelectSingleNode("//metadata/version", $ns) }
88+
if ($node -eq $null) { $node = $xml.SelectSingleNode("//version", $ns) }
89+
90+
if ($node -eq $null) {
91+
Write-Warning "No <version> element found in $Path; skipping."
92+
return
93+
}
94+
95+
$old = $node.InnerText
96+
$node.InnerText = $NewVersion
97+
98+
# Write formatted XML (UTF8 without BOM)
99+
$settings = New-Object System.Xml.XmlWriterSettings
100+
$settings.Indent = $true
101+
$settings.IndentChars = " "
102+
$settings.NewLineChars = "`r`n"
103+
$settings.NewLineHandling = "Replace"
104+
$settings.OmitXmlDeclaration = $false
105+
$settings.Encoding = New-Object System.Text.UTF8Encoding($false)
106+
107+
$writer = [System.Xml.XmlWriter]::Create($Path, $settings)
108+
try { $xml.Save($writer) } finally { $writer.Close() }
109+
110+
Write-Host "Updated nuspec: $Path (version: $old -> $NewVersion)"
111+
}
112+
catch {
113+
Write-Error ("Failed to update nuspec {0}: {1}" -f $Path, $($_.ToString()))
114+
}
62115
}
63116

64-
$typeGenCliCsprojPath = "src\TypeGen\TypeGen.Cli\TypeGen.Cli.csproj"
65-
if (Test-Path $typeGenCliCsprojPath) {
66-
(Get-Content $typeGenCliCsprojPath) `
67-
-Replace "<AssemblyVersion>$($assemblyOldVersion)</AssemblyVersion>", "<AssemblyVersion>$($assemblyNewVersion)</AssemblyVersion>" `
68-
-Replace "<FileVersion>$($assemblyOldVersion)</FileVersion>", "<FileVersion>$($assemblyNewVersion)</FileVersion>" `
69-
-Replace "<Version>$($oldVersion)</Version>", "<Version>$($newVersion)</Version>" `
70-
| Set-Content $typeGenCliCsprojPath
71-
}
72117

73-
$typeGenCoreCsprojPath = "src\TypeGen\TypeGen.Core\TypeGen.Core.csproj"
74-
if (Test-Path $typeGenCoreCsprojPath) {
75-
(Get-Content $typeGenCoreCsprojPath) `
76-
-Replace "<AssemblyVersion>$($assemblyOldVersion)</AssemblyVersion>", "<AssemblyVersion>$($assemblyNewVersion)</AssemblyVersion>" `
77-
-Replace "<FileVersion>$($assemblyOldVersion)</FileVersion>", "<FileVersion>$($assemblyNewVersion)</FileVersion>" `
78-
| Set-Content $typeGenCoreCsprojPath
118+
function Update-AssemblyInfo($Path, $AsmVer, $FileVer, $InfoVer) {
119+
try {
120+
$content = Get-Content -Path $Path -Raw
121+
$orig = $content
122+
123+
$rules = @(
124+
@{ P = 'AssemblyVersion'; V = $AsmVer }
125+
@{ P = 'AssemblyFileVersion'; V = $FileVer }
126+
@{ P = 'AssemblyInformationalVersion'; V = $InfoVer }
127+
)
128+
129+
foreach ($r in $rules) {
130+
$pattern = "(?m)^\s*\[assembly:\s*(?:System\.Reflection\.)?{0}\s*\(\s*""[^""]*""\s*\)\s*\]\s*$" -f $r.P
131+
$replacement = '[assembly: {0}("{1}")]' -f $r.P, $r.V
132+
133+
if ($content -match $pattern) {
134+
$content = [regex]::Replace($content, $pattern, $replacement)
135+
} else {
136+
$content = $content.TrimEnd() + "`r`n$replacement`r`n"
137+
}
138+
}
139+
140+
if ($content -ne $orig) {
141+
Set-Content -Path $Path -Value $content -Encoding UTF8
142+
Write-Host "Updated AssemblyInfo: $Path"
143+
} else {
144+
Write-Host "No changes: $Path"
145+
}
146+
}
147+
catch {
148+
Write-Error ("Failed to update AssemblyInfo {0}: {1}" -f $Path, $_)
149+
}
79150
}
80151

81-
# remove old NuGet package
82-
83-
$oldNupkgPath = "nuget\TypeGen.$($oldVersion).nupkg"
84-
if (Test-Path $oldNupkgPath) {
85-
rm $oldNupkgPath
152+
# Main loop
153+
foreach ($file in $Files) {
154+
Backup-File $file
155+
switch ([System.IO.Path]::GetExtension($file).ToLowerInvariant()) {
156+
".nuspec" { Update-Nuspec $file $InformationalVersion }
157+
".cs" { Update-AssemblyInfo $file $AssemblyVersion $AssemblyVersion $InformationalVersion }
158+
}
86159
}
87160

88-
$oldDotNetCliNupkgPath = "nuget-dotnetcli\dotnet-typegen.$($oldVersion).nupkg"
89-
if (Test-Path $oldDotNetCliNupkgPath) {
90-
rm $oldDotNetCliNupkgPath
91-
}
161+
Write-Host "Done. Updated to version $Version."
162+
exit 0

0 commit comments

Comments
 (0)