Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .netconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
weak
[file "src/Directory.Build.props"]
url = https://github.com/devlooped/oss/tree/main/src/Directory.Build.props
sha = 2fff747a9673b499c99f2da183cdd5263fdc9333
sha = 81d972fd0760c244d134dae7f4b17d6c43cb004a

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

etag = fcb9759a96966df40dcd24906fd328ddec05953b7e747a6bb8d0d1e4c3865274
weak
[file "src/Smith/Extensions/System/Throw.cs"]
url = https://github.com/devlooped/catbag/blob/main/System/Throw.cs
sha = 3012d56be7554c483e5c5d277144c063969cada9
etag = 43c81c6c6dcdf5baee40a9e3edc5e871e473e6c954c901b82bb87a3a48888ea0
weak
22 changes: 22 additions & 0 deletions Smith.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36221.1 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Smith", "src\Smith\Smith.csproj", "{728856C5-A241-6AD6-5CDE-1991FE2F10D7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{728856C5-A241-6AD6-5CDE-1991FE2F10D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{728856C5-A241-6AD6-5CDE-1991FE2F10D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{728856C5-A241-6AD6-5CDE-1991FE2F10D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{728856C5-A241-6AD6-5CDE-1991FE2F10D7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
4 changes: 0 additions & 4 deletions Smith.slnx

This file was deleted.

2 changes: 2 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
<_VersionLabel>$(_VersionLabel.Replace('/merge', ''))</_VersionLabel>
<!-- Finally sanitize the branch with dashes, so we can build path-separated branches, like rel/v1.0.0 or feature/foo -->
<_VersionLabel>$(_VersionLabel.Replace('/', '-'))</_VersionLabel>
<!-- And underscores which are also invalid labels, so we can use branches like dev/feature_foo -->
<_VersionLabel>$(_VersionLabel.Replace('_', '-'))</_VersionLabel>

<!-- Set sanitized version to the actual version suffix used in build/pack -->
<VersionSuffix Condition="!$(VersionLabel.Contains('refs/tags/'))">$(_VersionLabel)</VersionSuffix>
Expand Down
8 changes: 8 additions & 0 deletions src/Directory.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>

<PropertyGroup>
<RestoreSources>https://api.nuget.org/v3/index.json;https://pkg.kzu.app/index.json</RestoreSources>
<PackageProjectUrl>https://github.com/devlooped/smith</PackageProjectUrl>
</PropertyGroup>

</Project>
37 changes: 37 additions & 0 deletions src/Directory.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project InitialTargets="SetLocalVersion">

<PropertyGroup>
<PackOnBuild>true</PackOnBuild>
</PropertyGroup>

<Target Name="SetLocalVersion" Condition="!$(CI)">
<GetVersion>
<Output TaskParameter="Version" PropertyName="Version" />
</GetVersion>
</Target>

<UsingTask TaskName="GetVersion" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<Version Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="Microsoft.Build.Framework"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
var version = this.BuildEngine4.GetRegisteredTaskObject("Version", RegisteredTaskObjectLifetime.Build);
if (version == null)
{
var epoc = DateTime.Parse("2024-03-15");
var days = Math.Truncate(DateTime.UtcNow.Subtract(epoc).TotalDays);
var time = Math.Floor(DateTime.UtcNow.TimeOfDay.TotalMinutes);
version = "42." + days + "." + time;
this.BuildEngine4.RegisterTaskObject("Version", version, RegisteredTaskObjectLifetime.Build, false);
}
Version = (string)version;
]]>
</Code>
</Task>
</UsingTask>

</Project>
11 changes: 0 additions & 11 deletions src/Smith.Extensions/Smith.Extensions.csproj

This file was deleted.

25 changes: 25 additions & 0 deletions src/Smith/AppInitializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;

namespace Weaving;

class AppInitializer
{
#pragma warning disable CA2255 // The 'ModuleInitializer' attribute should not be used in libraries
[ModuleInitializer]
#pragma warning restore CA2255 // The 'ModuleInitializer' attribute should not be used in libraries
public static void Init()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Console.InputEncoding = Console.OutputEncoding = Encoding.UTF8;

// Load environment variables from .env files in current dir and above.
DotNetEnv.Env.TraversePath().Load();

// Load environment variables from user profile directory.
var userEnv = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".env");
if (File.Exists(userEnv))
DotNetEnv.Env.Load(userEnv);
}
}
30 changes: 30 additions & 0 deletions src/Smith/Env.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;

namespace Weaving;

/// <summary>
/// Allows retrieving configuration settings for the app environment using the
/// default configuration system provided by <see cref="Host.CreateApplicationBuilder()"/>
/// </summary>
public static class Env
{
static readonly IConfigurationManager configuration =
Host.CreateApplicationBuilder(Environment.GetCommandLineArgs()).Configuration;

/// <summary>
/// Gets a (possibly null) configuration value for the given key.
/// </summary>
/// <param name="key">The key to retrieve, following .NET configuration system conventions.</param>
public static string? Get(string key) => configuration[key];

/// <summary>
/// Gets a configuration value for the given key, returning a default value if the key is not found.
/// </summary>
/// <param name="key">The key to retrieve, following .NET configuration system conventions.</param>
/// <param name="defaultValue">Default value to return if the key is not found.</param>
/// <returns>Never returns null if <paramref name="defaultValue"/> is not <see langword="null"/>.</returns>
[return: NotNullIfNotNull(nameof(defaultValue))]
public static string? Get(string key, string defaultValue) => configuration[key] ?? defaultValue;
}
Loading