@fatdoge/wtree 0.1.0
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.en.md +113 -0
- package/README.md +136 -0
- package/api/app.ts +19 -0
- package/api/cli/wtree.ts +809 -0
- package/api/core/config.ts +26 -0
- package/api/core/exec.ts +55 -0
- package/api/core/git.ts +35 -0
- package/api/core/id.ts +8 -0
- package/api/core/open.ts +58 -0
- package/api/core/worktree.test.ts +33 -0
- package/api/core/worktree.ts +72 -0
- package/api/createApiApp.ts +33 -0
- package/api/index.ts +9 -0
- package/api/routes/worktrees.ts +255 -0
- package/api/server.ts +34 -0
- package/api/ui/startUiDev.ts +82 -0
- package/dist/assets/index-D9inyPb3.js +179 -0
- package/dist/assets/index-W34LSHWF.css +1 -0
- package/dist/favicon.svg +4 -0
- package/dist/index.html +354 -0
- package/dist-node/api/app.js +17 -0
- package/dist-node/api/cli/wtree.js +722 -0
- package/dist-node/api/cli/wtui.js +722 -0
- package/dist-node/api/core/config.js +21 -0
- package/dist-node/api/core/exec.js +24 -0
- package/dist-node/api/core/git.js +24 -0
- package/dist-node/api/core/id.js +6 -0
- package/dist-node/api/core/open.js +51 -0
- package/dist-node/api/core/worktree.js +58 -0
- package/dist-node/api/core/worktree.test.js +30 -0
- package/dist-node/api/createApiApp.js +26 -0
- package/dist-node/api/routes/worktrees.js +213 -0
- package/dist-node/api/server.js +29 -0
- package/dist-node/api/ui/startUiDev.js +65 -0
- package/dist-node/shared/wtui-types.js +1 -0
- package/index.html +24 -0
- package/package.json +89 -0
- package/postcss.config.js +10 -0
- package/shared/wtui-types.ts +36 -0
- package/src/App.tsx +28 -0
- package/src/assets/react.svg +1 -0
- package/src/components/Button.tsx +34 -0
- package/src/components/Empty.tsx +8 -0
- package/src/components/Input.tsx +16 -0
- package/src/components/Modal.tsx +33 -0
- package/src/components/ToastHost.tsx +42 -0
- package/src/hooks/useTheme.ts +29 -0
- package/src/i18n/index.ts +22 -0
- package/src/i18n/locales/en.json +145 -0
- package/src/i18n/locales/zh.json +145 -0
- package/src/index.css +24 -0
- package/src/lib/utils.ts +6 -0
- package/src/main.tsx +11 -0
- package/src/pages/CreateWorktree.tsx +181 -0
- package/src/pages/HelpPage.tsx +67 -0
- package/src/pages/Home.tsx +3 -0
- package/src/pages/SettingsPage.tsx +218 -0
- package/src/pages/Worktrees.tsx +354 -0
- package/src/stores/themeStore.ts +44 -0
- package/src/stores/toastStore.ts +29 -0
- package/src/stores/worktreeStore.ts +93 -0
- package/src/utils/api.ts +36 -0
- package/src/vite-env.d.ts +1 -0
- package/tailwind.config.js +13 -0
- package/vite.config.ts +46 -0
package/README.en.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# wtree
|
|
2
|
+
|
|
3
|
+
English | [简体中文](./README.md)
|
|
4
|
+
|
|
5
|
+
`wtree` is a local tool for managing git worktrees. It runs in an interactive command-line mode by default, and also supports a one-click local UI (TreeLab) for visual management.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Interactive creation and deletion of worktrees (supports force deletion of uncommitted changes)
|
|
10
|
+
- Local UI mode with a browser-based visual management interface, supporting Light/Dark mode and i18n (English/Chinese)
|
|
11
|
+
- Support for creating worktrees from new branches or existing branches/commits
|
|
12
|
+
- Open worktrees instantly in your system file manager or preferred IDEs (Trae, Cursor, VS Code)
|
|
13
|
+
- Support for Locking, Unlocking, and Pruning invalid worktrees
|
|
14
|
+
- Local API executes git commands securely on your machine, data never leaves your computer
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install -g wtree
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or run directly using `npx`:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npx wtree
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### Interactive CLI
|
|
31
|
+
|
|
32
|
+
Run inside your git repository:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
wtree
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Specify a branch directly to skip selection:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
wtree feature/my-branch
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
List all worktrees:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
wtree list
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### UI Mode (TreeLab)
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
wtree --ui
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Optional arguments:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
wtree --ui --repo /path/to/repo
|
|
60
|
+
wtree --ui --no-open
|
|
61
|
+
wtree --ui --port 0
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## CLI Commands
|
|
65
|
+
|
|
66
|
+
- `wtree`: Interactive main menu (Create/Delete/List/Open/Lock/Unlock/Prune)
|
|
67
|
+
- `wtree list`: Print worktree list
|
|
68
|
+
- `wtree create [branch]`: Create a worktree (interactive selection supported)
|
|
69
|
+
- `wtree delete`: Delete a worktree (interactive selection, force deletion supported)
|
|
70
|
+
- `wtree open [path|branch]`: Open a worktree
|
|
71
|
+
- `wtree lock [path|branch]`: Lock a specific worktree to prevent it from being moved or deleted
|
|
72
|
+
- `wtree unlock [path|branch]`: Unlock a specific worktree
|
|
73
|
+
- `wtree prune`: Prune worktree records that no longer exist locally but are tracked by Git
|
|
74
|
+
- `wtree config`: View local configuration
|
|
75
|
+
- `wtree config get <key>`: Read a configuration item
|
|
76
|
+
- `wtree config set <key> <value>`: Set a configuration item
|
|
77
|
+
- `wtree help`: View help information
|
|
78
|
+
|
|
79
|
+
## Configuration
|
|
80
|
+
|
|
81
|
+
The UI settings page saves configuration to a local file:
|
|
82
|
+
|
|
83
|
+
- macOS/Linux: `~/.config/wtree/config.json`
|
|
84
|
+
- Windows: `%USERPROFILE%\.config\wtree\config.json`
|
|
85
|
+
|
|
86
|
+
Supported configuration keys:
|
|
87
|
+
|
|
88
|
+
- `baseDir`: Used by the UI to remember the default directory (currently not automatically appended to the creation path)
|
|
89
|
+
- `openCommand`: The command used when clicking "Folder" in the UI to open the system file manager (defaults to system commands based on OS, e.g., `open` on macOS)
|
|
90
|
+
- `editorCommand`: The command used when clicking "IDE" in the UI. If not set, the system will automatically detect installed editors like Trae, Cursor, or VS Code.
|
|
91
|
+
|
|
92
|
+
**Note**: The UI theme mode (Light/Dark/System) and language preferences are stored independently in the browser's `localStorage`.
|
|
93
|
+
|
|
94
|
+
## Development
|
|
95
|
+
|
|
96
|
+
Install dependencies:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pnpm install
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Common scripts:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pnpm run wtree
|
|
106
|
+
pnpm run dev
|
|
107
|
+
pnpm run client:dev
|
|
108
|
+
pnpm run server:dev
|
|
109
|
+
pnpm run build
|
|
110
|
+
pnpm run lint
|
|
111
|
+
pnpm run test
|
|
112
|
+
pnpm run check
|
|
113
|
+
```
|
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# wtree
|
|
2
|
+
|
|
3
|
+
[English](./README.en.md) | 简体中文
|
|
4
|
+
|
|
5
|
+
`wtree` 是一个本地工具,用于管理 git worktree。默认是交互式命令行模式,也支持一键启动 UI 页面 (TreeLab) 进行可视化操作。
|
|
6
|
+
|
|
7
|
+
## 特性
|
|
8
|
+
|
|
9
|
+
- 交互式创建与删除 worktree (支持强制删除未提交更改)
|
|
10
|
+
- UI 模式本地启动,浏览器可视化管理,支持浅色/深色模式切换以及中英文国际化
|
|
11
|
+
- 支持创建新分支、从已有分支/提交创建 worktree
|
|
12
|
+
- 支持在系统文件管理器或常用 IDE (Trae, Cursor, VS Code) 中一键打开
|
|
13
|
+
- 支持锁定 (Lock) / 解锁 (Unlock) 以及清理 (Prune) 无效的 worktree
|
|
14
|
+
- 本地 API 执行 git 命令,数据不出机器
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
需要本机已安装 `git`,建议 Node.js `>= 18`。
|
|
19
|
+
|
|
20
|
+
本地软链安装:
|
|
21
|
+
```bash
|
|
22
|
+
pnpm install
|
|
23
|
+
pnpm run build
|
|
24
|
+
npm link
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 快速开始
|
|
28
|
+
|
|
29
|
+
### 交互式 CLI
|
|
30
|
+
|
|
31
|
+
在 git 仓库目录中运行:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
wtree
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
直接指定分支名跳过选择:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
wtree feature/my-branch
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
查看 worktree 列表:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
wtree list
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### UI 模式 (TreeLab)
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
wtree --ui
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
可选参数:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
wtree --ui --repo /path/to/repo
|
|
59
|
+
wtree --ui --no-open
|
|
60
|
+
wtree --ui --port 0
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## CLI 参数
|
|
64
|
+
|
|
65
|
+
- `--ui`:启动本地 UI
|
|
66
|
+
- `--repo <path>`:指定仓库路径(默认使用当前目录)
|
|
67
|
+
- `--no-open`:不自动打开浏览器
|
|
68
|
+
- `--port <number>`:指定 UI 端口(`0` 表示自动分配)
|
|
69
|
+
|
|
70
|
+
## CLI 命令
|
|
71
|
+
|
|
72
|
+
- `wtree`:交互式主菜单 (创建/删除/列表/打开/锁定/解锁/清理)
|
|
73
|
+
- `wtree list`:打印 worktree 列表
|
|
74
|
+
- `wtree create [branch]`:创建 worktree(支持交互式选择)
|
|
75
|
+
- `wtree delete`:删除 worktree(交互式选择,支持强制删除)
|
|
76
|
+
- `wtree open [path|branch]`:打开 worktree
|
|
77
|
+
- `wtree lock [path|branch]`:锁定指定的 worktree,防止被移动或删除
|
|
78
|
+
- `wtree unlock [path|branch]`:解锁指定的 worktree
|
|
79
|
+
- `wtree prune`:清理本地不存在记录但被 Git 记录的无效 worktree
|
|
80
|
+
- `wtree config`:查看本地配置
|
|
81
|
+
- `wtree config get <key>`:读取配置项
|
|
82
|
+
- `wtree config set <key> <value>`:设置配置项
|
|
83
|
+
- `wtree help`:查看帮助
|
|
84
|
+
|
|
85
|
+
## 配置
|
|
86
|
+
|
|
87
|
+
UI 设置页会将配置写入本地文件:
|
|
88
|
+
|
|
89
|
+
- macOS/Linux:`~/.config/wtree/config.json`
|
|
90
|
+
- Windows:`%USERPROFILE%\.config\wtree\config.json`
|
|
91
|
+
|
|
92
|
+
配置字段:
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"baseDir": "worktrees",
|
|
97
|
+
"openCommand": "open",
|
|
98
|
+
"editorCommand": "code"
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
- `baseDir`:用于 UI 记录默认目录,当前不会自动拼接到创建路径
|
|
103
|
+
- `openCommand`:UI 点击“Folder”打开系统文件管理器时使用的命令(默认按平台使用系统命令,如 macOS 的 `open`)
|
|
104
|
+
- `editorCommand`:UI 点击“IDE”打开编辑器时使用的命令。若不设置,则会自动检测系统中是否安装了 Trae、Cursor 或 VS Code。
|
|
105
|
+
|
|
106
|
+
**注意**:UI 的主题模式(浅色/深色/跟随系统)和语言偏好独立存储在浏览器的 `localStorage` 中。
|
|
107
|
+
|
|
108
|
+
## 开发
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pnpm install
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
常用脚本:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pnpm run wtree
|
|
118
|
+
pnpm run dev
|
|
119
|
+
pnpm run client:dev
|
|
120
|
+
pnpm run server:dev
|
|
121
|
+
pnpm run build
|
|
122
|
+
pnpm run lint
|
|
123
|
+
pnpm run test
|
|
124
|
+
pnpm run check
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
环境变量:
|
|
128
|
+
|
|
129
|
+
- `WTUI_REPO_ROOT`:本地 API 服务器运行时使用的 repo 根目录
|
|
130
|
+
- `PORT`:本地 API 服务器端口(默认 `3001`)
|
|
131
|
+
|
|
132
|
+
## 项目结构
|
|
133
|
+
|
|
134
|
+
- `api/`:CLI + 本地 API(git 执行与配置读写)
|
|
135
|
+
- `src/`:UI(React + Vite + Tailwind)
|
|
136
|
+
- `shared/`:前后端共享类型
|
package/api/app.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import dotenv from 'dotenv'
|
|
2
|
+
import { createApiApp } from './createApiApp.js'
|
|
3
|
+
import { getRepoRoot } from './core/git.js'
|
|
4
|
+
|
|
5
|
+
dotenv.config()
|
|
6
|
+
|
|
7
|
+
const repoRoot = (() => {
|
|
8
|
+
const fromEnv = process.env.WTUI_REPO_ROOT
|
|
9
|
+
if (fromEnv) return fromEnv
|
|
10
|
+
try {
|
|
11
|
+
return getRepoRoot(process.cwd())
|
|
12
|
+
} catch {
|
|
13
|
+
return process.cwd()
|
|
14
|
+
}
|
|
15
|
+
})()
|
|
16
|
+
|
|
17
|
+
const app = createApiApp(() => repoRoot)
|
|
18
|
+
|
|
19
|
+
export default app
|