@alexcrondon/tx 0.1.0 → 0.1.3
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.
- package/README.md +3 -1
- package/lib/code.sh +16 -1
- package/lib/common.sh +6 -3
- package/lib/completions.sh +2 -2
- package/lib/help.sh +2 -1
- package/lib/serv.sh +11 -0
- package/lib/wt.sh +18 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ Config uses two files; the tool writes each key to the appropriate one:
|
|
|
54
54
|
|
|
55
55
|
| Scope | File | Keys |
|
|
56
56
|
|-------|------|------|
|
|
57
|
-
| User | `~/.txrc` | code, tunnel, db, auto_open, auto_tmux |
|
|
57
|
+
| User | `~/.txrc` | code, tunnel, db, auto_open, auto_tmux, auto_start |
|
|
58
58
|
| Project | `.txrc` | port, start, url, branch, copy, worktrees_dir, install |
|
|
59
59
|
|
|
60
60
|
```bash
|
|
@@ -81,6 +81,7 @@ tx config reset user # Delete ~/.txrc
|
|
|
81
81
|
| db | user | (empty) | Background db command |
|
|
82
82
|
| auto_open | user | false | Open browser after serv start |
|
|
83
83
|
| auto_tmux | user | false | Auto-launch tx code in tmux |
|
|
84
|
+
| auto_start | user | false | Auto-start dev server with tx code |
|
|
84
85
|
|
|
85
86
|
## Examples
|
|
86
87
|
|
|
@@ -99,6 +100,7 @@ tx wt add -b fix/my-bug # Create worktree fix-my-bug on branch fix/my-bug
|
|
|
99
100
|
|
|
100
101
|
# Code editor (creates worktree by default)
|
|
101
102
|
tx code -b fix/my-bug # Worktree "fix-my-bug" on branch fix/my-bug
|
|
103
|
+
tx code -s -b fix/my-bug # Same, plus install deps and start dev server
|
|
102
104
|
tx code -r # Run in repo root instead
|
|
103
105
|
tx code -t # Launch in tmux session
|
|
104
106
|
tx code attach hotfix # Reattach to tmux
|
package/lib/code.sh
CHANGED
|
@@ -10,6 +10,8 @@ cmd_code() {
|
|
|
10
10
|
local flag_attach=0
|
|
11
11
|
local flag_caffeinate=0
|
|
12
12
|
local flag_install=0
|
|
13
|
+
local flag_start=0
|
|
14
|
+
[ "$TX_AUTO_START" = "true" ] && flag_start=1
|
|
13
15
|
local name=""
|
|
14
16
|
local branch=""
|
|
15
17
|
local attach_name=""
|
|
@@ -21,6 +23,7 @@ cmd_code() {
|
|
|
21
23
|
--tunnel|-t) flag_tunnel=1; shift ;;
|
|
22
24
|
--caffeinate|-c) flag_caffeinate=1; shift ;;
|
|
23
25
|
--install|-i) flag_install=1; shift ;;
|
|
26
|
+
--start|-s) flag_start=1; shift ;;
|
|
24
27
|
--attach|-a) flag_attach=1; attach_name="${2:-}"; shift; shift 2>/dev/null || true ;;
|
|
25
28
|
--name=*|-n=*) name="${1#*=}"; shift ;;
|
|
26
29
|
--name|-n) name="$2"; shift 2 ;;
|
|
@@ -41,7 +44,7 @@ cmd_code() {
|
|
|
41
44
|
return $?
|
|
42
45
|
fi
|
|
43
46
|
|
|
44
|
-
_code_start "$flag_worktree" "$flag_tunnel" "$flag_caffeinate" "$name" "$branch" "$flag_install"
|
|
47
|
+
_code_start "$flag_worktree" "$flag_tunnel" "$flag_caffeinate" "$name" "$branch" "$flag_install" "$flag_start"
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
_code_start() {
|
|
@@ -51,8 +54,14 @@ _code_start() {
|
|
|
51
54
|
local name="$4"
|
|
52
55
|
local branch="$5"
|
|
53
56
|
local flag_install="${6:-0}"
|
|
57
|
+
local flag_start="${7:-0}"
|
|
54
58
|
local work_dir="$PWD"
|
|
55
59
|
|
|
60
|
+
# Start implies install — always install before starting
|
|
61
|
+
if [ "$flag_start" -eq 1 ]; then
|
|
62
|
+
flag_install=1
|
|
63
|
+
fi
|
|
64
|
+
|
|
56
65
|
if [ "$flag_worktree" -eq 1 ]; then
|
|
57
66
|
local wt_args=""
|
|
58
67
|
[ -n "$name" ] && wt_args="$wt_args --name $name"
|
|
@@ -67,6 +76,12 @@ _code_start() {
|
|
|
67
76
|
cd "$work_dir" || return 1
|
|
68
77
|
fi
|
|
69
78
|
|
|
79
|
+
# Start dev server if requested
|
|
80
|
+
if [ "$flag_start" -eq 1 ]; then
|
|
81
|
+
cd "$work_dir" || return 1
|
|
82
|
+
_serv_start 0 0 "" ""
|
|
83
|
+
fi
|
|
84
|
+
|
|
70
85
|
local session_name
|
|
71
86
|
local detected_name
|
|
72
87
|
detected_name=$(tx_detect_worktree_name) || true
|
package/lib/common.sh
CHANGED
|
@@ -21,12 +21,13 @@ TX_TUNNEL_CMD="${TX_TUNNEL_CMD:-ngrok tcp 22}"
|
|
|
21
21
|
TX_DB_CMD="${TX_DB_CMD:-}"
|
|
22
22
|
TX_AUTO_OPEN="${TX_AUTO_OPEN:-false}"
|
|
23
23
|
TX_AUTO_TMUX="${TX_AUTO_TMUX:-false}"
|
|
24
|
+
TX_AUTO_START="${TX_AUTO_START:-false}"
|
|
24
25
|
TX_INSTALL_CMD="${TX_INSTALL_CMD:-yarn install}"
|
|
25
26
|
|
|
26
27
|
# Config scopes: user (~/.txrc) vs project (.txrc)
|
|
27
|
-
TX_CONFIG_USER_KEYS="code tunnel auto_open db auto_tmux"
|
|
28
|
+
TX_CONFIG_USER_KEYS="code tunnel auto_open db auto_tmux auto_start"
|
|
28
29
|
TX_CONFIG_PROJECT_KEYS="port start url branch copy worktrees_dir install"
|
|
29
|
-
TX_CONFIG_KEYS="port start url branch copy worktrees_dir install code tunnel db auto_open auto_tmux"
|
|
30
|
+
TX_CONFIG_KEYS="port start url branch copy worktrees_dir install code tunnel db auto_open auto_tmux auto_start"
|
|
30
31
|
|
|
31
32
|
# --- Config key-to-variable mapping ---
|
|
32
33
|
tx_config_var() {
|
|
@@ -43,6 +44,7 @@ tx_config_var() {
|
|
|
43
44
|
auto_open) echo "TX_AUTO_OPEN" ;;
|
|
44
45
|
install) echo "TX_INSTALL_CMD" ;;
|
|
45
46
|
auto_tmux) echo "TX_AUTO_TMUX" ;;
|
|
47
|
+
auto_start) echo "TX_AUTO_START" ;;
|
|
46
48
|
*) echo "" ;;
|
|
47
49
|
esac
|
|
48
50
|
}
|
|
@@ -62,6 +64,7 @@ tx_config_default() {
|
|
|
62
64
|
auto_open) echo "false" ;;
|
|
63
65
|
install) echo "yarn install" ;;
|
|
64
66
|
auto_tmux) echo "false" ;;
|
|
67
|
+
auto_start) echo "false" ;;
|
|
65
68
|
esac
|
|
66
69
|
}
|
|
67
70
|
|
|
@@ -113,7 +116,7 @@ _tx_config_apply_file "$(_tx_project_root)/.txrc" $TX_CONFIG_PROJECT_KEYS
|
|
|
113
116
|
|
|
114
117
|
# Hash a directory path to a safe filename (MD5)
|
|
115
118
|
tx_hash_dir() {
|
|
116
|
-
|
|
119
|
+
printf '%s' "$1" | md5 -q 2>/dev/null || printf '%s' "$1" | md5sum | cut -d' ' -f1
|
|
117
120
|
}
|
|
118
121
|
|
|
119
122
|
# Ensure /tmp/tx-serv/ directory exists
|
package/lib/completions.sh
CHANGED
|
@@ -14,7 +14,7 @@ _tx() {
|
|
|
14
14
|
case "${words[2]}" in
|
|
15
15
|
config)
|
|
16
16
|
if [ "$CURRENT" -eq 3 ]; then
|
|
17
|
-
compadd port start url branch copy worktrees_dir code tunnel db auto_open init reset
|
|
17
|
+
compadd port start url branch copy worktrees_dir code tunnel db auto_open auto_tmux auto_start install init reset
|
|
18
18
|
elif [ "$CURRENT" -eq 4 ] && [ "${words[3]}" = "reset" ]; then
|
|
19
19
|
compadd user project
|
|
20
20
|
fi
|
|
@@ -49,7 +49,7 @@ _tx() {
|
|
|
49
49
|
if [ "$CURRENT" -eq 3 ]; then
|
|
50
50
|
compadd start attach
|
|
51
51
|
else
|
|
52
|
-
compadd -- --root --tunnel --name --branch --attach --caffeinate
|
|
52
|
+
compadd -- --root --tunnel --name --branch --attach --caffeinate --install --start
|
|
53
53
|
fi
|
|
54
54
|
;;
|
|
55
55
|
esac
|
package/lib/help.sh
CHANGED
|
@@ -11,7 +11,7 @@ Usage:
|
|
|
11
11
|
tx config reset [user|project] Delete config file (with confirmation)
|
|
12
12
|
|
|
13
13
|
Keys:
|
|
14
|
-
User (~/.txrc): code, tunnel, auto_open, db, auto_tmux
|
|
14
|
+
User (~/.txrc): code, tunnel, auto_open, db, auto_tmux, auto_start
|
|
15
15
|
Project (.txrc): port, start, url, branch, copy, worktrees_dir
|
|
16
16
|
EOF
|
|
17
17
|
}
|
|
@@ -96,6 +96,7 @@ Flags:
|
|
|
96
96
|
-a, --attach Attach to existing session
|
|
97
97
|
-c, --caffeinate Prevent sleep
|
|
98
98
|
-i, --install Run install command after creating worktree (TX_INSTALL_CMD)
|
|
99
|
+
-s, --start Run dev server after install (TX_START_CMD)
|
|
99
100
|
EOF
|
|
100
101
|
}
|
|
101
102
|
|
package/lib/serv.sh
CHANGED
|
@@ -163,6 +163,17 @@ _serv_start() {
|
|
|
163
163
|
cmd="$TX_START_CMD"
|
|
164
164
|
fi
|
|
165
165
|
|
|
166
|
+
# Warn if npm/yarn will walk up to a parent package.json
|
|
167
|
+
if [ ! -f "package.json" ]; then
|
|
168
|
+
case "$cmd" in
|
|
169
|
+
npm*|yarn*|npx*)
|
|
170
|
+
echo "Warning: No package.json in $PWD" >&2
|
|
171
|
+
echo " $cmd will use a parent directory's package.json instead." >&2
|
|
172
|
+
echo " The server may start from the wrong directory." >&2
|
|
173
|
+
;;
|
|
174
|
+
esac
|
|
175
|
+
fi
|
|
176
|
+
|
|
166
177
|
# Write state files
|
|
167
178
|
echo "$port" > "$(_serv_file "$hash" port)"
|
|
168
179
|
echo "$PWD" > "$(_serv_file "$hash" dir)"
|
package/lib/wt.sh
CHANGED
|
@@ -74,8 +74,11 @@ _wt_add() {
|
|
|
74
74
|
# Create worktree
|
|
75
75
|
if [ -n "$branch" ]; then
|
|
76
76
|
if git show-ref --verify --quiet "refs/heads/${branch}" 2>/dev/null; then
|
|
77
|
-
# Existing branch
|
|
77
|
+
# Existing local branch
|
|
78
78
|
git worktree add "$worktree_path" "$branch"
|
|
79
|
+
elif git show-ref --verify --quiet "refs/remotes/origin/${branch}" 2>/dev/null; then
|
|
80
|
+
# Existing remote branch — check it out locally
|
|
81
|
+
git worktree add --track -b "$branch" "$worktree_path" "origin/${branch}"
|
|
79
82
|
else
|
|
80
83
|
# New branch from default
|
|
81
84
|
git worktree add -b "$branch" "$worktree_path" "$TX_DEFAULT_BRANCH"
|
|
@@ -88,6 +91,9 @@ _wt_add() {
|
|
|
88
91
|
# Copy configured files
|
|
89
92
|
_wt_copy_files "$worktree_path"
|
|
90
93
|
|
|
94
|
+
# Symlink .claude/ so worktrees inherit permissions and settings
|
|
95
|
+
_wt_link_claude_config "$worktree_path"
|
|
96
|
+
|
|
91
97
|
# Symlink node_modules from repo root if it exists
|
|
92
98
|
_wt_link_node_modules "$worktree_path"
|
|
93
99
|
|
|
@@ -145,6 +151,17 @@ _wt_copy_files() {
|
|
|
145
151
|
done
|
|
146
152
|
}
|
|
147
153
|
|
|
154
|
+
_wt_link_claude_config() {
|
|
155
|
+
local target_dir="$1"
|
|
156
|
+
local repo_root
|
|
157
|
+
repo_root=$(git rev-parse --show-toplevel 2>/dev/null || echo ".")
|
|
158
|
+
|
|
159
|
+
[ -d "$repo_root/.claude" ] || return 0
|
|
160
|
+
[ -e "$target_dir/.claude" ] && return 0
|
|
161
|
+
|
|
162
|
+
ln -s "$repo_root/.claude" "$target_dir/.claude"
|
|
163
|
+
}
|
|
164
|
+
|
|
148
165
|
_wt_link_node_modules() {
|
|
149
166
|
# No-op: node_modules is not copied or symlinked into worktrees.
|
|
150
167
|
# Symlinks break yarn v1 (can't resolve nested deps through them),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexcrondon/tx",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Modular CLI for isolated dev environments using git worktrees",
|
|
5
5
|
"bin": {
|
|
6
6
|
"tx": "./bin/tx"
|
|
@@ -9,5 +9,8 @@
|
|
|
9
9
|
"bin/",
|
|
10
10
|
"lib/"
|
|
11
11
|
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"publish": "sh scripts/publish.sh"
|
|
14
|
+
},
|
|
12
15
|
"license": "MIT"
|
|
13
16
|
}
|