You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env pwsh
# 指定脚本解释器为PowerShell核心版pwsh
# 获取当前脚本所在目录的路径
# $MyInvocation.MyCommand.Definition 表示当前脚本的完整路径
# Split-Path 用于从该路径中提取目录部分
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
$exe=""
# 根据PowerShell版本和操作系统决定是否添加.exe扩展名
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
# 当PowerShell版本低于6.0或运行在Windows系统时使用.exe扩展名
# 解决Node.js的Windows和Linux版本安装在同一目录时的冲突问题
$exe=".exe"
}
$ret=0 # 用于存储命令的退出码
# 检查当前脚本目录下是否存在node可执行文件带对应扩展名
if (Test-Path "$basedir/node$exe") {
# 支持管道输入(若有输入通过管道传递给脚本)
if ($MyInvocation.ExpectingInput) {
# 将管道输入传递给node并执行flat的CLI脚本
$input | & "$basedir/node$exe" "$basedir/../flat/cli.js" $args
} else {
# 直接执行node和目标脚本传递命令行参数$args
& "$basedir/node$exe" "$basedir/../flat/cli.js" $args
}
$ret=$LASTEXITCODE # 获取上一条命令的退出码
} else {
# 若当前目录无node使用系统全局的node命令
# 同样支持管道输入
if ($MyInvocation.ExpectingInput) {
$input | & "node$exe" "$basedir/../flat/cli.js" $args
} else {
& "node$exe" "$basedir/../flat/cli.js" $args
}
$ret=$LASTEXITCODE # 获取全局node命令的退出码
}
exit $ret # 脚本退出,返回之前获取的退出码