Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SigSpec UI #35

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
/src/**/bin
/src/New folder
**/*.user

src/SigSpec.AspNetCore/SigSpecUi/*.js
src/SigSpec.AspNetCore/SigSpecUi/*.css
src/SigSpec.AspNetCore/SigSpecUi/*.js.map
*.sqlite
.vs/VSWorkspaceState.json
.vs/SigSpec/v16/.suo
138 changes: 76 additions & 62 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
trigger:
branches:
include:
include:
- master
- release
- refs/tags/*
pr:
- master
- master

pool:
vmImage: 'windows-2019'
Expand All @@ -15,66 +15,80 @@ variables:
Projects: '**/*.csproj'

steps:
# Install required SDKs and tools
- task: UseDotNet@2
displayName: 'Install .NET Core SDK'
inputs:
packageType: 'sdk'
version: '3.1.101'
# Install required SDKs and tools
- task: UseDotNet@2
displayName: 'Install .NET Core SDK'
inputs:
packageType: 'sdk'
version: '3.1.101'

# Patch preview project versions (only when on master branch)
- task: CmdLine@2
displayName: 'Install DNT'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
inputs:
script: 'npm i -g dotnettools'
- task: CmdLine@2
displayName: 'Update project version patch'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
inputs:
script: 'dnt bump-versions patch'
failOnStderr: true
- task: CmdLine@2
displayName: 'Patch project version preview'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
inputs:
script: 'dnt bump-versions preview "$(Build.BuildNumber)"'
failOnStderr: true
# Patch preview project versions (only when on master branch)
- task: CmdLine@2
displayName: 'Install DNT'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
inputs:
script: 'npm i -g dotnettools'
- task: CmdLine@2
displayName: 'Update project version patch'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
inputs:
script: 'dnt bump-versions patch'
failOnStderr: true
- task: CmdLine@2
displayName: 'Patch project version preview'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
inputs:
script: 'dnt bump-versions preview "$(Build.BuildNumber)"'
failOnStderr: true

# Build and test
- task: DotNetCoreCLI@2
displayName: 'Build solution'
inputs:
command: 'build'
projects: '$(Projects)'
arguments: '--configuration $(BuildConfiguration)'
feedsToUse: 'select'
versioningScheme: 'off'
- task: DotNetCoreCLI@2
displayName: 'Run tests'
inputs:
command: 'test'
projects: '$(Projects)'
arguments: '--configuration $(BuildConfiguration) --collect "Code Coverage" --settings "$(Build.SourcesDirectory)/src/CodeCoverage.runsettings"'
publishTestResults: true
feedsToUse: 'select'
versioningScheme: 'off'
env:
AzureBlobStorageConnectionString: $(AzureBlobStorageConnectionString)
FtpPassword: $(FtpPassword)
# Build and test
- task: Npm@1
displayName: 'Install UI Dependencies'
inputs:
workingDir: 'src/SigSpec.UI'
verbose: false

# Publish artifacts
- task: CopyFiles@2
displayName: 'Copy packages'
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
inputs:
Contents: '**/*.nupkg'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
flattenFolders: true
- task: PublishBuildArtifacts@1
displayName: 'Publish artifacts'
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- task: Npm@1
displayName: 'Build UI'
inputs:
workingDir: 'src/SigSpec.UI'
command: custom
verbose: false
customCommand: run build

- task: DotNetCoreCLI@2
displayName: 'Build solution'
inputs:
command: 'build'
projects: '$(Projects)'
arguments: '--configuration $(BuildConfiguration)'
feedsToUse: 'select'
versioningScheme: 'off'
- task: DotNetCoreCLI@2
displayName: 'Run tests'
inputs:
command: 'test'
projects: '$(Projects)'
arguments: '--configuration $(BuildConfiguration) --collect "Code Coverage" --settings "$(Build.SourcesDirectory)/src/CodeCoverage.runsettings"'
publishTestResults: true
feedsToUse: 'select'
versioningScheme: 'off'
env:
AzureBlobStorageConnectionString: $(AzureBlobStorageConnectionString)
FtpPassword: $(FtpPassword)

# Publish artifacts
- task: CopyFiles@2
displayName: 'Copy packages'
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
inputs:
Contents: '**/*.nupkg'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
flattenFolders: true
- task: PublishBuildArtifacts@1
displayName: 'Publish artifacts'
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
4 changes: 3 additions & 1 deletion src/HelloSignalR/ChatHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Task Send(string message)

public Task AddPerson(Person person)
{
return Task.CompletedTask;
return Clients.All.PersonAdded(person);
}

public ChannelReader<Event> GetEvents()
Expand Down Expand Up @@ -49,5 +49,7 @@ public interface IChatClient
Task Welcome();

Task Send(string message);

Task PersonAdded(Person person);
}
}
3 changes: 1 addition & 2 deletions src/HelloSignalR/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddSignalR();

// TODO: Automatically look hubs up
services.AddSigSpecDocument(o => o.Hubs["/chat"] = typeof(ChatHub));

