diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-02 15:18:08 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-02 15:18:29 +0800 |
| commit | db3760d1a1704be93049992e19dca3996237643c (patch) | |
| tree | 2c00470900ea87ec06cacd4cd7419001231855f9 /run.ps1 | |
| parent | a93bf4ec45b1187185942d79828ab50ebbd8b828 (diff) | |
refactor(run-scripts): reorder languages and prioritize .sh/.ps1 in
listing
Diffstat (limited to 'run.ps1')
| -rw-r--r-- | run.ps1 | 148 |
1 files changed, 74 insertions, 74 deletions
@@ -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 = @' +<Project> + <PropertyGroup> + <BaseOutputPath>$(MSBuildThisFileDirectory)../../csharp/bin</BaseOutputPath> + <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)../../csharp/obj</BaseIntermediateOutputPath> + </PropertyGroup> +</Project> +'@ + Set-Content -Path "$temp_dir/Directory.Build.props" -Value $props_content + + $csproj_content = @" +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> +"@ + 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 = @' -<Project> - <PropertyGroup> - <BaseOutputPath>$(MSBuildThisFileDirectory)../../csharp/bin</BaseOutputPath> - <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)../../csharp/obj</BaseIntermediateOutputPath> - </PropertyGroup> -</Project> -'@ - Set-Content -Path "$temp_dir/Directory.Build.props" -Value $props_content - - $csproj_content = @" -<Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <OutputType>Exe</OutputType> - <TargetFramework>net8.0</TargetFramework> - <ImplicitUsings>enable</ImplicitUsings> - <Nullable>enable</Nullable> - </PropertyGroup> - -</Project> -"@ - 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 } } |
