-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:riganti/dotvvm into feature/azure-p…
…ipelines
- Loading branch information
Showing
303 changed files
with
7,135 additions
and
13,221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.IO; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace DotVVM.CommandLine | ||
{ | ||
public class ApiClientDefinition | ||
{ | ||
public const string DefaultSwaggerFile = "openapi.json"; | ||
public const string DefaultCSharpClient = "ApiClient.cs"; | ||
public const string DefaultTypeScriptClient = "ApiClient.ts"; | ||
public const string DefaultInvalidNamespace = "Invalid.Namespace"; | ||
|
||
[JsonPropertyName("swaggerFile")] | ||
public Uri SwaggerFile { get; set; } | ||
= new Uri(Path.Combine(Directory.GetCurrentDirectory(), DefaultSwaggerFile)); | ||
|
||
[JsonPropertyName("csharpClient")] | ||
public string CSharpClient { get; set; } = DefaultCSharpClient; | ||
|
||
[JsonPropertyName("typescriptClient")] | ||
public string TypescriptClient { get; set; } = DefaultTypeScriptClient; | ||
|
||
[JsonPropertyName("namespace")] | ||
public string Namespace { get; set; } = DefaultInvalidNamespace; | ||
|
||
[JsonPropertyName("compileTypescript")] | ||
[DefaultValue(true)] | ||
public bool CompileTypescript { get; set; } = true; | ||
|
||
[JsonPropertyName("generateWrapperClass")] | ||
[DefaultValue(true)] | ||
public bool GenerateWrapperClass { get; set; } = true; | ||
|
||
[DefaultValue(false)] | ||
[JsonPropertyName("isSingleClient")] | ||
public bool IsSingleClient { get; set; } | ||
|
||
[JsonPropertyName("fetchOptions")] | ||
public ApiClientFetchOptions FetchOptions { get; set; } = new ApiClientFetchOptions(); | ||
} | ||
} |
13 changes: 4 additions & 9 deletions
13
...andLine/Metadata/ApiClientFetchOptions.cs → ...tVVM.CommandLine/ApiClientFetchOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace DotVVM.CommandLine.Metadata | ||
namespace DotVVM.CommandLine | ||
{ | ||
public class ApiClientFetchOptions | ||
{ | ||
|
||
[DefaultValue("same-origin")] | ||
[JsonProperty("credentials")] | ||
[JsonPropertyName("credentials")] | ||
public string Credentials { get; set; } = "same-origin"; | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
using System.Collections.Generic; | ||
using System.CommandLine.Builder; | ||
using System.CommandLine.Invocation; | ||
using System.CommandLine.Parsing; | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.IO; | ||
using System.Linq; | ||
using DotVVM.CommandLine; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Microsoft.Extensions.Logging.Console; | ||
|
||
namespace System.CommandLine | ||
{ | ||
public static class CommandLineExtensions | ||
{ | ||
public const string VerboseAlias = "--verbose"; | ||
public const string DebuggerBreakAlias = "--debugger-break"; | ||
public const string TargetArg = "target"; | ||
|
||
public static ILoggerFactory Factory = new NullLoggerFactory(); | ||
|
||
private static readonly Option<bool> verboseOption = new Option<bool>( | ||
aliases: new[] { "-v", VerboseAlias }, | ||
description: "Print more verbose output"); | ||
|
||
private static readonly Option<bool> debuggerBreakOption = new Option<bool>( | ||
alias: DebuggerBreakAlias, | ||
description: "Breaks to let a debugger attach to the process"); | ||
|
||
private static readonly Argument<FileSystemInfo> targetArgument = new Argument<FileSystemInfo>( | ||
name: TargetArg, | ||
description: "Path to a DotVVM project") | ||
{ | ||
Arity = ArgumentArity.ZeroOrOne | ||
}; | ||
|
||
public static void AddRange(this Command command, params Symbol[] symbols) | ||
{ | ||
foreach (var symbol in symbols) | ||
{ | ||
command.Add(symbol); | ||
} | ||
} | ||
|
||
public static void AddVerboseOption(this Command command) | ||
{ | ||
command.AddGlobalOption(verboseOption); | ||
} | ||
|
||
public static void AddDebuggerBreakOption(this Command command) | ||
{ | ||
command.AddGlobalOption(debuggerBreakOption); | ||
} | ||
|
||
public static void AddTargetArgument(this Command command) | ||
{ | ||
command.AddArgument(targetArgument); | ||
} | ||
|
||
public static CommandLineBuilder UseLogging(this CommandLineBuilder builder) | ||
{ | ||
return builder.UseMiddleware(async (c, next) => | ||
{ | ||
var logLevel = c.ParseResult.ValueForOption(verboseOption) | ||
? LogLevel.Debug | ||
: LogLevel.Information; | ||
Factory = LoggerFactory.Create(b => b.AddConsole().SetMinimumLevel(logLevel)); | ||
var loggerName = GetCommandPath(c.ParseResult.CommandResult); | ||
c.BindingContext.AddService(_ => Factory.CreateLogger(loggerName)); | ||
await next(c); | ||
Factory.Dispose(); | ||
}); | ||
} | ||
|
||
public static CommandLineBuilder UseDotvvmMetadata(this CommandLineBuilder builder) | ||
{ | ||
return builder.UseMiddleware(async (c, next) => | ||
{ | ||
var target = FindTarget(c.ParseResult); | ||
if (target is object) | ||
{ | ||
var logger = Factory.CreateLogger("Project Metadata"); | ||
var csproj = DotvvmProject.FindProjectFile(target.FullName); | ||
if (csproj is null) | ||
{ | ||
logger.LogError($"No project could be found in '{target}'."); | ||
c.ResultCode = 1; | ||
return; | ||
} | ||
var project = DotvvmProject.FromCsproj(csproj.FullName, logger); | ||
if (project is null) | ||
{ | ||
c.ResultCode = 1; | ||
return; | ||
} | ||
c.BindingContext.AddService(_ => project); | ||
} | ||
await next(c); | ||
}); | ||
} | ||
|
||
public static CommandLineBuilder UseDebuggerBreak(this CommandLineBuilder builder) | ||
{ | ||
return builder.UseMiddleware(async (c, next) => | ||
{ | ||
var shouldBreak = c.ParseResult.ValueForOption<bool>(DebuggerBreakAlias); | ||
if (shouldBreak) | ||
{ | ||
var logger = Factory.CreateLogger("debugging"); | ||
var pid = Diagnostics.Process.GetCurrentProcess().Id; | ||
logger.LogInformation($"Started with PID '{pid}'. Waiting for debugger to attach."); | ||
Debugger.Break(); | ||
} | ||
await next(c); | ||
}); | ||
} | ||
|
||
private static FileSystemInfo? FindTarget(ParseResult result) | ||
{ | ||
CommandResult? current = result.CommandResult; | ||
while (current is object) | ||
{ | ||
var target = current.Command.Arguments.FirstOrDefault(c => c.Name == TargetArg); | ||
if (target is object) | ||
{ | ||
var fsInfo = result.ValueForArgument((Argument<FileSystemInfo>)target); | ||
fsInfo ??= new DirectoryInfo(Environment.CurrentDirectory); | ||
return fsInfo; | ||
} | ||
current = current.Parent as CommandResult; | ||
} | ||
return null; | ||
} | ||
|
||
private static string GetCommandPath(CommandResult result) | ||
{ | ||
var names = new List<string>(); | ||
CommandResult? current = result; | ||
while (current is object) | ||
{ | ||
names.Add(current.Symbol.Name); | ||
current = current.Parent as CommandResult; | ||
} | ||
names.Reverse(); | ||
return string.Join(" ", names); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.