Skip to content

Commit

Permalink
Add server bits too
Browse files Browse the repository at this point in the history
  • Loading branch information
IEvangelist committed Feb 24, 2022
1 parent a11eb9d commit 0c94f8d
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 4 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,41 @@ jobs:
run: |
dotnet restore ./src/Blazor.SourceGenerators/Blazor.SourceGenerators.csproj
dotnet restore ./src/Blazor.LocalStorage.WebAssembly/Blazor.LocalStorage.WebAssembly.csproj
dotnet restore ./src/Blazor.LocalStorage.Server/Blazor.LocalStorage.Server.csproj
- name: Build
run: |
dotnet build ./src/Blazor.SourceGenerators/Blazor.SourceGenerators.csproj --configuration Release --no-restore
dotnet build ./src/Blazor.LocalStorage.WebAssembly/Blazor.LocalStorage.WebAssembly.csproj --configuration Release --no-restore
dotnet build ./src/Blazor.LocalStorage.Server/Blazor.LocalStorage.Server.csproj --configuration Release --no-restore
- name: Test
run: dotnet test

- name: Pack
run: |
dotnet pack ./src/Blazor.SourceGenerators/Blazor.SourceGenerators.csproj --output packages
dotnet pack ./src/Blazor.LocalStorage.WebAssembly/Blazor.LocalStorage.WebAssembly.csproj --output packages
dotnet pack ./src/Blazor.LocalStorage.Server/Blazor.LocalStorage.Server.csproj --output packages
- name: Publish package
run: |
nuget push **\*.nupkg -Source 'https://api.nuget.org/v3/index.json' -NoSymbols -NonInteractive -ApiKey ${{secrets.NUGET_API_KEY}}
- name: Upload abstractions package
- name: Upload source generators package
uses: actions/upload-artifact@v2
with:
name: Blazor.SourceGenerators.${{ steps.regex-match.outputs.match }}.nupkg
path: packages/

- name: Upload client package
- name: Upload localStorage WebAssembly package
uses: actions/upload-artifact@v2
with:
name: Blazor.LocalStorage.WebAssembly.${{ steps.regex-match.outputs.match }}.nupkg
path: packages/

