From db3760d1a1704be93049992e19dca3996237643c Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 2 Jul 2026 15:18:08 +0800 Subject: refactor(run-scripts): reorder languages and prioritize .sh/.ps1 in listing --- run.ps1 | 148 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 74 insertions(+), 74 deletions(-) (limited to 'run.ps1') diff --git a/run.ps1 b/run.ps1 index 460343f..8b76260 100644 --- a/run.ps1 +++ b/run.ps1 @@ -2,33 +2,33 @@ $tools = @{} -if (Test-Path ".run/src/bin/*.cs") { - Get-ChildItem -Path ".run/src/bin/*.cs" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "cs"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.ps1") { + Get-ChildItem -Path ".run/src/bin/*.ps1" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "ps1"; Path = $_.FullName } } } -if (Test-Path ".run/src/bin/*.rs") { - Get-ChildItem -Path ".run/src/bin/*.rs" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "rs"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.cs") { + Get-ChildItem -Path ".run/src/bin/*.cs" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "cs"; Path = $_.FullName } } } -if (Test-Path ".run/src/bin/*.py") { - Get-ChildItem -Path ".run/src/bin/*.py" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "py"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.exe") { + Get-ChildItem -Path ".run/src/bin/*.exe" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "exe"; Path = $_.FullName } } } -if (Test-Path ".run/src/bin/*.ps1") { - Get-ChildItem -Path ".run/src/bin/*.ps1" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "ps1"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.go") { + Get-ChildItem -Path ".run/src/bin/*.go" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "go"; Path = $_.FullName } } } -if (Test-Path ".run/src/bin/*.rb") { - Get-ChildItem -Path ".run/src/bin/*.rb" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "rb"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.nim") { + Get-ChildItem -Path ".run/src/bin/*.nim" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "nim"; Path = $_.FullName } } } @@ -38,32 +38,32 @@ if (Test-Path ".run/src/bin/*.pl") { } } -if (Test-Path ".run/src/bin/*.go") { - Get-ChildItem -Path ".run/src/bin/*.go" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "go"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.py") { + Get-ChildItem -Path ".run/src/bin/*.py" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "py"; Path = $_.FullName } } } -if (Test-Path ".run/src/bin/*.zig") { - Get-ChildItem -Path ".run/src/bin/*.zig" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "zig"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.rb") { + Get-ChildItem -Path ".run/src/bin/*.rb" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "rb"; Path = $_.FullName } } } -if (Test-Path ".run/src/bin/*.nim") { - Get-ChildItem -Path ".run/src/bin/*.nim" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "nim"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.rs") { + Get-ChildItem -Path ".run/src/bin/*.rs" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "rs"; Path = $_.FullName } } } -if (Test-Path ".run/src/bin/*.exe") { - Get-ChildItem -Path ".run/src/bin/*.exe" | ForEach-Object { - $tools[$_.BaseName] = @{ Type = "exe"; Path = $_.FullName } +if (Test-Path ".run/src/bin/*.zig") { + Get-ChildItem -Path ".run/src/bin/*.zig" | ForEach-Object { + $tools[$_.BaseName] = @{ Type = "zig"; Path = $_.FullName } } } if ($args.Count -eq 0) { - $sorted = $tools.Keys | Sort-Object + $sorted = $tools.Keys | Sort-Object @{Expression={if ($tools[$_].Type -eq 'ps1') {0} else {1}}}, {$_} $total = $sorted.Count $num_w = $total.ToString().Length @@ -85,16 +85,16 @@ if ($args.Count -eq 0) { foreach ($name in $sorted) { $type = $tools[$name].Type $lang = switch ($type) { + "ps1" { "PowerShell" } "cs" { "C#" } + "exe" { "Binary" } + "go" { "Go" } + "nim" { "Nim" } + "pl" { "Perl" } "py" { "Python" } - "rs" { "Rust" } - "ps1" { "PowerShell" } "rb" { "Ruby" } - "pl" { "Perl" } - "go" { "Go" } + "rs" { "Rust" } "zig" { "Zig" } - "nim" { "Nim" } - "exe" { "Binary" } } $displayName = $name -replace '[_\-]', ' ' $entry = " " + $i.ToString().PadRight($num_w) + ") " + $displayName.PadRight($max_name) + " [$lang]" @@ -110,7 +110,7 @@ if ($args.Count -eq 0) { $target_name = $args[0] if ($target_name -match '^\d+$') { - $sorted = $tools.Keys | Sort-Object + $sorted = $tools.Keys | Sort-Object @{Expression={if ($tools[$_].Type -eq 'ps1') {0} else {1}}}, {$_} $idx = [int]$target_name - 1 if ($idx -ge 0 -and $idx -lt $sorted.Count) { $target_name = $sorted[$idx] @@ -145,27 +145,55 @@ switch ($info.Type) { "ps1" { & $info.Path @script_args } - "rb" { - ruby $info.Path $script_args + "cs" { + $temp_dir = ".run/target/csproj/$target_name" + $null = New-Item -ItemType Directory -Path $temp_dir -Force + + $props_content = @' + + + $(MSBuildThisFileDirectory)../../csharp/bin + $(MSBuildThisFileDirectory)../../csharp/obj + + +'@ + Set-Content -Path "$temp_dir/Directory.Build.props" -Value $props_content + + $csproj_content = @" + + + + Exe + net8.0 + enable + enable + + + +"@ + Set-Content -Path "$temp_dir/$target_name.csproj" -Value $csproj_content + Copy-Item -Path $info.Path -Destination "$temp_dir/Program.cs" -Force + + dotnet run --project "$temp_dir/$target_name.csproj" -- $script_args } - "pl" { - perl $info.Path $script_args + "exe" { + & $info.Path $script_args } "go" { go run $info.Path $script_args } - "zig" { - zig run $info.Path $script_args - } "nim" { nim r --hints:off $info.Path $script_args } - "exe" { - & $info.Path $script_args + "pl" { + perl $info.Path $script_args } "py" { python $info.Path $script_args } + "rb" { + ruby $info.Path $script_args + } "rs" { if (-not (Test-Path ".run/Cargo.toml")) { @" @@ -186,36 +214,8 @@ edition = "2024" } & $binary $script_args } - "cs" { - $temp_dir = ".run/target/csproj/$target_name" - $null = New-Item -ItemType Directory -Path $temp_dir -Force - - $props_content = @' - - - $(MSBuildThisFileDirectory)../../csharp/bin - $(MSBuildThisFileDirectory)../../csharp/obj - - -'@ - Set-Content -Path "$temp_dir/Directory.Build.props" -Value $props_content - - $csproj_content = @" - - - - Exe - net8.0 - enable - enable - - - -"@ - Set-Content -Path "$temp_dir/$target_name.csproj" -Value $csproj_content - Copy-Item -Path $info.Path -Destination "$temp_dir/Program.cs" -Force - - dotnet run --project "$temp_dir/$target_name.csproj" -- $script_args + "zig" { + zig run $info.Path $script_args } } -- cgit