services.AddSigSpecDocument(o => o.Hubs["chat"] = typeof(ChatHub));
services.AddCors(c =>
{
c.AddDefaultPolicy(policy =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@ public static IApplicationBuilder UseSigSpec(this IApplicationBuilder app, Actio
return app;
}

public static IApplicationBuilder UseSigSpecUi(this IApplicationBuilder app, Action<SigSpecUiSettings> configure = null)
public static IApplicationBuilder UseSigSpecUi(this IApplicationBuilder app,
Action<SigSpecUiSettings> configure = null)
{
var settings = new SigSpecUiSettings();
configure?.Invoke(settings);

// TODO: Redirect /sigspec to /sigspec/index.html
// TODO: Inject URLs and document names from registered documents into index.html => and then JS
app.UseMiddleware<SigSpecUIIndexMiddleware>($"{settings.Route}/index.html", settings,
"SigSpec.AspNetCore.SigSpecUi.index.html");

app.UseFileServer(new FileServerOptions
{
RequestPath = new PathString(settings.Route),
FileProvider = new EmbeddedFileProvider(typeof(SigSpecApplicationBuilderExtensions).GetTypeInfo().Assembly, "SigSpec.AspNetCore.SigSpecUi")
FileProvider = new EmbeddedFileProvider(
typeof(SigSpecApplicationBuilderExtensions).GetTypeInfo().Assembly, "SigSpec.AspNetCore.SigSpecUi")
});

return app;
Expand Down
1 change: 0 additions & 1 deletion src/SigSpec.AspNetCore/Middlewares/SigSpecMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public async Task Invoke(HttpContext httpContext)
else
{
await _next(httpContext);
return;
}
}

Expand Down
42 changes: 42 additions & 0 deletions src/SigSpec.AspNetCore/Middlewares/SigSpecUiIndexMiddleware.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;

namespace SigSpec.AspNetCore.Middlewares
{
internal class SigSpecUIIndexMiddleware
{
private readonly RequestDelegate _nextDelegate;
private readonly string _indexPath;
private readonly SigSpecUiSettings _settings;
private readonly string _resourcePath;

public SigSpecUIIndexMiddleware(RequestDelegate nextDelegate, string indexPath, SigSpecUiSettings settings, string resourcePath)
{
_nextDelegate = nextDelegate;
_indexPath = indexPath;
_settings = settings;
_resourcePath = resourcePath;
}

public async Task Invoke(HttpContext context)
{
if (context.Request.Path.HasValue && string.Equals(context.Request.Path.Value.Trim('/'), _indexPath.Trim('/'), StringComparison.OrdinalIgnoreCase))
{
var stream = typeof(SigSpecUIIndexMiddleware).GetTypeInfo().Assembly.GetManifestResourceStream(_resourcePath);
using (var reader = new StreamReader(stream))
{
context.Response.Headers["Content-Type"] = "text/html; charset=utf-8";
context.Response.StatusCode = 200;
await context.Response.WriteAsync(_settings.TransformHtml(await reader.ReadToEndAsync(), context.Request));
}
}
else
{
await _nextDelegate(context);
}
}
}
}
7 changes: 2 additions & 5 deletions src/SigSpec.AspNetCore/SigSpec.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
<PackageTags>SignalR Specification CodeGeneration</PackageTags>
</PropertyGroup>
<ItemGroup>
<None Remove="SigSpecUi\index.html" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="SigSpecUi\index.html" />
<EmbeddedResource Include="SigSpecUi\**\*" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
Expand All @@ -27,4 +24,4 @@
<ItemGroup>
<ProjectReference Include="..\SigSpec.Core\SigSpec.Core.csproj" />
</ItemGroup>
</Project>
</Project>
5 changes: 4 additions & 1 deletion src/SigSpec.AspNetCore/SigSpecSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
namespace SigSpec.AspNetCore.Middlewares
using Microsoft.AspNetCore.Http;

namespace SigSpec.AspNetCore.Middlewares
{
public class SigSpecSettings
{
/// <summary>Gets or sets the path to serve the SigSpec document (default: '/sigspec/{documentName}/sigspec.json').</summary>
public string Path { get; set; } = "/sigspec/{documentName}/sigspec.json";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to Route? What is the default in asp?


}
}
Binary file added src/SigSpec.AspNetCore/SigSpecUi/favicon.ico
Binary file not shown.
35 changes: 26 additions & 9 deletions src/SigSpec.AspNetCore/SigSpecUi/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Hello World!</title>
</head>
<body>
Hello World!
</body>
</html>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<link rel="icon" href="./favicon.ico" />
<title>SigSpecUI</title>
</head>

<body>
<noscript>
<strong>We're sorry but SigSpecUI doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<script>
window.sigSpecUiSettings = {
baseUrl: '{BaseUrl}',
route : '{Route}'
}
</script>

<div id="app"></div>
<script src="./app.js"></script>
<script src="./chunk-vendors.js"></script>
<link href="./app.css" rel="stylesheet" />
<link href="./chunk-vendors.css" rel="stylesheet" />
</body>
</html>
11 changes: 10 additions & 1 deletion src/SigSpec.AspNetCore/SigSpecUiSettings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
namespace SigSpec.AspNetCore
using Microsoft.AspNetCore.Http;

namespace SigSpec.AspNetCore
{
public class SigSpecUiSettings
{
public string Route { get; set; } = "/sigspec";

public string TransformHtml(string html, HttpRequest request)
{
html = html.Replace("{Route}", this.Route);
html = html.Replace("{BaseUrl}", request.Scheme + "://" + request.Host);
return html;
}
}
}
3 changes: 3 additions & 0 deletions src/SigSpec.UI/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> 1%
last 2 versions
not dead
15 changes: 15 additions & 0 deletions src/SigSpec.UI/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
root: true,
env: {
node: true
},
extends: ['plugin:vue/essential', 'eslint:recommended', '@vue/typescript/recommended'],
parserOptions: {
ecmaVersion: 2020
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
}
};
Loading