xero-cli-bin 1.7.2 → 1.7.3

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 +2 -2
  2. package/scripts/install.js +73 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xero-cli-bin",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "Xero Accounting API CLI - Xero 會計 API 命令行工具",
5
5
  "bin": {
6
6
  "xero-cli": "./bin/xero-cli"
@@ -15,7 +15,7 @@
15
15
  "dependencies": {
16
16
  "extract-zip": "^2.0.1",
17
17
  "node-downloader-helper": "^2.1.9",
18
- "tar": "^6.2.0"
18
+ "tar": "^7.0.0"
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",
@@ -87,7 +87,7 @@ async function downloadFromGitHubRelease() {
87
87
  });
88
88
  }
89
89
 
90
- fs.unlinkSync(downloadPath);
90
+ await deleteWithRetry(downloadPath);
91
91
 
92
92
  const binaryPath = join(extractDir, getFileName());
93
93
 
@@ -95,6 +95,78 @@ async function downloadFromGitHubRelease() {
95
95
  fs.chmodSync(binaryPath, 0o755);
96
96
  }
97
97
 
98
+ console.log('[xero-cli-bin] Installation complete!');
99
+ console.log(`[xero-cli-bin] Binary installed to: ${binaryPath}`);
100
+ } catch (error) {
101
+ if (fs.existsSync(downloadPath)) {
102
+ await deleteWithRetry(downloadPath);
103
+ }
104
+ throw error;
105
+ }
106
+ }
107
+
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
+
98
170
  console.log('[xero-cli-bin] Installation complete!');
99
171
  console.log(`[xero-cli-bin] Binary installed to: ${binaryPath}`);
100
172
  } catch (error) {