返回 ViMax
vimax
根目录 / vimax
1 #!/usr/bin/env bash
2 set -euo pipefail
3
4 SOURCE="${BASH_SOURCE[0]}"
5 while [[ -L "$SOURCE" ]]; do
6 DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
7 SOURCE="$(readlink "$SOURCE")"
8 [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE"
9 done
10 ROOT="$(cd -P "$(dirname "$SOURCE")" && pwd)"
11
12 usage() {
13 cat <<EOF
14 Usage:
15 vimax tui Resume the current active session
16 vimax tui new Create and activate a new empty session
17 vimax tui resume Resume the current active session
18 vimax tui resume <session_id> Resume a specific existing session
19 vimax tui --new-session Same as: vimax tui new
20 vimax tui --session <session_id> Same as: vimax tui resume <session_id>
21 vimax web Start the ViMax Web development server
22 vimax web start Serve a built ViMax Web app
23 EOF
24 }
25
26 if [[ $# -lt 1 ]]; then
27 usage
28 exit 2
29 fi
30
31 command="$1"
32 shift
33
34 case "$command" in
35 web)
36 web_mode="${1:-dev}"
37 if [[ "$web_mode" == "start" ]]; then
38 shift
39 elif [[ "$web_mode" != "dev" ]]; then
40 echo "error: unknown web mode: $web_mode" >&2
41 usage >&2
42 exit 2
43 fi
44 if [[ ! -x "$ROOT/web/node_modules/.bin/vite" ]]; then
45 echo "error: web dependencies are missing. Run: cd $ROOT/web && npm install" >&2
46 exit 2
47 fi
48 if [[ "$web_mode" == "start" ]]; then
49 if [[ ! -f "$ROOT/web/dist/index.html" ]]; then
50 echo "error: web build is missing. Run: cd $ROOT/web && npm run build" >&2
51 exit 2
52 fi
53 exec npm --prefix "$ROOT/web" run start
54 fi
55 exec npm --prefix "$ROOT/web" run dev
56 ;;
57 tui)
58 tui_args=()
59 case "${1:-}" in
60 new)
61 tui_args+=("--new-session")
62 shift
63 ;;
64 resume|old)
65 shift
66 if [[ -n "${1:-}" && "${1:-}" != --* ]]; then
67 tui_args+=("--session" "$1")
68 shift
69 fi
70 ;;
71 --new-session)
72 tui_args+=("--new-session")
73 shift
74 ;;
75 --session)
76 if [[ -z "${2:-}" ]]; then
77 echo "error: --session requires a session id" >&2
78 exit 2
79 fi
80 tui_args+=("--session" "$2")
81 shift 2
82 ;;
83 "")
84 ;;
85 --help|-h|help)
86 usage
87 exit 0
88 ;;
89 *)
90 echo "error: unknown tui mode: $1" >&2
91 usage >&2
92 exit 2
93 ;;
94 esac
95 if [[ $# -gt 0 ]]; then
96 tui_args+=("$@")
97 fi
98 if [[ ! -x "$ROOT/ui/node_modules/.bin/tsx" ]]; then
99 echo "error: ui dependencies are missing. Run: cd $ROOT/ui && npm install" >&2
100 exit 2
101 fi
102 exec "$ROOT/ui/node_modules/.bin/tsx" "$ROOT/ui/src/cli.tsx" ${tui_args[@]+"${tui_args[@]}"}
103 ;;
104 --help|-h|help)
105 usage
106 ;;
107 *)
108 echo "error: unknown command: $command" >&2
109 usage >&2
110 exit 2
111 ;;
112 esac
113
113 lines Plain Text