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
4 changes: 2 additions & 2 deletions scripts/PublishToLocal.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $OutputEncoding = [System.Console]::OutputEncoding = [System.Console]::InputEnco

$commandLinePath = Join-Path $location "../src/Command/CommandLine";
$studioPath = Join-Path $location "../src/Studio/AterStudio";
$dotnetVersion = "net8.0"
$dotnetVersion = "net9.0"

try {
Set-Location $location
Expand Down Expand Up @@ -48,7 +48,7 @@ try {
$xml.Save($studioProjectPath)

# pack modules
& "./PackTemplate.ps1"
# & "./PackTemplate.ps1"

# build web project
if ($withStudio -eq $true) {
Expand Down
1 change: 1 addition & 0 deletions src/Command/Command.Share/Command.Share.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.4" />
<PackageReference Include="Spectre.Console" Version="0.50.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Definition\Share\Share.csproj" />
Expand Down
18 changes: 9 additions & 9 deletions src/Command/Command.Share/CommandRunner.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CodeGenerator;
using CodeGenerator;
using CodeGenerator.Helper;
using CodeGenerator.Models;
using Entity;
using Command.Share.Runners;
using Microsoft.Extensions.Logging;
using Share.Services;

Expand All @@ -25,8 +25,8 @@ public class CommandRunner(CodeGenService codeGen, CodeAnalysisService codeAnaly
public static async Task RunStudioAsync()
{
using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
ILogger<StudioCommand> studioLogger = loggerFactory.CreateLogger<StudioCommand>();
var studioCommand = new StudioCommand(studioLogger);
ILogger<StudioRunner> studioLogger = loggerFactory.CreateLogger<StudioRunner>();
var studioCommand = new StudioRunner(studioLogger);
await studioCommand.RunStudioAsync();
}

Expand All @@ -36,8 +36,8 @@ public static async Task RunStudioAsync()
public static void UpdateStudio()
{
using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
ILogger<StudioCommand> studioLogger = loggerFactory.CreateLogger<StudioCommand>();
var studioCommand = new StudioCommand(studioLogger);
ILogger<StudioRunner> studioLogger = loggerFactory.CreateLogger<StudioRunner>();
var studioCommand = new StudioRunner(studioLogger);
studioCommand.UpdateStudio();
}

Expand All @@ -52,7 +52,7 @@ public async Task GenerateNgAsync(string url = "", string output = "")
try
{
_logger.LogInformation("🚀 Generating ts models and ng services...");
RequestCommand cmd = new(url, output, RequestLibType.NgHttp);
RequestRunner cmd = new(url, output, RequestLibType.NgHttp);
await cmd.RunAsync();
}
catch (WebException webExp)
Expand All @@ -77,7 +77,7 @@ public async Task GenerateRequestAsync(string url = "", string output = "", Requ
try
{
_logger.LogInformation($"🚀 Generating ts models and {type} request services...");
RequestCommand cmd = new(url, output, type);
RequestRunner cmd = new(url, output, type);
await cmd.RunAsync();
}
catch (WebException webExp)
Expand Down Expand Up @@ -171,7 +171,7 @@ public async Task GenerateApiAsync(string entityPath, string sharePath = "",
/// <returns></returns>
public static async Task GenerateCSharpApiClientAsync(string swaggerUrl, string outputPath, LanguageType language = LanguageType.CSharp)
{
ApiClientCommand cmd = new(swaggerUrl, outputPath, language);
ApiClientRunner cmd = new(swaggerUrl, outputPath, language);
await cmd.RunAsync();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Command/Command.Share/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
global using Command.Share.Commands;
global using Framework.Common.Utils;
global using Microsoft.OpenApi.Models;
global using Microsoft.OpenApi.Readers;
global using Microsoft.OpenApi.Readers;
global using Spectre.Console;
48 changes: 48 additions & 0 deletions src/Command/Command.Share/OutputHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

namespace Command.Share;
public class OutputHelper
{
public static void ShowLogo()
{
string logo = """
_____ _____ __ __
| __ \ | __ \ \ \ / /
| | | | | |__) | \ \_/ /
| | | | | _ / \ /
| |__| | | | \ \ | |
|_____/ |_| \_\ |_|
""";
string sign1 = " —→ for freedom 🗽 ←—";
string sign2 = " 🌐 [link]https://dusi.dev/docs[/]";

AnsiConsole.MarkupLine($"[bold green]{logo}[/]");
AnsiConsole.MarkupLine($"[blue]{sign2}[/]");
AnsiConsole.MarkupLine("");
AnsiConsole.MarkupLine($"[yellow]{sign1}[/]");
}

public static void ShowError(string message)
{
AnsiConsole.MarkupLine($"[red]✖️ {message}[/]");
}

public static void ShowSuccess(string message)
{
AnsiConsole.MarkupLine($"[green]✔️ {message}[/]");
}

public static void ShowInfo(string message)
{
AnsiConsole.MarkupLine($"ℹ️ {message}");
}
}

public class SubCommand
{
public const string New = "new";
public const string Studio = "studio";
public const string Update = "update";
public const string NewDes = "NewDes";
public const string StudioDes = "StudioDes";
public const string StudioUpdateDes = "StudioUpdateDes";
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using CodeGenerator.Models;
using CodeGenerator.Models;
using Share.Infrastructure.Helper;
namespace Command.Share.Commands;
namespace Command.Share.Runners;
/// <summary>
/// 客户端请求生成
/// </summary>
public class ApiClientCommand : CommandBase
public class ApiClientRunner : CommandBase
{
/// <summary>
/// swagger文档链接
Expand All @@ -24,7 +24,7 @@ public class ApiClientCommand : CommandBase
/// </summary>
public string OutputPath { get; set; }

public ApiClientCommand(string docUrl, string output, LanguageType languageType)
public ApiClientRunner(string docUrl, string output, LanguageType languageType)
{
DocUrl = docUrl;
DocName = docUrl.Split('/').Reverse().Skip(1).First();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers;

namespace Command.Share.Commands;
public class DocCommand : CommandBase
public class DocRunner : CommandBase
{
public string DocUrl { get; set; } = default!;
public OpenApiDocument? ApiDocument { get; set; }

public string OutputPath { get; set; }

public DocCommand(string docUrl, string output)
public DocRunner(string docUrl, string output)
{
DocUrl = docUrl;
OutputPath = Path.Combine(output);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using CodeGenerator.Models;
namespace Command.Share.Commands;
using CodeGenerator.Models;
namespace Command.Share.Runners;

/// <summary>
/// 前端ts请求生成命令
/// </summary>
public class RequestCommand : CommandBase
public class RequestRunner : CommandBase
{
/// <summary>
/// swagger文档链接
Expand All @@ -21,7 +21,7 @@ public class RequestCommand : CommandBase

public string OutputPath { get; set; }

public RequestCommand(string docUrl, string output, RequestLibType libType)
public RequestRunner(string docUrl, string output, RequestLibType libType)
{
DocUrl = docUrl;
OutputPath = output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
using Microsoft.Extensions.Logging;
using Share.Infrastructure.Helper;

namespace Command.Share.Commands;
public class StudioCommand(ILogger<StudioCommand> logger)
namespace Command.Share.Runners;
public class StudioRunner(ILogger<StudioRunner> logger)
{
private readonly ILogger<StudioCommand> _logger = logger;
private readonly ILogger<StudioRunner> _logger = logger;

public async Task RunStudioAsync()
{
Expand Down Expand Up @@ -112,7 +112,7 @@ public void UpdateStudio()
"Microsoft.Extensions.Configuration.Abstractions",
"Microsoft.Extensions.DependencyInjection.Abstractions",
"Microsoft.Extensions.DependencyInjection",
"Microsoft.Extensions.Logging.Abstractions",
"Microsoft.Extensions.Logging.Abstractions",1
"Microsoft.Extensions.Logging",
"Microsoft.Extensions.Options",
"Microsoft.Extensions.Primitives",
Expand Down
3 changes: 2 additions & 1 deletion src/Command/CommandLine/CommandLine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<PackAsTool>true</PackAsTool>
<ToolCommandName>dry</ToolCommandName>
<ToolCommandName>ater</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<AssemblyVersion>10.0.0</AssemblyVersion>
<PackageId>ater.dry</PackageId>
Expand Down Expand Up @@ -45,6 +45,7 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Spectre.Console.Cli" Version="0.50.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>
<ItemGroup>
Expand Down
19 changes: 19 additions & 0 deletions src/Command/CommandLine/Commands/AddCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Spectre.Console.Cli;

namespace CommandLine.Commands;
public class AddCommand : AsyncCommand<AddCommand.Settings>
{
public class Settings : CommandSettings
{
[CommandArgument(0, "[name]")]
public string Name { get; set; } = string.Empty;
[CommandOption("--path")]
public string Path { get; set; } = string.Empty;
}


public override Task<int> ExecuteAsync(CommandContext context, Settings settings)
{
throw new NotImplementedException();
}
}
17 changes: 17 additions & 0 deletions src/Command/CommandLine/Commands/GenerateCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

namespace CommandLine.Commands;
public class GenerateCommand : AsyncCommand<GenerateCommand.Settings>
{
public class Settings : CommandSettings
{
[CommandArgument(0, "[name]")]
public string Name { get; set; } = string.Empty;
[CommandOption("--path")]
public string Path { get; set; } = string.Empty;
}
public override Task<int> ExecuteAsync(CommandContext context, Settings settings)
{
throw new NotImplementedException();
}
}

19 changes: 19 additions & 0 deletions src/Command/CommandLine/Commands/NewCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Spectre.Console.Cli;

namespace CommandLine.Commands;
public class NewCommand : AsyncCommand<NewCommand.Settings>
{
public class Settings : CommandSettings
{
[CommandArgument(0, "[name]")]
public string Name { get; set; } = string.Empty;
[CommandOption("--path")]
public string Path { get; set; } = string.Empty;
}


public override Task<int> ExecuteAsync(CommandContext context, Settings settings)
{
throw new NotImplementedException();
}
}
15 changes: 15 additions & 0 deletions src/Command/CommandLine/Commands/StudioCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace CommandLine.Commands;
public class StudioCommand : AsyncCommand<StudioCommand.Settings>
{
public class Settings : CommandSettings
{

}

public override async Task<int> ExecuteAsync(CommandContext context, Settings settings)
{
await CommandRunner.RunStudioAsync();
return 0;
}
}

53 changes: 53 additions & 0 deletions src/Command/CommandLine/DITypeRegistrar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace CommandLine;
using System;
using Spectre.Console.Cli;

public sealed class DITypeRegistrar : ITypeRegistrar
{
private readonly IServiceProvider _serviceProvider;

public DITypeRegistrar(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}

public void Register(Type service, Type implementation)
{
}

public void RegisterInstance(Type service, object implementation)
{
}

public void RegisterLazy(Type service, Func<object> factory)
{
}

public ITypeResolver Build()
{
return new DITypeResolver(_serviceProvider);
}
}

public sealed class DITypeResolver : ITypeResolver, IDisposable
{
private readonly IServiceProvider _serviceProvider;

public DITypeResolver(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}

public object? Resolve(Type? type)
{
return type == null ? null : _serviceProvider.GetService(type);
}

public void Dispose()
{
if (_serviceProvider is IDisposable disposable)
{
disposable.Dispose();
}
}
}
5 changes: 3 additions & 2 deletions src/Command/CommandLine/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
global using System;
global using System;
global using System.Threading.Tasks;
global using CodeGenerator.Generate;
global using Command.Share;
global using Command.Share.Commands;
global using Command.Share.Runners;
global using Spectre.Console.Cli;
Loading