From 350e4a575338e116f4aa7e11478cf3bbc823f535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E6=98=8A=E5=BC=98?= Date: Tue, 21 Jan 2025 19:35:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor(tool):=20=E4=BD=BF=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E6=94=AF=E6=8C=81=E8=B7=A8=E5=B9=B3=E5=8F=B0=E8=BF=90?= =?UTF-8?q?=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 AddModuleCommand 和 CloneCommand 中增加了对操作系统类型的判断 - 为 Windows、macOS 和 Linux 系统分别设置了不同的进程启动信息 -优化了路径组合方式,使用 Path.Combine 以确保跨平台兼容性 --- .../Yi.Abp.Tool/Commands/AddModuleCommand.cs | 18 ++++++++++++++---- .../tool/Yi.Abp.Tool/Commands/CloneCommand.cs | 16 +++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/AddModuleCommand.cs b/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/AddModuleCommand.cs index d1e9b1dc..d6578c90 100644 --- a/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/AddModuleCommand.cs +++ b/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/AddModuleCommand.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.CommandLineUtils; @@ -41,7 +42,7 @@ namespace Yi.Abp.Tool.Commands CheckFirstSlnPath(slnPath); var dotnetSlnCommandPart1 = $"dotnet sln \"{slnPath}\" add \"{modulePath}\\{moduleName}."; var dotnetSlnCommandPart2 = new List() { "Application", "Application.Contracts", "Domain", "Domain.Shared", "SqlSugarCore" }; - var paths = dotnetSlnCommandPart2.Select(x => $@"{modulePath}\{moduleName}." + x).ToArray(); + var paths = dotnetSlnCommandPart2.Select(x => Path.Combine(modulePath, $"{moduleName}.{x}")).ToArray(); CheckPathExist(paths); var cmdCommands = dotnetSlnCommandPart2.Select(x => dotnetSlnCommandPart1 + x+"\"").ToArray(); @@ -81,15 +82,24 @@ namespace Yi.Abp.Tool.Commands { ProcessStartInfo psi = new ProcessStartInfo { - FileName = "cmd.exe", - Arguments = $"/c chcp 65001&{string.Join("&", cmdCommands)}", RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, UseShellExecute = false }; - + // 判断操作系统 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + psi.FileName = "cmd.exe"; + psi.Arguments = $"/c chcp 65001&{string.Join("&", cmdCommands)}"; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + psi.FileName = "/bin/bash"; + psi.Arguments = $"-c \"{string.Join("; ", cmdCommands)}\""; + } + Process proc = new Process { StartInfo = psi diff --git a/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/CloneCommand.cs b/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/CloneCommand.cs index 00802bc9..d959e170 100644 --- a/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/CloneCommand.cs +++ b/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/CloneCommand.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.CommandLineUtils; @@ -35,15 +36,24 @@ namespace Yi.Abp.Tool.Commands { ProcessStartInfo psi = new ProcessStartInfo { - FileName = "cmd.exe", - Arguments = $"/c chcp 65001&{string.Join("&", cmdCommands)}", RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, UseShellExecute = false }; - + // 判断操作系统 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + psi.FileName = "cmd.exe"; + psi.Arguments = $"/c chcp 65001&{string.Join("&", cmdCommands)}"; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + psi.FileName = "/bin/bash"; + psi.Arguments = $"-c \"{string.Join("; ", cmdCommands)}\""; + } + Process proc = new Process { StartInfo = psi From b9866af6cda5c1072817d72946418faeffd9fff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E6=98=8A=E5=BC=98?= Date: Wed, 22 Jan 2025 17:58:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor(tool):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=B7=BB=E5=8A=A0=E5=91=BD=E4=BB=A4=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 优化了路径组合的方式,使代码更加简洁 - 修复AddModule在mac/linux下只能添加一个文件夹的问题 --- .../tool/Yi.Abp.Tool/Commands/AddModuleCommand.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/AddModuleCommand.cs b/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/AddModuleCommand.cs index d6578c90..6540a976 100644 --- a/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/AddModuleCommand.cs +++ b/Yi.Abp.Net8/tool/Yi.Abp.Tool/Commands/AddModuleCommand.cs @@ -40,12 +40,11 @@ namespace Yi.Abp.Tool.Commands } CheckFirstSlnPath(slnPath); - var dotnetSlnCommandPart1 = $"dotnet sln \"{slnPath}\" add \"{modulePath}\\{moduleName}."; - var dotnetSlnCommandPart2 = new List() { "Application", "Application.Contracts", "Domain", "Domain.Shared", "SqlSugarCore" }; - var paths = dotnetSlnCommandPart2.Select(x => Path.Combine(modulePath, $"{moduleName}.{x}")).ToArray(); + var dotnetSlnCommandPart = new List() { "Application", "Application.Contracts", "Domain", "Domain.Shared", "SqlSugarCore" }; + var paths = dotnetSlnCommandPart.Select(x => Path.Combine(modulePath, $"{moduleName}.{x}")).ToArray(); CheckPathExist(paths); - - var cmdCommands = dotnetSlnCommandPart2.Select(x => dotnetSlnCommandPart1 + x+"\"").ToArray(); + + var cmdCommands = dotnetSlnCommandPart.Select(x => $"dotnet sln \"{slnPath}\" add \"{Path.Combine(modulePath, $"{moduleName}.{x}")}\"").ToArray(); StartCmd(cmdCommands); Console.WriteLine("恭喜~模块添加成功!");