alurkerja-cli 1.0.1 → 1.0.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.
- package/index.js +64 -11
- package/index.js.backup +64 -11
- package/package.json +1 -1
- package/package.json.backup +1 -1
package/index.js
CHANGED
|
@@ -56,15 +56,19 @@ function getVersion() {
|
|
|
56
56
|
*/
|
|
57
57
|
async function downloadBinary(version, platform) {
|
|
58
58
|
const binaryName = `alurkerja-${platform.os}-${platform.arch}${platform.os === 'windows' ? '.exe' : ''}`;
|
|
59
|
-
|
|
59
|
+
// Use GitLab raw file download with correct parameters
|
|
60
|
+
const downloadUrl = `${GITLAB_BASE}/-/raw/master/dist/${binaryName}?ref_type=heads&inline=false`;
|
|
60
61
|
|
|
61
62
|
console.log(`📥 Downloading Alurkerja CLI ${version}...`);
|
|
62
63
|
|
|
63
64
|
// Ensure install directory exists
|
|
64
65
|
fs.mkdirSync(INSTALL_DIR, { recursive: true });
|
|
65
66
|
|
|
67
|
+
// Use temporary file to avoid ETXTBSY error
|
|
68
|
+
const tempPath = `${BINARY_PATH}.tmp`;
|
|
69
|
+
|
|
66
70
|
return new Promise((resolve, reject) => {
|
|
67
|
-
const file = fs.createWriteStream(
|
|
71
|
+
const file = fs.createWriteStream(tempPath);
|
|
68
72
|
|
|
69
73
|
const url = new URL(downloadUrl);
|
|
70
74
|
const options = {
|
|
@@ -88,32 +92,79 @@ async function downloadBinary(version, platform) {
|
|
|
88
92
|
};
|
|
89
93
|
return https.get(redirectOptions, (redirectRes) => {
|
|
90
94
|
redirectRes.pipe(file);
|
|
91
|
-
redirectRes.on('end', resolve);
|
|
92
95
|
});
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
if (res.statusCode !== 200) {
|
|
99
|
+
file.close();
|
|
100
|
+
fs.unlinkSync(tempPath);
|
|
96
101
|
reject(new Error(`Download failed with status ${res.statusCode}`));
|
|
97
102
|
return;
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
res.pipe(file);
|
|
101
|
-
res.on('end', resolve);
|
|
102
106
|
});
|
|
103
107
|
|
|
104
|
-
req.on('error',
|
|
108
|
+
req.on('error', (err) => {
|
|
109
|
+
file.close();
|
|
110
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
111
|
+
reject(err);
|
|
112
|
+
});
|
|
113
|
+
|
|
105
114
|
req.setTimeout(30000, () => {
|
|
106
115
|
req.abort();
|
|
116
|
+
file.close();
|
|
117
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
107
118
|
reject(new Error('Download timeout'));
|
|
108
119
|
});
|
|
109
120
|
|
|
110
|
-
file.on('error',
|
|
121
|
+
file.on('error', (err) => {
|
|
122
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
123
|
+
reject(err);
|
|
124
|
+
});
|
|
125
|
+
|
|
111
126
|
file.on('finish', () => {
|
|
112
|
-
file.close()
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
127
|
+
file.close((err) => {
|
|
128
|
+
if (err) {
|
|
129
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
130
|
+
reject(err);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Make executable on Unix systems before renaming
|
|
135
|
+
if (platform.os !== 'windows') {
|
|
136
|
+
try {
|
|
137
|
+
fs.chmodSync(tempPath, '755');
|
|
138
|
+
} catch (err) {
|
|
139
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
140
|
+
reject(new Error(`Failed to make binary executable: ${err.message}`));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Validate the downloaded file
|
|
146
|
+
const stats = fs.statSync(tempPath);
|
|
147
|
+
if (stats.size < 1000) {
|
|
148
|
+
// File too small, likely an error page
|
|
149
|
+
const content = fs.readFileSync(tempPath, 'utf8');
|
|
150
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
151
|
+
reject(new Error(`Download failed: received invalid file (${stats.size} bytes)`));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Rename temp file to final path
|
|
156
|
+
try {
|
|
157
|
+
// Remove old binary if exists
|
|
158
|
+
if (fs.existsSync(BINARY_PATH)) {
|
|
159
|
+
fs.unlinkSync(BINARY_PATH);
|
|
160
|
+
}
|
|
161
|
+
fs.renameSync(tempPath, BINARY_PATH);
|
|
162
|
+
resolve();
|
|
163
|
+
} catch (err) {
|
|
164
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
165
|
+
reject(new Error(`Failed to install binary: ${err.message}`));
|
|
166
|
+
}
|
|
167
|
+
});
|
|
117
168
|
});
|
|
118
169
|
});
|
|
119
170
|
}
|
|
@@ -178,6 +229,8 @@ async function bootstrap() {
|
|
|
178
229
|
if (needsDownload) {
|
|
179
230
|
await downloadBinary(version, platform);
|
|
180
231
|
console.log(`✅ Alurkerja CLI ${version} ready!`);
|
|
232
|
+
// Small delay to ensure file system sync after download
|
|
233
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
181
234
|
}
|
|
182
235
|
|
|
183
236
|
// Execute the binary with all arguments passed to this script
|
package/index.js.backup
CHANGED
|
@@ -56,15 +56,19 @@ function getVersion() {
|
|
|
56
56
|
*/
|
|
57
57
|
async function downloadBinary(version, platform) {
|
|
58
58
|
const binaryName = `alurkerja-${platform.os}-${platform.arch}${platform.os === 'windows' ? '.exe' : ''}`;
|
|
59
|
-
|
|
59
|
+
// Use GitLab raw file download with correct parameters
|
|
60
|
+
const downloadUrl = `${GITLAB_BASE}/-/raw/master/dist/${binaryName}?ref_type=heads&inline=false`;
|
|
60
61
|
|
|
61
62
|
console.log(`📥 Downloading Alurkerja CLI ${version}...`);
|
|
62
63
|
|
|
63
64
|
// Ensure install directory exists
|
|
64
65
|
fs.mkdirSync(INSTALL_DIR, { recursive: true });
|
|
65
66
|
|
|
67
|
+
// Use temporary file to avoid ETXTBSY error
|
|
68
|
+
const tempPath = `${BINARY_PATH}.tmp`;
|
|
69
|
+
|
|
66
70
|
return new Promise((resolve, reject) => {
|
|
67
|
-
const file = fs.createWriteStream(
|
|
71
|
+
const file = fs.createWriteStream(tempPath);
|
|
68
72
|
|
|
69
73
|
const url = new URL(downloadUrl);
|
|
70
74
|
const options = {
|
|
@@ -88,32 +92,79 @@ async function downloadBinary(version, platform) {
|
|
|
88
92
|
};
|
|
89
93
|
return https.get(redirectOptions, (redirectRes) => {
|
|
90
94
|
redirectRes.pipe(file);
|
|
91
|
-
redirectRes.on('end', resolve);
|
|
92
95
|
});
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
if (res.statusCode !== 200) {
|
|
99
|
+
file.close();
|
|
100
|
+
fs.unlinkSync(tempPath);
|
|
96
101
|
reject(new Error(`Download failed with status ${res.statusCode}`));
|
|
97
102
|
return;
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
res.pipe(file);
|
|
101
|
-
res.on('end', resolve);
|
|
102
106
|
});
|
|
103
107
|
|
|
104
|
-
req.on('error',
|
|
108
|
+
req.on('error', (err) => {
|
|
109
|
+
file.close();
|
|
110
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
111
|
+
reject(err);
|
|
112
|
+
});
|
|
113
|
+
|
|
105
114
|
req.setTimeout(30000, () => {
|
|
106
115
|
req.abort();
|
|
116
|
+
file.close();
|
|
117
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
107
118
|
reject(new Error('Download timeout'));
|
|
108
119
|
});
|
|
109
120
|
|
|
110
|
-
file.on('error',
|
|
121
|
+
file.on('error', (err) => {
|
|
122
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
123
|
+
reject(err);
|
|
124
|
+
});
|
|
125
|
+
|
|
111
126
|
file.on('finish', () => {
|
|
112
|
-
file.close()
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
127
|
+
file.close((err) => {
|
|
128
|
+
if (err) {
|
|
129
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
130
|
+
reject(err);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Make executable on Unix systems before renaming
|
|
135
|
+
if (platform.os !== 'windows') {
|
|
136
|
+
try {
|
|
137
|
+
fs.chmodSync(tempPath, '755');
|
|
138
|
+
} catch (err) {
|
|
139
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
140
|
+
reject(new Error(`Failed to make binary executable: ${err.message}`));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Validate the downloaded file
|
|
146
|
+
const stats = fs.statSync(tempPath);
|
|
147
|
+
if (stats.size < 1000) {
|
|
148
|
+
// File too small, likely an error page
|
|
149
|
+
const content = fs.readFileSync(tempPath, 'utf8');
|
|
150
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
151
|
+
reject(new Error(`Download failed: received invalid file (${stats.size} bytes)`));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Rename temp file to final path
|
|
156
|
+
try {
|
|
157
|
+
// Remove old binary if exists
|
|
158
|
+
if (fs.existsSync(BINARY_PATH)) {
|
|
159
|
+
fs.unlinkSync(BINARY_PATH);
|
|
160
|
+
}
|
|
161
|
+
fs.renameSync(tempPath, BINARY_PATH);
|
|
162
|
+
resolve();
|
|
163
|
+
} catch (err) {
|
|
164
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
165
|
+
reject(new Error(`Failed to install binary: ${err.message}`));
|
|
166
|
+
}
|
|
167
|
+
});
|
|
117
168
|
});
|
|
118
169
|
});
|
|
119
170
|
}
|
|
@@ -178,6 +229,8 @@ async function bootstrap() {
|
|
|
178
229
|
if (needsDownload) {
|
|
179
230
|
await downloadBinary(version, platform);
|
|
180
231
|
console.log(`✅ Alurkerja CLI ${version} ready!`);
|
|
232
|
+
// Small delay to ensure file system sync after download
|
|
233
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
181
234
|
}
|
|
182
235
|
|
|
183
236
|
// Execute the binary with all arguments passed to this script
|
package/package.json
CHANGED