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.

27 lines
1.2 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.

#!/bin/sh
# 指定脚本解释器为sh
# 获取当前脚本所在目录的绝对路径
# 1. "$0" 表示当前脚本的文件名
# 2. sed -e 's,\\,/,g' 将路径中的反斜杠(\)替换为斜杠(/)适配Windows系统路径格式
# 3. dirname 提取目录部分,得到脚本所在的目录路径
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
# 判断操作系统类型处理Windows类Unix环境如Git Bash的路径转换
# uname 命令返回操作系统名称匹配CYGWIN、MINGW、MSYS等环境
# cygpath -w 将Unix风格路径转换为Windows风格路径例如将/c/xxx转换为C:\xxx
case `uname` in
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
esac
# 检查当前目录下是否存在可执行的node程序
if [ -x "$basedir/node" ]; then
# 若存在本地node使用该node执行flat的CLI脚本
# exec 用node进程替换当前shell进程避免创建额外子进程
# "$basedir/../flat/cli.js" 是flat的命令行入口脚本相对路径
# "$@" 传递所有命令行参数给目标脚本
exec "$basedir/node" "$basedir/../flat/cli.js" "$@"
else
# 若本地无node使用系统全局的node命令执行目标脚本
exec node "$basedir/../flat/cli.js" "$@"
fi