xero-cli-bin 1.7.3 → 1.7.4

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/package.json +1 -1
  2. package/scripts/install.js +18 -72
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xero-cli-bin",
3
- "version": "1.7.3",
3
+ "version": "1.7.4",
4
4
  "description": "Xero Accounting API CLI - Xero 會計 API 命令行工具",
5
5
  "bin": {
6
6
  "xero-cli": "./bin/xero-cli"
@@ -28,6 +28,24 @@ function getFileName() {
28
28
  return platform === 'win32' ? 'xero-cli.exe' : 'xero-cli';
29
29
  }
30
30
 
31
+ async function deleteWithRetry(filePath, maxRetries = 3) {
32
+ for (let i = 0; i < maxRetries; i++) {
33
+ try {
34
+ if (platform === 'win32') {
35
+ fs.rmSync(filePath, { force: true, recursive: true });
36
+ } else {
37
+ fs.unlinkSync(filePath);
38
+ }
39
+ return;
40
+ } catch (error) {
41
+ if (i === maxRetries - 1) {
42
+ throw error;
43
+ }
44
+ await new Promise(resolve => setTimeout(resolve, 500 * (i + 1)));
45
+ }
46
+ }
47
+ }
48
+
31
49
  async function downloadFromGitHubRelease() {
32
50
  const pkg = require('../package.json');
33
51
  const version = pkg.version.replace(/^v/, '');
@@ -105,78 +123,6 @@ async function downloadFromGitHubRelease() {
105
123
  }
106
124
  }
107
125
 
108
- async function deleteWithRetry(filePath, maxRetries = 3) {
109
- for (let i = 0; i < maxRetries; i++) {
110
- try {
111
- if (platform === 'win32') {
112
- fs.rmSync(filePath, { force: true, recursive: true });
113
- } else {
114
- fs.unlinkSync(filePath);
115
- }
116
- return;
117
- } catch (error) {
118
- if (i === maxRetries - 1) {
119
- throw error;
120
- }
121
- await new Promise(resolve => setTimeout(resolve, 500 * (i + 1)));
122
- }
123
- }
124
- }
125
- });
126
-
127
- dl.on('progress', (stats) => {
128
- const percent = stats.progress.toFixed(1);
129
- const downloaded = (stats.downloaded / 1024 / 1024).toFixed(2);
130
- const total = (stats.total / 1024 / 1024).toFixed(2);
131
- process.stdout.write(`[xero-cli-bin] Downloading: ${percent}% (${downloaded}/${total} MB)\r`);
132
- });
133
-
134
- dl.on('end', () => {
135
- console.log('\n[xero-cli-bin] Download completed');
136
- resolve();
137
- });
138
-
139
- dl.on('error', (err) => {
140
- reject(err);
141
- });
142
-
143
- dl.start();
144
- });
145
-
146
- console.log('[xero-cli-bin] Extracting...');
147
-
148
- if (!fs.existsSync(extractDir)) {
149
- fs.mkdirSync(extractDir, { recursive: true });
150
- }
151
-
152
- if (platform === 'win32') {
153
- await extractZip(downloadPath, { dir: extractDir });
154
- } else {
155
- await tar.x({
156
- file: downloadPath,
157
- cwd: extractDir,
158
- strip: 0
159
- });
160
- }
161
-
162
- fs.unlinkSync(downloadPath);
163
-
164
- const binaryPath = join(extractDir, getFileName());
165
-
166
- if (platform !== 'win32') {
167
- fs.chmodSync(binaryPath, 0755);
168
- }
169
-
170
- console.log('[xero-cli-bin] Installation complete!');
171
- console.log(`[xero-cli-bin] Binary installed to: ${binaryPath}`);
172
- } catch (error) {
173
- if (fs.existsSync(downloadPath)) {
174
- fs.unlinkSync(downloadPath);
175
- }
176
- throw error;
177
- }
178
- }
179
-
180
126
  console.log(`[xero-cli-bin] Platform: ${platform} ${arch}`);
181
127
  console.log(`[xero-cli-bin] Node.js: ${process.version}`);
182
128