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.
Files changed (2) hide show
  1. package/codexctl.js +40 -19
  2. 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.4.4';
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
- https.get(url, (res) => {
43
- if (res.statusCode === 302 || res.statusCode === 301) {
44
- download(res.headers.location).then(resolve).catch(reject);
45
- return;
46
- }
47
- const file = fs.createWriteStream(path.join(binDir, 'download' + platform.ext));
48
- res.pipe(file);
49
- file.on('finish', () => {
50
- if (platform.ext === '.zip') {
51
- const { execSync } = require('child_process');
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
- fs.unlinkSync(file.path);
58
- resolve();
59
- });
60
- }).on('error', reject);
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexctl",
3
- "version": "0.4.5",
3
+ "version": "0.5.0",
4
4
  "description": "Codex CLI Profile Manager - Manage multiple AI CLI accounts",
5
5
  "main": "index.js",
6
6
  "bin": {