oh-my-worktree 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.
Files changed (4) hide show
  1. package/README.md +51 -0
  2. package/bin/owt +27 -0
  3. package/install.js +106 -0
  4. package/package.json +40 -0
package/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # owt (oh-my-worktree)
2
+
3
+ A TUI tool for managing Git worktrees in bare repositories.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g oh-my-worktree
9
+ ```
10
+
11
+ Or use with npx:
12
+
13
+ ```bash
14
+ npx oh-my-worktree
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```bash
20
+ # Run in a bare repository or worktree directory
21
+ owt
22
+
23
+ # Clone a repository as bare with first worktree
24
+ owt clone <url>
25
+
26
+ # Show guide for converting existing repo to bare
27
+ owt init
28
+ ```
29
+
30
+ ## Key Bindings
31
+
32
+ | Key | Action |
33
+ |-----|--------|
34
+ | `↑/k` | Previous item |
35
+ | `↓/j` | Next item |
36
+ | `a` | Add new worktree |
37
+ | `d` | Delete worktree |
38
+ | `o` | Open in editor |
39
+ | `t` | Open terminal |
40
+ | `f` | Fetch all |
41
+ | `r` | Refresh list |
42
+ | `q` | Quit |
43
+
44
+ ## Requirements
45
+
46
+ - Git 2.5+ (for worktree support)
47
+ - A bare Git repository
48
+
49
+ ## More Information
50
+
51
+ For more details, visit the [GitHub repository](https://github.com/dding-g/oh-my-worktree).
package/bin/owt ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn } = require('child_process');
4
+ const path = require('path');
5
+ const fs = require('fs');
6
+
7
+ const binName = process.platform === 'win32' ? 'owt.exe' : 'owt';
8
+ const binPath = path.join(__dirname, binName);
9
+
10
+ if (!fs.existsSync(binPath)) {
11
+ console.error('owt binary not found. Please reinstall the package:');
12
+ console.error(' npm install -g oh-my-worktree');
13
+ process.exit(1);
14
+ }
15
+
16
+ const child = spawn(binPath, process.argv.slice(2), {
17
+ stdio: 'inherit',
18
+ });
19
+
20
+ child.on('error', (err) => {
21
+ console.error('Failed to run owt:', err.message);
22
+ process.exit(1);
23
+ });
24
+
25
+ child.on('close', (code) => {
26
+ process.exit(code || 0);
27
+ });
package/install.js ADDED
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+
3
+ const https = require('https');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const { execSync } = require('child_process');
7
+
8
+ const REPO = 'dding-g/oh-my-worktree';
9
+ const BINARY_NAME = 'owt';
10
+
11
+ function getPlatform() {
12
+ const platform = process.platform;
13
+ const arch = process.arch;
14
+
15
+ const platformMap = {
16
+ 'darwin-x64': 'owt-darwin-x64',
17
+ 'darwin-arm64': 'owt-darwin-arm64',
18
+ 'linux-x64': 'owt-linux-x64',
19
+ 'linux-arm64': 'owt-linux-arm64',
20
+ 'win32-x64': 'owt-win32-x64.exe',
21
+ };
22
+
23
+ const key = `${platform}-${arch}`;
24
+ const binaryName = platformMap[key];
25
+
26
+ if (!binaryName) {
27
+ console.error(`Unsupported platform: ${platform}-${arch}`);
28
+ console.error('Supported platforms: darwin-x64, darwin-arm64, linux-x64, linux-arm64, win32-x64');
29
+ process.exit(1);
30
+ }
31
+
32
+ return binaryName;
33
+ }
34
+
35
+ function getPackageVersion() {
36
+ const packageJson = require('./package.json');
37
+ return packageJson.version;
38
+ }
39
+
40
+ function downloadFile(url, dest) {
41
+ return new Promise((resolve, reject) => {
42
+ const file = fs.createWriteStream(dest);
43
+
44
+ const request = (url) => {
45
+ https.get(url, (response) => {
46
+ if (response.statusCode === 302 || response.statusCode === 301) {
47
+ // Follow redirect
48
+ request(response.headers.location);
49
+ return;
50
+ }
51
+
52
+ if (response.statusCode !== 200) {
53
+ reject(new Error(`Failed to download: ${response.statusCode}`));
54
+ return;
55
+ }
56
+
57
+ response.pipe(file);
58
+ file.on('finish', () => {
59
+ file.close();
60
+ resolve();
61
+ });
62
+ }).on('error', (err) => {
63
+ fs.unlink(dest, () => {});
64
+ reject(err);
65
+ });
66
+ };
67
+
68
+ request(url);
69
+ });
70
+ }
71
+
72
+ async function install() {
73
+ const binaryName = getPlatform();
74
+ const version = getPackageVersion();
75
+ const binDir = path.join(__dirname, 'bin');
76
+ const binPath = path.join(binDir, BINARY_NAME + (process.platform === 'win32' ? '.exe' : ''));
77
+
78
+ // Create bin directory
79
+ if (!fs.existsSync(binDir)) {
80
+ fs.mkdirSync(binDir, { recursive: true });
81
+ }
82
+
83
+ const downloadUrl = `https://github.com/${REPO}/releases/download/v${version}/${binaryName}`;
84
+
85
+ console.log(`Downloading owt v${version} for ${process.platform}-${process.arch}...`);
86
+ console.log(`URL: ${downloadUrl}`);
87
+
88
+ try {
89
+ await downloadFile(downloadUrl, binPath);
90
+
91
+ // Make executable on Unix systems
92
+ if (process.platform !== 'win32') {
93
+ fs.chmodSync(binPath, 0o755);
94
+ }
95
+
96
+ console.log('owt installed successfully!');
97
+ } catch (error) {
98
+ console.error('Failed to download binary:', error.message);
99
+ console.error('');
100
+ console.error('You can manually install owt using cargo:');
101
+ console.error(' cargo install --git https://github.com/dding-g/oh-my-worktree');
102
+ process.exit(1);
103
+ }
104
+ }
105
+
106
+ install();
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "oh-my-worktree",
3
+ "version": "0.1.0",
4
+ "description": "A TUI tool for managing Git worktrees in bare repositories",
5
+ "keywords": [
6
+ "git",
7
+ "worktree",
8
+ "tui",
9
+ "cli",
10
+ "bare-repository"
11
+ ],
12
+ "author": "matthew",
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/dding-g/oh-my-worktree"
17
+ },
18
+ "homepage": "https://github.com/dding-g/oh-my-worktree#readme",
19
+ "bugs": {
20
+ "url": "https://github.com/dding-g/oh-my-worktree/issues"
21
+ },
22
+ "bin": {
23
+ "owt": "./bin/owt"
24
+ },
25
+ "scripts": {
26
+ "postinstall": "node install.js"
27
+ },
28
+ "engines": {
29
+ "node": ">=14"
30
+ },
31
+ "os": [
32
+ "darwin",
33
+ "linux",
34
+ "win32"
35
+ ],
36
+ "cpu": [
37
+ "x64",
38
+ "arm64"
39
+ ]
40
+ }