- name: Upload localStorage Server package
uses: actions/upload-artifact@v2
with:
name: Blazor.LocalStorage.Server.${{ steps.regex-match.outputs.match }}.nupkg
path: packages/
7 changes: 7 additions & 0 deletions blazorators.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.ExampleConsumer", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.LocalStorage.WebAssembly", "src\Blazor.LocalStorage.WebAssembly\Blazor.LocalStorage.WebAssembly.csproj", "{2F4EE253-7D56-4853-ADA7-4F2F6280C2D2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blazor.LocalStorage.Server", "src\Blazor.LocalStorage.Server\Blazor.LocalStorage.Server.csproj", "{9AA2BB50-9F1A-43D0-BB6B-C3C4E9765BE1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -50,6 +52,10 @@ Global
{2F4EE253-7D56-4853-ADA7-4F2F6280C2D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F4EE253-7D56-4853-ADA7-4F2F6280C2D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F4EE253-7D56-4853-ADA7-4F2F6280C2D2}.Release|Any CPU.Build.0 = Release|Any CPU
{9AA2BB50-9F1A-43D0-BB6B-C3C4E9765BE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9AA2BB50-9F1A-43D0-BB6B-C3C4E9765BE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9AA2BB50-9F1A-43D0-BB6B-C3C4E9765BE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9AA2BB50-9F1A-43D0-BB6B-C3C4E9765BE1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -59,6 +65,7 @@ Global
{A84D365E-4FC5-46DB-B25E-D1BB5D3A8C4A} = {A644CEC3-BD94-4EB6-9BF0-86B562806BF9}
{72914F05-4DF1-491C-B2E5-EFE9BB12FCC2} = {91A35318-B03F-4D41-AE18-2C21B9D9C3F3}
{2F4EE253-7D56-4853-ADA7-4F2F6280C2D2} = {537EB83C-6982-40B0-801A-479DF3B17DBE}
{9AA2BB50-9F1A-43D0-BB6B-C3C4E9765BE1} = {537EB83C-6982-40B0-801A-479DF3B17DBE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3F86284A-32D2-4F79-B23C-7A0CB8775971}
Expand Down
77 changes: 77 additions & 0 deletions src/Blazor.LocalStorage.Server/Blazor.LocalStorage.Server.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>true</ImplicitUsings>
<Description>Source generated JavaScript interop for the browser's localStorage API compatible with Blazor Server.</Description>
<Copyright>Copyright © David Pine. All rights reserved. Licensed under the MIT License.</Copyright>
<NeutralLanguage>en-US</NeutralLanguage>
<CurrentDate>$([System.DateTime]::Now.ToString(yyyyMMdd))</CurrentDate>
<ClientVersion Condition=" '$(IsPreview)' != 'true' ">$(ClientOfficialVersion)</ClientVersion>
<ClientVersion Condition=" '$(IsPreview)' == 'true' ">$(ClientPreviewVersion)</ClientVersion>
<VersionSuffix Condition=" '$(IsNightly)' == 'true' ">nightly-$(CurrentDate)</VersionSuffix>
<VersionSuffix Condition=" '$(IsPreview)' == 'true' ">preview</VersionSuffix>
<Version Condition=" '$(VersionSuffix)' == '' ">$(ClientVersion)</Version>
<Version Condition=" '$(VersionSuffix)' != '' ">$(ClientVersion)-$(VersionSuffix)</Version>
<FileVersion>$(ClientVersion)</FileVersion>
<Authors>David Pine</Authors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AssemblyName>Blazor.LocalStorage.Server</AssemblyName>
<Title>A C# source-generated class library implementation of the native browser's localStorage API available as IJSRuntime extension methods.</Title>
<PackageId>Blazor.LocalStorage.Server</PackageId>
<PackageTags>dotnet;dotnetcore;csharp;blazor;generators;sourcegen;roslyn;</PackageTags>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageProjectUrl>https://github.com/IEvangelist/blazorators</PackageProjectUrl>
<PublishRepositoryUrl Condition=" '$(ProjectRef)' != 'True' ">true</PublishRepositoryUrl>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PlatformTarget>AnyCPU</PlatformTarget>
<ShippingScope>External</ShippingScope>
<SigningType>Product</SigningType>
<DebugType>embedded</DebugType>
<IncludeSymbols>false</IncludeSymbols>
<IncludeSource>false</IncludeSource>
<RootNamespace>Blazor.LocalStorage.Server</RootNamespace>
<NoWarn>NU5125;NU5039</NoWarn>
<Optimize Condition="'$(Configuration)'=='Release'">true</Optimize>
<RepositoryUrl>https://github.com/IEvangelist/blazorators</RepositoryUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<RepositoryType>git</RepositoryType>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<PackageReadmeFile>README.md</PackageReadmeFile>
<IsPackable>true</IsPackable>
<PackageIcon>logo.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MinVer" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="6.0.0" />
<PackageReference Include="Microsoft.JSInterop" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Blazor.SourceGenerators\Blazor.SourceGenerators.csproj"
OutputItemType="Analyzer"
SetTargetFramework="TargetFramework=netstandard2.0"
ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup Label="Files">
<None Include="..\..\LICENSE" Pack="true" PackagePath="\" />
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
<None Include="..\..\logo.png" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions src/Blazor.LocalStorage.Server/LocalStorageExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.JSInterop;

/// <summary>
/// Source generated extension methods on the <see cref="IJSRuntime"/> implementation.
/// </summary>
[JSAutoInterop(
TypeName = "Storage",
PathFromWindow = "window.localStorage",
HostingModel = BlazorHostingModel.Server,
OnlyGeneratePureJS = true,
Url = "https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage")]
public static partial class LocalStorageExtensions
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>true</ImplicitUsings>
<Description>Source generated JavaScript interop for the browser's localStorage API compatibel with WebAssembly.</Description>
<Description>Source generated JavaScript interop for the browser's localStorage API compatible with Blazor WebAssembly.</Description>
<Copyright>Copyright © David Pine. All rights reserved. Licensed under the MIT License.</Copyright>
<NeutralLanguage>en-US</NeutralLanguage>
<CurrentDate>$([System.DateTime]::Now.ToString(yyyyMMdd))</CurrentDate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ public static class ServiceCollectionExtensions
/// Adds the ability to either <c>@inject</c>
/// (or <c>[Inject]</c>) the <c>IJSInProcessRuntime</c> type.
/// </summary>
[Obsolete("Call AddInProcessJavaScript instead.")]
public static IServiceCollection AddWebAssemblyLocalStorage(
this IServiceCollection services) =>
services.AddInProcessJavaScript();

/// <summary>
/// Adds the ability to either <c>@inject</c>
/// (or <c>[Inject]</c>) the <c>IJSInProcessRuntime</c> type.
/// </summary>
public static IServiceCollection AddInProcessJavaScript(
this IServiceCollection services) =>
services.AddScoped<IJSInProcessRuntime>(
serviceProvider =>
Expand Down
6 changes: 6 additions & 0 deletions src/Blazor.SourceGenerators/CSharp/CSharpExtensionObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ static StringBuilder AppendTripleSlashComments(

var jsMethodName = method.RawName.LowerCaseFirstLetter();
var func = $"{options.PathFromWindow}.{jsMethodName}";

// TODO: Bug, fix URL
// For example:
// https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage/getItem
// should be:
// https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem
builder.Append($" /// Source generated extension method implementation of <c>{func}</c>.\r\n");
if (options.Url is { Length: > 0 } url)
{
Expand Down

0 comments on commit 0c94f8d

Please sign in to comment.