codexctl 0.4.5 → 0.5.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.
- package/codexctl.js +40 -19
- package/package.json +1 -1
package/codexctl.js
CHANGED
|
@@ -9,7 +9,7 @@ const os = require('os');
|
|
|
9
9
|
const { spawn } = require('child_process');
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
|
-
const VERSION = '0.
|
|
12
|
+
const VERSION = '0.5.0';
|
|
13
13
|
|
|
14
14
|
const PLATFORMS = {
|
|
15
15
|
'linux-x64': { url: 'codexctl-x86_64-unknown-linux-gnu.tar.gz', ext: '.tar.gz' },
|
|
@@ -39,25 +39,46 @@ async function download() {
|
|
|
39
39
|
console.log(`Downloading codexctl ${VERSION} for ${os.platform()}-${os.arch()}...`);
|
|
40
40
|
|
|
41
41
|
return new Promise((resolve, reject) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
execSync(`powershell -Command "Expand-Archive -Path '${file.path}' -DestinationPath '${binDir}' -Force"`);
|
|
53
|
-
} else {
|
|
54
|
-
const { execSync } = require('child_process');
|
|
55
|
-
execSync(`tar -xzf '${file.path}' -C '${binDir}'`);
|
|
42
|
+
const doDownload = (downloadUrl) => {
|
|
43
|
+
https.get(downloadUrl, (res) => {
|
|
44
|
+
if (res.statusCode === 302 || res.statusCode === 301) {
|
|
45
|
+
const redirectUrl = res.headers.location;
|
|
46
|
+
if (!redirectUrl) {
|
|
47
|
+
reject(new Error('Redirect without location'));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
doDownload(redirectUrl);
|
|
51
|
+
return;
|
|
56
52
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
if (res.statusCode !== 200) {
|
|
54
|
+
reject(new Error(`Download failed with status ${res.statusCode}`));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const file = fs.createWriteStream(path.join(binDir, 'download' + platform.ext));
|
|
58
|
+
res.pipe(file);
|
|
59
|
+
file.on('finish', () => {
|
|
60
|
+
try {
|
|
61
|
+
if (platform.ext === '.zip') {
|
|
62
|
+
const { execSync } = require('child_process');
|
|
63
|
+
execSync(`powershell -Command "Expand-Archive -Path '${file.path}' -DestinationPath '${binDir}' -Force"`, { stdio: 'ignore' });
|
|
64
|
+
} else {
|
|
65
|
+
const { execSync } = require('child_process');
|
|
66
|
+
execSync(`tar -xzf '${file.path}' -C '${binDir}'`, { stdio: 'ignore' });
|
|
67
|
+
}
|
|
68
|
+
fs.unlinkSync(file.path);
|
|
69
|
+
if (!fs.existsSync(binPath)) {
|
|
70
|
+
reject(new Error('Downloaded file not found after extraction'));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
resolve();
|
|
74
|
+
} catch (err) {
|
|
75
|
+
reject(err);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
file.on('error', reject);
|
|
79
|
+
}).on('error', reject);
|
|
80
|
+
};
|
|
81
|
+
doDownload(url);
|
|
61
82
|
});
|
|
62
83
|
}
|
|
63
84
|
|