oh-my-worktree 0.1.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.
Files changed (2) hide show
  1. package/install.js +48 -9
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const https = require('https');
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
- const { execSync } = require('child_process');
6
+ const { execSync, spawn } = require('child_process');
7
7
 
8
8
  const REPO = 'dding-g/oh-my-worktree';
9
9
  const BINARY_NAME = 'owt';
@@ -37,25 +37,60 @@ function getPackageVersion() {
37
37
  return packageJson.version;
38
38
  }
39
39
 
40
- function downloadFile(url, dest) {
40
+ function commandExists(cmd) {
41
+ try {
42
+ execSync(`which ${cmd}`, { stdio: 'ignore' });
43
+ return true;
44
+ } catch {
45
+ return false;
46
+ }
47
+ }
48
+
49
+ // Fast download using curl (if available)
50
+ function downloadWithCurl(url, dest) {
51
+ return new Promise((resolve, reject) => {
52
+ const curl = spawn('curl', ['-fSL', '--progress-bar', '-o', dest, url], {
53
+ stdio: ['ignore', 'inherit', 'inherit']
54
+ });
55
+ curl.on('close', (code) => {
56
+ if (code === 0) resolve();
57
+ else reject(new Error(`curl exited with code ${code}`));
58
+ });
59
+ curl.on('error', reject);
60
+ });
61
+ }
62
+
63
+ // Fallback: Node.js https with progress
64
+ function downloadWithNode(url, dest) {
41
65
  return new Promise((resolve, reject) => {
42
66
  const file = fs.createWriteStream(dest);
43
67
 
44
68
  const request = (url) => {
45
69
  https.get(url, (response) => {
46
70
  if (response.statusCode === 302 || response.statusCode === 301) {
47
- // Follow redirect
48
71
  request(response.headers.location);
49
72
  return;
50
73
  }
51
74
 
52
75
  if (response.statusCode !== 200) {
53
- reject(new Error(`Failed to download: ${response.statusCode}`));
76
+ reject(new Error(`HTTP ${response.statusCode}`));
54
77
  return;
55
78
  }
56
79
 
80
+ const totalSize = parseInt(response.headers['content-length'], 10);
81
+ let downloaded = 0;
82
+
83
+ response.on('data', (chunk) => {
84
+ downloaded += chunk.length;
85
+ if (totalSize) {
86
+ const percent = Math.round((downloaded / totalSize) * 100);
87
+ process.stdout.write(`\rDownloading... ${percent}%`);
88
+ }
89
+ });
90
+
57
91
  response.pipe(file);
58
92
  file.on('finish', () => {
93
+ process.stdout.write('\n');
59
94
  file.close();
60
95
  resolve();
61
96
  });
@@ -82,22 +117,26 @@ async function install() {
82
117
 
83
118
  const downloadUrl = `https://github.com/${REPO}/releases/download/v${version}/${binaryName}`;
84
119
 
85
- console.log(`Downloading owt v${version} for ${process.platform}-${process.arch}...`);
86
- console.log(`URL: ${downloadUrl}`);
120
+ console.log(`Installing owt v${version} for ${process.platform}-${process.arch}`);
87
121
 
88
122
  try {
89
- await downloadFile(downloadUrl, binPath);
123
+ // Prefer curl for faster download with built-in progress
124
+ if (commandExists('curl')) {
125
+ await downloadWithCurl(downloadUrl, binPath);
126
+ } else {
127
+ await downloadWithNode(downloadUrl, binPath);
128
+ }
90
129
 
91
130
  // Make executable on Unix systems
92
131
  if (process.platform !== 'win32') {
93
132
  fs.chmodSync(binPath, 0o755);
94
133
  }
95
134
 
96
- console.log('owt installed successfully!');
135
+ console.log('owt installed successfully!');
97
136
  } catch (error) {
98
137
  console.error('Failed to download binary:', error.message);
99
138
  console.error('');
100
- console.error('You can manually install owt using cargo:');
139
+ console.error('Alternative installation methods:');
101
140
  console.error(' cargo install --git https://github.com/dding-g/oh-my-worktree');
102
141
  process.exit(1);
103
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oh-my-worktree",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "A TUI tool for managing Git worktrees in bare repositories",
5
5
  "keywords": [
6
6
  "git",