codexctl 0.4.4 → 0.4.6

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 (3) hide show
  1. package/codexctl.js +96 -0
  2. package/package.json +4 -3
  3. package/run.js +0 -0
package/codexctl.js ADDED
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CodexCTL Runner - Downloads binary on first run if not present
4
+ */
5
+
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const os = require('os');
9
+ const { spawn } = require('child_process');
10
+
11
+ 'use strict';
12
+ const VERSION = '0.4.4';
13
+
14
+ const PLATFORMS = {
15
+ 'linux-x64': { url: 'codexctl-x86_64-unknown-linux-gnu.tar.gz', ext: '.tar.gz' },
16
+ 'linux-arm64': { url: 'codexctl-aarch64-unknown-linux-gnu.tar.gz', ext: '.tar.gz' },
17
+ 'darwin-x64': { url: 'codexctl-x86_64-apple-darwin.tar.gz', ext: '.tar.gz' },
18
+ 'darwin-arm64': { url: 'codexctl-aarch64-apple-darwin.tar.gz', ext: '.tar.gz' },
19
+ 'win32-x64': { url: 'codexctl-x86_64-pc-windows-msvc.zip', ext: '.zip' }
20
+ };
21
+
22
+ function getPlatform() {
23
+ const key = `${os.platform()}-${os.arch()}`;
24
+ return PLATFORMS[key] || PLATFORMS['linux-x64'];
25
+ }
26
+
27
+ const binDir = path.join(__dirname, 'bin');
28
+ const platform = getPlatform();
29
+ const binName = platform.ext === '.zip' ? 'codexctl.exe' : 'codexctl';
30
+ const binPath = path.join(binDir, binName);
31
+
32
+ async function download() {
33
+ if (!fs.existsSync(binDir)) fs.mkdirSync(binDir, { recursive: true });
34
+ if (fs.existsSync(binPath)) return;
35
+
36
+ const https = require('https');
37
+ const url = `https://github.com/repohelper/codexctl/releases/download/v${VERSION}/${platform.url}`;
38
+
39
+ console.log(`Downloading codexctl ${VERSION} for ${os.platform()}-${os.arch()}...`);
40
+
41
+ return new Promise((resolve, reject) => {
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;
52
+ }
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);
82
+ });
83
+ }
84
+
85
+ async function main() {
86
+ await download();
87
+
88
+ if (os.platform() !== 'win32') {
89
+ try { fs.chmodSync(binPath, 0o755); } catch {}
90
+ }
91
+
92
+ const child = spawn(binPath, process.argv.slice(2), { stdio: 'inherit', windowsHide: true });
93
+ child.on('exit', (code) => process.exit(code ?? 0));
94
+ }
95
+
96
+ main().catch((err) => { console.error(err.message); process.exit(1); });
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "codexctl",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "Codex CLI Profile Manager - Manage multiple AI CLI accounts",
5
5
  "main": "index.js",
6
6
  "bin": {
7
- "codexctl": "./run.js",
8
- "cdx": "./run.js"
7
+ "codexctl": "./codexctl.js",
8
+ "cdx": "./codexctl.js"
9
9
  },
10
10
  "scripts": {
11
11
  "test": "echo 'Binary package - no tests'"
@@ -26,6 +26,7 @@
26
26
  },
27
27
  "files": [
28
28
  "run.js",
29
+ "codexctl.js",
29
30
  "index.js",
30
31
  "README.md",
31
32
  "LICENSE"
package/run.js CHANGED
File without changes