Skip to content

Commit 07a4472

Browse files
committed
Update to leverage Devlooped.Extensions.AI
Adds Env, Throws.
1 parent e204494 commit 07a4472

File tree

17 files changed

+1249
-88
lines changed

17 files changed

+1249
-88
lines changed

.netconfig

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
weak
1313
[file "src/Directory.Build.props"]
1414
url = https://github.com/devlooped/oss/tree/main/src/Directory.Build.props
15-
sha = 2fff747a9673b499c99f2da183cdd5263fdc9333
15+
sha = 81d972fd0760c244d134dae7f4b17d6c43cb004a
1616

17-
etag = 0fccddf04f282fe98122ab2610dc2972c205a521254559bf013655c6271b0017
17+
etag = 1368697c1521e465a1dea88b93787b1c7def441c37d62afc903fb8d07179e4f6
1818
weak
1919
[file "src/Directory.Build.targets"]
2020
url = https://github.com/devlooped/oss/tree/main/src/Directory.Build.targets
@@ -64,3 +64,8 @@
6464

6565
etag = fcb9759a96966df40dcd24906fd328ddec05953b7e747a6bb8d0d1e4c3865274
6666
weak
67+
[file "src/Smith/Extensions/System/Throw.cs"]
68+
url = https://github.com/devlooped/catbag/blob/main/System/Throw.cs
69+
sha = 3012d56be7554c483e5c5d277144c063969cada9
70+
etag = 43c81c6c6dcdf5baee40a9e3edc5e871e473e6c954c901b82bb87a3a48888ea0
71+
weak

Smith.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36221.1 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Smith", "src\Smith\Smith.csproj", "{728856C5-A241-6AD6-5CDE-1991FE2F10D7}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{728856C5-A241-6AD6-5CDE-1991FE2F10D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{728856C5-A241-6AD6-5CDE-1991FE2F10D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{728856C5-A241-6AD6-5CDE-1991FE2F10D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{728856C5-A241-6AD6-5CDE-1991FE2F10D7}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

Smith.slnx

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

src/Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@
126126
<_VersionLabel>$(_VersionLabel.Replace('/merge', ''))</_VersionLabel>
127127
<!-- Finally sanitize the branch with dashes, so we can build path-separated branches, like rel/v1.0.0 or feature/foo -->
128128
<_VersionLabel>$(_VersionLabel.Replace('/', '-'))</_VersionLabel>
129+
<!-- And underscores which are also invalid labels, so we can use branches like dev/feature_foo -->
130+
<_VersionLabel>$(_VersionLabel.Replace('_', '-'))</_VersionLabel>
129131

130132
<!-- Set sanitized version to the actual version suffix used in build/pack -->
131133
<VersionSuffix Condition="!$(VersionLabel.Contains('refs/tags/'))">$(_VersionLabel)</VersionSuffix>

src/Directory.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<RestoreSources>https://api.nuget.org/v3/index.json;https://pkg.kzu.app/index.json</RestoreSources>
5+
<PackageProjectUrl>https://github.com/devlooped/smith</PackageProjectUrl>
6+
</PropertyGroup>
7+
8+
</Project>

src/Directory.targets

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<Project InitialTargets="SetLocalVersion">
2+
3+
<PropertyGroup>
4+
<PackOnBuild>true</PackOnBuild>
5+
</PropertyGroup>
6+
7+
<Target Name="SetLocalVersion" Condition="!$(CI)">
8+
<GetVersion>
9+
<Output TaskParameter="Version" PropertyName="Version" />
10+
</GetVersion>
11+
</Target>
12+
13+
<UsingTask TaskName="GetVersion" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
14+
<ParameterGroup>
15+
<Version Output="true" />
16+
</ParameterGroup>
17+
<Task>
18+
<Using Namespace="System" />
19+
<Using Namespace="Microsoft.Build.Framework"/>
20+
<Code Type="Fragment" Language="cs">
21+
<![CDATA[
22+
var version = this.BuildEngine4.GetRegisteredTaskObject("Version", RegisteredTaskObjectLifetime.Build);
23+
if (version == null)
24+
{
25+
var epoc = DateTime.Parse("2024-03-15");
26+
var days = Math.Truncate(DateTime.UtcNow.Subtract(epoc).TotalDays);
27+
var time = Math.Floor(DateTime.UtcNow.TimeOfDay.TotalMinutes);
28+
version = "42." + days + "." + time;
29+
this.BuildEngine4.RegisterTaskObject("Version", version, RegisteredTaskObjectLifetime.Build, false);
30+
}
31+
Version = (string)version;
32+
]]>
33+
</Code>
34+
</Task>
35+
</UsingTask>
36+
37+
</Project>

src/Smith.Extensions/Smith.Extensions.csproj

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

src/Smith/AppInitializer.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Runtime.CompilerServices;
2+
using System.Runtime.InteropServices;
3+
using System.Text;
4+
5+
namespace Weaving;
6+
7+
class AppInitializer
8+
{
9+
#pragma warning disable CA2255 // The 'ModuleInitializer' attribute should not be used in libraries
10+
[ModuleInitializer]
11+
#pragma warning restore CA2255 // The 'ModuleInitializer' attribute should not be used in libraries
12+
public static void Init()
13+
{
14+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
15+
Console.InputEncoding = Console.OutputEncoding = Encoding.UTF8;
16+
17+
// Load environment variables from .env files in current dir and above.
18+
DotNetEnv.Env.TraversePath().Load();
19+
20+
// Load environment variables from user profile directory.
21+
var userEnv = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".env");
22+
if (File.Exists(userEnv))
23+
DotNetEnv.Env.Load(userEnv);
24+
}
25+
}

src/Smith/Env.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.Hosting;
4+
5+
namespace Weaving;
6+
7+
/// <summary>
8+
/// Allows retrieving configuration settings for the app environment using the
9+
/// default configuration system provided by <see cref="Host.CreateApplicationBuilder()"/>
10+
/// </summary>
11+
public static class Env
12+
{
13+
static readonly IConfigurationManager configuration =
14+
Host.CreateApplicationBuilder(Environment.GetCommandLineArgs()).Configuration;
15+
16+
/// <summary>
17+
/// Gets a (possibly null) configuration value for the given key.
18+
/// </summary>
19+
/// <param name="key">The key to retrieve, following .NET configuration system conventions.</param>
20+
public static string? Get(string key) => configuration[key];
21+
22+
/// <summary>
23+
/// Gets a configuration value for the given key, returning a default value if the key is not found.
24+
/// </summary>
25+
/// <param name="key">The key to retrieve, following .NET configuration system conventions.</param>
26+
/// <param name="defaultValue">Default value to return if the key is not found.</param>
27+
/// <returns>Never returns null if <paramref name="defaultValue"/> is not <see langword="null"/>.</returns>
28+
[return: NotNullIfNotNull(nameof(defaultValue))]
29+
public static string? Get(string key, string defaultValue) => configuration[key] ?? defaultValue;
30+
}

0 commit comments

Comments
 (0)