@fatdoge/wtree 0.2.0 → 0.2.1
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/api/cli/wtree.ts +30 -0
- package/dist-node/api/cli/wtree.js +30 -0
- package/package.json +1 -1
package/api/cli/wtree.ts
CHANGED
|
@@ -6,6 +6,7 @@ import inquirer from 'inquirer'
|
|
|
6
6
|
import chalk from 'chalk'
|
|
7
7
|
import { execSync } from 'node:child_process'
|
|
8
8
|
import fs from 'node:fs'
|
|
9
|
+
import { fileURLToPath } from 'node:url'
|
|
9
10
|
import { getRepoRoot } from '../core/git.js'
|
|
10
11
|
import { git, gitOrThrow } from '../core/git.js'
|
|
11
12
|
import { listWorktrees, parseWorktreePorcelain } from '../core/worktree.js'
|
|
@@ -26,6 +27,7 @@ type ParsedFlags = {
|
|
|
26
27
|
editor: string | undefined
|
|
27
28
|
noEditor: boolean
|
|
28
29
|
noInstall: boolean
|
|
30
|
+
version: boolean
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
type Ctx = {
|
|
@@ -43,6 +45,25 @@ type SourceSelection =
|
|
|
43
45
|
type SourceType = SourceSelection['type']
|
|
44
46
|
type CommandType = 'list' | 'create' | 'delete' | 'open' | 'config' | 'help' | 'interactive' | 'prune' | 'lock' | 'unlock'
|
|
45
47
|
|
|
48
|
+
function getVersion(): string {
|
|
49
|
+
try {
|
|
50
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
51
|
+
// 从 api/cli/ 或 dist-node/api/cli/ 向上查找 package.json
|
|
52
|
+
let dir = __dirname
|
|
53
|
+
for (let i = 0; i < 5; i++) {
|
|
54
|
+
const pkgPath = path.join(dir, 'package.json')
|
|
55
|
+
if (fs.existsSync(pkgPath)) {
|
|
56
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
|
|
57
|
+
return pkg.version || 'unknown'
|
|
58
|
+
}
|
|
59
|
+
dir = path.dirname(dir)
|
|
60
|
+
}
|
|
61
|
+
return 'unknown'
|
|
62
|
+
} catch {
|
|
63
|
+
return 'unknown'
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
46
67
|
function errMsg(e: unknown) {
|
|
47
68
|
return e instanceof Error ? e.message : String(e)
|
|
48
69
|
}
|
|
@@ -62,6 +83,7 @@ function parseArgs(argv: string[]) {
|
|
|
62
83
|
editor: undefined,
|
|
63
84
|
noEditor: false,
|
|
64
85
|
noInstall: false,
|
|
86
|
+
version: false,
|
|
65
87
|
}
|
|
66
88
|
const positional: string[] = []
|
|
67
89
|
|
|
@@ -92,6 +114,7 @@ function parseArgs(argv: string[]) {
|
|
|
92
114
|
if (a === '--editor') { flags.editor = String(args.shift() || ''); continue }
|
|
93
115
|
if (a === '--no-editor') { flags.noEditor = true; continue }
|
|
94
116
|
if (a === '--no-install') { flags.noInstall = true; continue }
|
|
117
|
+
if (a === '--version' || a === '-v') { flags.version = true; continue }
|
|
95
118
|
if (a.startsWith('--')) continue
|
|
96
119
|
positional.push(a)
|
|
97
120
|
}
|
|
@@ -163,6 +186,7 @@ function printHelp() {
|
|
|
163
186
|
console.info(' wtree config get <key>')
|
|
164
187
|
console.info(' wtree config set <key> <value>')
|
|
165
188
|
console.info(' wtree --ui [--repo <path>] [--no-open] [--port <number>]')
|
|
189
|
+
console.info(' wtree --version, -v')
|
|
166
190
|
console.info('')
|
|
167
191
|
console.info('选项:')
|
|
168
192
|
console.info(' --json 以 JSON 格式输出 (适合脚本/agent 使用)')
|
|
@@ -343,6 +367,12 @@ async function pruneWorktrees(rootDir: string) {
|
|
|
343
367
|
|
|
344
368
|
async function main() {
|
|
345
369
|
const { flags, positional } = parseArgs(process.argv.slice(2))
|
|
370
|
+
|
|
371
|
+
if (flags.version || positional[0] === 'version') {
|
|
372
|
+
console.info(getVersion())
|
|
373
|
+
return
|
|
374
|
+
}
|
|
375
|
+
|
|
346
376
|
const cwd = flags.repo ? path.resolve(flags.repo) : process.cwd()
|
|
347
377
|
const rootDir = getRepoRoot(cwd)
|
|
348
378
|
|
|
@@ -5,12 +5,32 @@ import inquirer from 'inquirer';
|
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
import { execSync } from 'node:child_process';
|
|
7
7
|
import fs from 'node:fs';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
8
9
|
import { getRepoRoot } from '../core/git.js';
|
|
9
10
|
import { git, gitOrThrow } from '../core/git.js';
|
|
10
11
|
import { listWorktrees, parseWorktreePorcelain } from '../core/worktree.js';
|
|
11
12
|
import { openPath } from '../core/open.js';
|
|
12
13
|
import { readConfig, writeConfig, getConfigPaths } from '../core/config.js';
|
|
13
14
|
import { startUiDevServer } from '../ui/startUiDev.js';
|
|
15
|
+
function getVersion() {
|
|
16
|
+
try {
|
|
17
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
// 从 api/cli/ 或 dist-node/api/cli/ 向上查找 package.json
|
|
19
|
+
let dir = __dirname;
|
|
20
|
+
for (let i = 0; i < 5; i++) {
|
|
21
|
+
const pkgPath = path.join(dir, 'package.json');
|
|
22
|
+
if (fs.existsSync(pkgPath)) {
|
|
23
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
24
|
+
return pkg.version || 'unknown';
|
|
25
|
+
}
|
|
26
|
+
dir = path.dirname(dir);
|
|
27
|
+
}
|
|
28
|
+
return 'unknown';
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return 'unknown';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
14
34
|
function errMsg(e) {
|
|
15
35
|
return e instanceof Error ? e.message : String(e);
|
|
16
36
|
}
|
|
@@ -29,6 +49,7 @@ function parseArgs(argv) {
|
|
|
29
49
|
editor: undefined,
|
|
30
50
|
noEditor: false,
|
|
31
51
|
noInstall: false,
|
|
52
|
+
version: false,
|
|
32
53
|
};
|
|
33
54
|
const positional = [];
|
|
34
55
|
while (args.length) {
|
|
@@ -83,6 +104,10 @@ function parseArgs(argv) {
|
|
|
83
104
|
flags.noInstall = true;
|
|
84
105
|
continue;
|
|
85
106
|
}
|
|
107
|
+
if (a === '--version' || a === '-v') {
|
|
108
|
+
flags.version = true;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
86
111
|
if (a.startsWith('--'))
|
|
87
112
|
continue;
|
|
88
113
|
positional.push(a);
|
|
@@ -151,6 +176,7 @@ function printHelp() {
|
|
|
151
176
|
console.info(' wtree config get <key>');
|
|
152
177
|
console.info(' wtree config set <key> <value>');
|
|
153
178
|
console.info(' wtree --ui [--repo <path>] [--no-open] [--port <number>]');
|
|
179
|
+
console.info(' wtree --version, -v');
|
|
154
180
|
console.info('');
|
|
155
181
|
console.info('选项:');
|
|
156
182
|
console.info(' --json 以 JSON 格式输出 (适合脚本/agent 使用)');
|
|
@@ -318,6 +344,10 @@ async function pruneWorktrees(rootDir) {
|
|
|
318
344
|
}
|
|
319
345
|
async function main() {
|
|
320
346
|
const { flags, positional } = parseArgs(process.argv.slice(2));
|
|
347
|
+
if (flags.version || positional[0] === 'version') {
|
|
348
|
+
console.info(getVersion());
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
321
351
|
const cwd = flags.repo ? path.resolve(flags.repo) : process.cwd();
|
|
322
352
|
const rootDir = getRepoRoot(cwd);
|
|
323
353
|
if (flags.ui) {
|