dsh-ssh-tunnel 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,12 +6,94 @@
6
6
  # dsh plugin --profile <profile> add "link:<repo>"
7
7
  # 由 DSH 自己登记 dsh.profile.bundles 并解析依赖(ssh2 / @xterm/*),仓库改动无需再同步。
8
8
  #
9
- # 环境:DSH_PROFILE(默认 web)、DSH_CMD(默认 dsh);DSH_HOME 由 dsh 自行解析。
9
+ # 用法:
10
+ # bash scripts/sync-to-dsh.sh [-p|--profile <名称>] [--dry-run] [-h|--help]
11
+ #
12
+ # -p/--profile 目标 profile;缺省读 DSH_PROFILE 环境变量;两者皆无则报错并列出实存 profile。
13
+ # --dry-run 只打印将执行的命令,不做任何改动。
14
+ #
15
+ # 环境:DSH_PROFILE、DSH_CMD(默认 dsh)、DSH_HOME(默认 ~/.dsh,用于列出实存 profile)。
16
+ # MSYS/git-bash 下会用 cygpath -w 把仓库路径转成 Windows 形态再拼 link: spec。
10
17
  set -euo pipefail
18
+
11
19
  ROOT="$(cd "$(dirname "$0")/.." && pwd)"
12
- PROFILE="${DSH_PROFILE:-web}"
20
+ DSH_HOME="${DSH_HOME:-${HOME:-${USERPROFILE:-}}/.dsh}"
13
21
  DSH_CMD="${DSH_CMD:-dsh}"
14
22
 
23
+ usage() {
24
+ cat <<'EOF'
25
+ 把本仓库作为本地 link 插件接入 DSH profile(开发用)
26
+
27
+ 用法:bash scripts/sync-to-dsh.sh [-p|--profile <名称>] [--dry-run] [-h|--help]
28
+
29
+ -p|--profile <名> 目标 profile;缺省读 DSH_PROFILE 环境变量(两者皆无则报错并列出实存 profile)
30
+ --dry-run 只打印将执行的命令,不做任何改动
31
+ -h|--help 显示本帮助
32
+
33
+ 环境:DSH_PROFILE、DSH_CMD(默认 dsh)、DSH_HOME(默认 ~/.dsh)
34
+ EOF
35
+ }
36
+
37
+ list_profiles() {
38
+ if [ ! -d "$DSH_HOME/profiles" ]; then
39
+ echo " (未找到 $DSH_HOME/profiles)"
40
+ return 0
41
+ fi
42
+ local any="" d
43
+ for d in "$DSH_HOME"/profiles/*/; do
44
+ [ -d "$d" ] || continue
45
+ any=1
46
+ echo " - $(basename "$d")"
47
+ done
48
+ [ -n "$any" ] || echo " ($DSH_HOME/profiles 下没有 profile)"
49
+ }
50
+
51
+ PROFILE="${DSH_PROFILE:-}"
52
+ DRY_RUN=false
53
+ SHOW_HELP=false
54
+
55
+ while [ $# -gt 0 ]; do
56
+ case "$1" in
57
+ -p|--profile)
58
+ [ $# -ge 2 ] || { echo "[error] $1 需要一个名称(用 -h 查看用法)" >&2; exit 2; }
59
+ PROFILE="$2"; shift 2 ;;
60
+ --profile=*) PROFILE="${1#*=}"; shift ;;
61
+ --dry-run) DRY_RUN=true; shift ;;
62
+ -h|--help) SHOW_HELP=true; shift ;;
63
+ -*) echo "[error] 未知参数: $1(用 -h 查看用法)" >&2; exit 2 ;;
64
+ *) echo "[error] 多余的位置参数: $1(用 -h 查看用法)" >&2; exit 2 ;;
65
+ esac
66
+ done
67
+
68
+ if [ "$SHOW_HELP" = true ]; then usage; exit 0; fi
69
+
70
+ if [ -z "$PROFILE" ]; then
71
+ echo "[error] 未指定 profile(用 -p/--profile 或环境变量 DSH_PROFILE)。$DSH_HOME/profiles/ 下实存 profile:" >&2
72
+ list_profiles >&2
73
+ exit 2
74
+ fi
75
+
76
+ PROFILE_DIR="$DSH_HOME/profiles/$PROFILE"
77
+ if [ ! -d "$PROFILE_DIR" ]; then
78
+ echo "[error] profile 不存在: $PROFILE($PROFILE_DIR)。$DSH_HOME/profiles/ 下实存 profile:" >&2
79
+ list_profiles >&2
80
+ exit 2
81
+ fi
82
+
83
+ # MSYS/git-bash/Cygwin:link: spec 需要 Windows 路径形态
84
+ LINK_TARGET="$ROOT"
85
+ if command -v cygpath >/dev/null 2>&1 && uname -s 2>/dev/null | grep -qiE 'MINGW|MSYS|CYGWIN'; then
86
+ LINK_TARGET="$(cygpath -w "$ROOT")"
87
+ fi
88
+ ADD_SPEC="link:$LINK_TARGET"
89
+
90
+ if [ "$DRY_RUN" = true ]; then
91
+ echo "[dry-run] 1) node --check \"$ROOT/lib/index.js\""
92
+ echo "[dry-run] 2) node \"$ROOT/scripts/smoke-test.mjs\""
93
+ printf '[dry-run] 3) %s plugin --profile %s add "%s"\n' "$DSH_CMD" "$PROFILE" "$ADD_SPEC"
94
+ exit 0
95
+ fi
96
+
15
97
  command -v node >/dev/null 2>&1 || { echo "需要 node(>= 20)" >&2; exit 1; }
16
98
  NODE_MAJOR="$(node -p 'process.versions.node.split(".")[0]' 2>/dev/null)" || NODE_MAJOR=0
17
99
  [ "${NODE_MAJOR:-0}" -ge 20 ] || { echo "Node.js $(node -v) 过旧(需要 ≥ 20)" >&2; exit 1; }
@@ -22,11 +104,11 @@ node "$ROOT/scripts/smoke-test.mjs"
22
104
 
23
105
  if ! command -v "$DSH_CMD" >/dev/null 2>&1; then
24
106
  echo "未找到 $DSH_CMD(可用 DSH_CMD 指定);手动执行:" >&2
25
- echo " dsh plugin --profile $PROFILE add \"link:$ROOT\"" >&2
107
+ printf ' %s plugin --profile %s add "%s"\n' "$DSH_CMD" "$PROFILE" "$ADD_SPEC" >&2
26
108
  exit 1
27
109
  fi
28
110
 
29
111
  echo "== 接入 profile ${PROFILE}(link) =="
30
- "$DSH_CMD" plugin --profile "$PROFILE" add "link:$ROOT"
31
- echo "已接入:$ROOT"
112
+ "$DSH_CMD" plugin --profile "$PROFILE" add "$ADD_SPEC"
113
+ printf '已接入:%s\n' "$ROOT"
32
114
  echo "下一步:重启 dsh web,并硬刷新浏览器。"