@lingjingai/lj-awb-cli-pre 0.4.0 → 0.4.5

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.
@@ -1,10 +1,112 @@
1
1
  #!/usr/bin/env bash
2
2
  set -euo pipefail
3
3
 
4
- if command -v lj-awb >/dev/null 2>&1; then
5
- printf 'lj-awb\n'
6
- exit 0
4
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
5
+ SKILL_DIR="$(cd "$SCRIPT_DIR/.." >/dev/null 2>&1 && pwd)"
6
+ VERSION_FILE="$SKILL_DIR/VERSION"
7
+ COMPAT_FILE="$SKILL_DIR/compat.json"
8
+
9
+ read_json_string() {
10
+ local key="$1"
11
+ local file="$2"
12
+ sed -n "s/.*\"$key\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/p" "$file" 2>/dev/null | head -1
13
+ }
14
+
15
+ normalize_version() {
16
+ local version="${1#v}"
17
+ version="${version%%[-+]*}"
18
+ printf '%s' "$version"
19
+ }
20
+
21
+ semver_ge() {
22
+ local current required
23
+ current="$(normalize_version "$1")"
24
+ required="$(normalize_version "$2")"
25
+
26
+ local current_major current_minor current_patch
27
+ local required_major required_minor required_patch
28
+ IFS=. read -r current_major current_minor current_patch <<< "$current"
29
+ IFS=. read -r required_major required_minor required_patch <<< "$required"
30
+
31
+ current_major="${current_major:-0}"
32
+ current_minor="${current_minor:-0}"
33
+ current_patch="${current_patch:-0}"
34
+ required_major="${required_major:-0}"
35
+ required_minor="${required_minor:-0}"
36
+ required_patch="${required_patch:-0}"
37
+
38
+ if (( current_major != required_major )); then
39
+ (( current_major > required_major ))
40
+ return
41
+ fi
42
+ if (( current_minor != required_minor )); then
43
+ (( current_minor > required_minor ))
44
+ return
45
+ fi
46
+ (( current_patch >= required_patch ))
47
+ }
48
+
49
+ find_lj_awb() {
50
+ if command -v lj-awb >/dev/null 2>&1; then
51
+ command -v lj-awb
52
+ return 0
53
+ fi
54
+
55
+ if command -v npm >/dev/null 2>&1; then
56
+ local npm_prefix npm_bin
57
+ npm_prefix="$(npm prefix -g 2>/dev/null || true)"
58
+ npm_bin="$npm_prefix/bin/lj-awb"
59
+ if [ -n "$npm_prefix" ] && [ -x "$npm_bin" ]; then
60
+ printf '%s\n' "$npm_bin"
61
+ return 0
62
+ fi
63
+ fi
64
+
65
+ return 1
66
+ }
67
+
68
+ command_version() {
69
+ local cmd="$1"
70
+ "$cmd" --version 2>/dev/null | grep -Eo 'v?[0-9]+(\.[0-9]+){2}([-+][0-9A-Za-z.-]+)?' | head -1
71
+ }
72
+
73
+ SKILL_VERSION="$(cat "$VERSION_FILE" 2>/dev/null || printf '0.4.0')"
74
+ MIN_CLI_VERSION="$(read_json_string minCliVersion "$COMPAT_FILE")"
75
+ MIN_CLI_VERSION="${MIN_CLI_VERSION:-$SKILL_VERSION}"
76
+ CLI_VERSION="${LINGJING_AWB_CLI_VERSION:-$MIN_CLI_VERSION}"
77
+ CLI_PACKAGE="${LINGJING_AWB_CLI_PACKAGE:-@lingjingai/lj-awb-cli}"
78
+ CLI_PACKAGE_SPEC="${LINGJING_AWB_CLI_PACKAGE_SPEC:-$CLI_PACKAGE@$CLI_VERSION}"
79
+
80
+ if LJ_AWB_CMD="$(find_lj_awb)"; then
81
+ INSTALLED_VERSION="$(command_version "$LJ_AWB_CMD" || true)"
82
+ if [ -n "$INSTALLED_VERSION" ] && semver_ge "$INSTALLED_VERSION" "$MIN_CLI_VERSION"; then
83
+ printf '%s\n' "$LJ_AWB_CMD"
84
+ exit 0
85
+ fi
86
+
87
+ printf 'Found lj-awb %s, but this skill requires >= %s.\n' "${INSTALLED_VERSION:-unknown}" "$MIN_CLI_VERSION" >&2
88
+ fi
89
+
90
+ if [ "${LINGJING_AWB_AUTO_INSTALL:-1}" = "0" ]; then
91
+ printf 'No compatible lj-awb CLI found. Install it first: npm install -g %s\n' "$CLI_PACKAGE_SPEC" >&2
92
+ exit 1
93
+ fi
94
+
95
+ if ! command -v npm >/dev/null 2>&1; then
96
+ printf 'No compatible lj-awb CLI found, and npm is unavailable. Install Node.js >=20 and npm, then run: npm install -g %s\n' "$CLI_PACKAGE_SPEC" >&2
97
+ exit 1
98
+ fi
99
+
100
+ printf 'Installing lj-awb CLI: npm install -g %s\n' "$CLI_PACKAGE_SPEC" >&2
101
+ npm install -g "$CLI_PACKAGE_SPEC" >&2
102
+
103
+ if LJ_AWB_CMD="$(find_lj_awb)"; then
104
+ INSTALLED_VERSION="$(command_version "$LJ_AWB_CMD" || true)"
105
+ if [ -n "$INSTALLED_VERSION" ] && semver_ge "$INSTALLED_VERSION" "$MIN_CLI_VERSION"; then
106
+ printf '%s\n' "$LJ_AWB_CMD"
107
+ exit 0
108
+ fi
7
109
  fi
8
110
 
9
- printf 'No usable lj-awb CLI found. Install `@lingjingai/lj-awb-cli` first.\n' >&2
111
+ printf 'Installed %s, but lj-awb is still not available on PATH. Check npm global bin path, then retry.\n' "$CLI_PACKAGE_SPEC" >&2
10
112
  exit 1