Skip to content

Commit 4b8c773

Browse files
committed
feat(button): versioning from assembly not file parsing
1 parent 63ded2c commit 4b8c773

File tree

5 files changed

+21
-30
lines changed

5 files changed

+21
-30
lines changed

TELBlazor.Components/TELBlazor.Components.csproj

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<Content Remove="..\CICDPackageLocation\**\*" />
4949
<None Remove="..\CICDPackageLocation\**\*" />
5050
</ItemGroup>
51+
5152
<ItemGroup>
5253
<Content Include="Core\DI\gitinclude.txt" />
5354
</ItemGroup>
@@ -61,13 +62,6 @@
6162
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6263
</Content>
6364
</ItemGroup>
64-
<Target Name="CleanVersionInfoFile" BeforeTargets="WriteTELBlazorPackageVersionToFile">
65-
<Delete Files="TELBlazorPackageVersion/VersionInfo.cs" />
66-
</Target>
67-
<Target Name="WriteTELBlazorPackageVersionToFile" BeforeTargets="RunGulp">
68-
<WriteLinesToFile File="wwwroot/TELBlazorPackageVersion.txt" Lines="$(TELBlazorPackageVersion)" Overwrite="true" Encoding="UTF-8" />
69-
<WriteLinesToFile File="TELBlazorPackageVersion/VersionInfo.cs" Lines="namespace TELBlazor.Components.TELBlazorPackageVersion { public static class VersionInfo { public static string TELBlazorPackageVersion = &quot;$(TELBlazorPackageVersion)&quot; %3B; } }" Overwrite="true" Encoding="UTF-8" />
70-
</Target>
7165
<Target Name="RunGulp" BeforeTargets="PrepareForBuild">
7266
<!--
7367
1) Use solution root as working dir so npx picks up root/node_modules
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace TELBlazor.Components.TELBlazorPackageVersion
2+
{
3+
public static partial class VersionInfo
4+
{
5+
public static readonly string TELBlazorPackageVersion = typeof(_Imports).Assembly.GetName().Version?.ToString() ?? "Unknown";
6+
}
7+
}

TELBlazor.Components/TELBlazorPackageVersion/VersionInfo.TELFrontEnd.cs

Whitespace-only changes.
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
namespace TELBlazor.Components.TELBlazorPackageVersion { public static class VersionInfo { public static string TELBlazorPackageVersion = "1.4.0" ;
2-
public static string TELFrontEndPackageVersion = "0.0.2"; } }
1+
// VersionInfo.cs
2+
namespace TELBlazor.Components.TELBlazorPackageVersion
3+
{
4+
public static partial class VersionInfo { }
5+
}

TELBlazor.Components/gulpfile.js

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function getTELFrontEndPackageVersion() {
2727

2828
// Task that adds a second public static string to existing file that provides the TELFrontend.css version
2929
gulp.task("add-telFrontEndVersion-to-versionInfo", function (done) {
30-
const versionFilePath = "TELBlazorPackageVersion/VersionInfo.cs";
30+
const versionFilePath = "TELBlazorPackageVersion/VersionInfo.TELFrontEnd.cs";
3131
const TELFrontEndPackageVersion = getTELFrontEndPackageVersion();
3232

3333
if (TELFrontEndPackageVersion === null) {
@@ -37,29 +37,16 @@ gulp.task("add-telFrontEndVersion-to-versionInfo", function (done) {
3737

3838
console.log(`Adding TELFrontEndPackageVersion to CS file at: ${versionFilePath}`);
3939

40-
if (fs.existsSync(versionFilePath)) {
41-
console.log("File exists, adding TELFrontEndPackageVersion string");
4240

43-
// Read existing content
44-
let existingContent = fs.readFileSync(versionFilePath, "utf8");
45-
console.log("Existing content:", existingContent);
41+
// Read existing content
42+
let existingContent = fs.readFileSync(versionFilePath, "utf8");
43+
console.log("Existing content:", existingContent);
4644

47-
// Find the closing brace of the class
48-
const closingBraceIndex = existingContent.lastIndexOf("}");
49-
const secondLastBraceIndex = existingContent.lastIndexOf("}", closingBraceIndex - 1);
45+
const content = ` namespace TELBlazor.Components.TELBlazorPackageVersion{public static partial class VersionInfo{public static readonly string TELFrontEndPackageVersion = "${TELFrontEndPackageVersion}";}} `;
5046

51-
if (closingBraceIndex > 0 && secondLastBraceIndex > 0) {
52-
// Insert the new property before the class closing brace
53-
const newContent = existingContent.substring(0, secondLastBraceIndex) +
54-
` public static string TELFrontEndPackageVersion = "${TELFrontEndPackageVersion}"; ` +
55-
existingContent.substring(secondLastBraceIndex);
56-
57-
fs.writeFileSync(versionFilePath, newContent);
58-
console.log("Second string added successfully!");
59-
} else {
60-
console.error("Couldn't find proper location to insert second string");
61-
}
62-
}
47+
// Write or overwrite the file completely
48+
fs.writeFileSync(versionFilePath, content, "utf8");
49+
console.log(`VersionInfo.TELFrontEnd.cs file updated with version ${TELFrontEndPackageVersion}`);
6350

6451
done();
6552
});

0 commit comments

Comments
 (0)