Skip to content

Commit 4e65815

Browse files
committed
feat(button): Refactoring and nhsukfrontend version
1 parent c08796e commit 4e65815

File tree

10 files changed

+108
-53
lines changed

10 files changed

+108
-53
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,4 @@ CHANGELOG.md
191191
/TELBlazor.Components.UnitTests/coverage.cobertura.xml
192192
/CoverageReport
193193
/TELBlazor.Components/wwwroot/css/nhsuk.css
194+
/TELBlazor.Components/wwwroot/css/nhsuk.css

TELBlazor.Components/Core/DI/DI.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ ITELBlazorBaseComponentConfiguration TELBlazorBaseComponentConfiguration
3030
)
3131
{
3232

33-
if (IsClient)
33+
34+
//// Register only if not already registered
35+
//if (!services.Any(sd => sd.ServiceType == typeof(ITELBlazorBaseComponentConfiguration)))
36+
//{
37+
38+
if (IsClient)
3439
{
3540
services.AddSingleton<ITELBlazorBaseComponentConfiguration>(sp =>{return TELBlazorBaseComponentConfiguration;});
3641

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace TELBlazor.Components.Core.Models.Logging
8+
{
9+
public interface ILocalStorageLogLevel
10+
{
11+
public string Level { get; set; }
12+
public DateTime Expires { get; set; }
13+
}
14+
}

TELBlazor.Components/Core/Models/Logging/LocalStorageLogLevel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace TELBlazor.Components.Core.Models.Logging
88
{
9-
public class LocalStorageLogLevel
9+
public class LocalStorageLogLevel : ILocalStorageLogLevel
1010
{
1111
public string Level { get; set; } = null;
1212
public DateTime Expires { get; set; }

TELBlazor.Components/Core/Services/HelperServices/ILogLevelSwitcherService.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ namespace TELBlazor.Components.Core.Services.HelperServices
88
{
99
public interface ILogLevelSwitcherService
1010
{
11-
12-
/// <summary>
13-
/// String so can be more generic
14-
/// </summary>
15-
/// <returns></returns>
16-
public string GetCurrentLogLevel();
11+
public string GetCurrentLogLevel();// String so can be more generic
1712

1813
public string SetLogLevel(string level);
1914

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
using Microsoft.AspNetCore.Components;
22
using Microsoft.Extensions.Logging;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
83
using TELBlazor.Components.Core.Configuration;
94

105
namespace TELBlazor.Components.Core
116
{
7+
/// <summary>
8+
/// Base class for TEL Blazor components.
9+
/// Provides shared configuration and logging functionality.
10+
/// </summary>
1211
public class TELComponentBase : ComponentBase
1312
{
1413
// this will receive server version prerender and then client side if received must be true
1514
[Inject]
16-
private ITELBlazorBaseComponentConfiguration TELBlazorBaseComponentConfiguration { get; set; }
15+
private ITELBlazorBaseComponentConfiguration TELBlazorBaseComponentConfiguration { get; set; } = default!;
1716

1817
[Inject]
19-
public ILogger<TELComponentBase> Logger { get; set; }
18+
public ILogger<TELComponentBase> Logger { get; set; } = default!;
2019

2120
protected bool JSEnabled => TELBlazorBaseComponentConfiguration.JSEnabled;
2221
protected string HostType => TELBlazorBaseComponentConfiguration.HostType;
2322
protected override void OnInitialized()
2423
{
2524
base.OnInitialized();
26-
Logger.LogInformation("base component made by {HostType}, JsEnabled is {JsEnabled}", HostType, JSEnabled);
25+
Logger.LogInformation("TEL base component initialised made by {HostType}, JsEnabled is {JsEnabled}", HostType, JSEnabled);
2726
}
2827
}
2928
}

TELBlazor.Components/TELBlazor.Components.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
<PackageOutputPath>$(NupkgOutputPath)</PackageOutputPath>
2525
<Configurations>Debug;Release</Configurations>
2626

27-
28-
29-
3027
</PropertyGroup>
3128

3229
<ItemGroup>
@@ -59,10 +56,10 @@
5956
</ItemGroup>
6057
<Target Name="WriteTELBlazorPackageVersionToFile" BeforeTargets="PrepareForBuild">
6158
<WriteLinesToFile File="wwwroot/TELBlazorPackageVersion.txt" Lines="$(TELBlazorPackageVersion)" Overwrite="true" Encoding="UTF-8" />
62-
<WriteLinesToFile File="TELBlazorPackageVersion/VersionInfo.cs" Lines="namespace TELBlazor.Components.TELBlazorPackageVersion { public static class VersionInfo { public static string Version = &quot;$(TELBlazorPackageVersion)&quot; %3B; } }" Overwrite="true" Encoding="UTF-8" />
59+
<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" />
6360
</Target>
6461
<!--Exclude for release so consuming projects responsible for providing the css to prevent duplication-->
65-
<Target Name="RunGulp" BeforeTargets="Build" Condition="'$(Configuration)' != 'Release'">
62+
<Target Name="RunGulp" BeforeTargets="PrepareForBuild" Condition="'$(Configuration)' != 'Release'">
6663
<Exec Command="npx gulp" WorkingDirectory="$(ProjectDir)" />
6764
</Target>
6865
</Project>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p>
2-
<b>TELBlazor Package Version:</b> @TELBlazor.Components.TELBlazorPackageVersion.VersionInfo.Version
2+
<b>TELBlazor Package Version:</b> @TELBlazor.Components.TELBlazorPackageVersion.VersionInfo.TELBlazorPackageVersion
33
&nbsp;|&nbsp;
4-
<b>TEL-NHSUK Version:</b> TODO QQQQ
4+
<b>TELFrontEnd Package Version:</b> @TELBlazor.Components.TELBlazorPackageVersion.VersionInfo.TELFrontEndPackageVersion
55
</p>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
namespace TELBlazor.Components.TELBlazorPackageVersion { public static class VersionInfo { public static string Version = "10.9.9" ;
2-
} }
1+
namespace TELBlazor.Components.TELBlazorPackageVersion { public static class VersionInfo { public static string TELBlazorPackageVersion = "10.9.9" ;
2+
public static string TELFrontEndPackageVersion = "0.0.2"; } }

TELBlazor.Components/gulpfile.js

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,77 @@
1-
/// Summary
2-
// Dont want to run on publish but instead make it required for the consuming project to provide the nhsukcss so it isnt twice in the consuming project
3-
///
4-
5-
// gulpfile.js
6-
//qqqq clear up if commented out isnt needed later
1+
// gulpfile.js
2+
// qqqq not centralised and deliberately does not run on release so could end up out of step
73
const gulp = require("gulp");
8-
//const sass = require("gulp-sass")(require("sass"));
9-
//const concat = require("gulp-concat");
10-
11-
//// Compile SCSS to CSS
12-
//gulp.task("sass", function () {
13-
// return gulp
14-
// .src("./scss/**/*.scss") // Adjust this path if needed
15-
// .pipe(sass().on("error", sass.logError))
16-
// .pipe(concat("site.css"))
17-
// .pipe(gulp.dest("wwwroot/css"));
18-
//});
4+
const fs = require('fs');
5+
const path = require('path');
196

207
gulp.task("copy-nhsuk-css", function () {
21-
return gulp
22-
.src("node_modules/nhse-tel-frontend/dist/nhsuk.css")
23-
.pipe(gulp.dest("wwwroot/css"));
8+
9+
const cssPath = "node_modules/nhse-tel-frontend/dist/nhsuk.css";
10+
const destPath = "wwwroot/css";
11+
12+
return gulp.src(cssPath)
13+
.pipe(gulp.dest(destPath));
14+
});
15+
16+
// Function to get the TELFrontEndPackageVersion from package.json
17+
function getTELFrontEndPackageVersion() {
18+
const packageJsonPath = path.join(__dirname, "node_modules", "nhse-tel-frontend", "package.json");
19+
console.log("Attempting to read package.json at:", packageJsonPath);
20+
21+
try {
22+
if (fs.existsSync(packageJsonPath)) {
23+
const packageJsonContent = fs.readFileSync(packageJsonPath, "utf8");
24+
const packageJson = JSON.parse(packageJsonContent);
25+
console.log("Successfully read package.json. Version:", packageJson.version);
26+
return packageJson.version;
27+
} else {
28+
console.warn("Package.json file does not exist at:", packageJsonPath);
29+
return null; // Return null if file not found
30+
}
31+
} catch (error) {
32+
console.error("Error reading or parsing package.json:", error);
33+
return null; // Return null on error
34+
}
35+
}
36+
37+
// Task that adds a second public static string to existing file
38+
gulp.task("add-telFrontEndVersion-to-versionInfo", function (done) {
39+
const versionFilePath = "TELBlazorPackageVersion/VersionInfo.cs";
40+
const TELFrontEndPackageVersion = getTELFrontEndPackageVersion();
41+
42+
if (TELFrontEndPackageVersion === null) {
43+
console.error("Could not determine TELFrontEndPackageVersion. Aborting task.");
44+
return done(new Error("Failed to get TELFrontEndPackageVersion")); // Indicate task failure
45+
}
46+
47+
console.log(`Adding TELFrontEndPackageVersion to CS file at: ${versionFilePath}`);
48+
49+
if (fs.existsSync(versionFilePath)) {
50+
console.log("File exists, adding TELFrontEndPackageVersion string");
51+
52+
// Read existing content
53+
let existingContent = fs.readFileSync(versionFilePath, "utf8");
54+
console.log("Existing content:", existingContent);
55+
56+
// Find the closing brace of the class
57+
const closingBraceIndex = existingContent.lastIndexOf("}");
58+
const secondLastBraceIndex = existingContent.lastIndexOf("}", closingBraceIndex - 1);
59+
60+
if (closingBraceIndex > 0 && secondLastBraceIndex > 0) {
61+
// Insert the new property before the class closing brace
62+
const newContent = existingContent.substring(0, secondLastBraceIndex) +
63+
` public static string TELFrontEndPackageVersion = "${TELFrontEndPackageVersion}"; ` +
64+
existingContent.substring(secondLastBraceIndex);
65+
66+
fs.writeFileSync(versionFilePath, newContent);
67+
console.log("Second string added successfully!");
68+
} else {
69+
console.error("Couldn't find proper location to insert second string");
70+
}
71+
}
72+
73+
done();
2474
});
2575

26-
// Watch for changes
27-
//gulp.task("watch", function () {
28-
// gulp.watch("./scss/**/*.scss", gulp.series("sass"));
29-
//});
30-
//,"watch"
31-
// Default task
32-
gulp.task("default", gulp.series("copy-nhsuk-css"));
33-
//gulp.task("default", gulp.series("copy-nhsuk-css", "sass"));
76+
77+
gulp.task("default", gulp.series("copy-nhsuk-css", "add-telFrontEndVersion-to-versionInfo"));

0 commit comments

Comments
 (0)