codexdb-sdk 0.1.15 → 0.1.17
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/package.json +1 -1
- package/scripts/postinstall.js +141 -0
package/package.json
CHANGED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const os = require('os');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { https } = require('follow-redirects');
|
|
5
|
+
const { execSync } = require('child_process');
|
|
6
|
+
|
|
7
|
+
// Get package.json path relative to this script
|
|
8
|
+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
|
|
9
|
+
const packageJson = require(packageJsonPath);
|
|
10
|
+
const version = packageJson.version;
|
|
11
|
+
|
|
12
|
+
// Map platform to OS name in release
|
|
13
|
+
const OS_MAP = {
|
|
14
|
+
darwin: 'darwin',
|
|
15
|
+
linux: 'linux',
|
|
16
|
+
win32: 'windows'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Get system info
|
|
20
|
+
const platform = os.platform();
|
|
21
|
+
const osName = OS_MAP[platform];
|
|
22
|
+
const arch = os.arch() === 'arm64' ? 'arm64' : 'amd64';
|
|
23
|
+
|
|
24
|
+
if (!osName) {
|
|
25
|
+
console.log(`⚠️ No binary available for platform: ${platform}`);
|
|
26
|
+
process.exit(0); // Don't fail, just skip
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const dest = path.join(__dirname, '..', 'codex-cli' + (platform === 'win32' ? '.exe' : ''));
|
|
30
|
+
const tempDir = path.join(__dirname, '..', '.temp-extract');
|
|
31
|
+
|
|
32
|
+
console.log(`Fetching release info for v${version}...`);
|
|
33
|
+
|
|
34
|
+
// Fetch release information from GitHub API
|
|
35
|
+
const apiUrl = `https://api.github.com/repos/evertonmj/codex/releases/tags/v${version}`;
|
|
36
|
+
|
|
37
|
+
https.get(apiUrl, {
|
|
38
|
+
headers: { 'User-Agent': 'codex-postinstall' }
|
|
39
|
+
}, (res) => {
|
|
40
|
+
let data = '';
|
|
41
|
+
res.on('data', chunk => { data += chunk; });
|
|
42
|
+
res.on('end', () => {
|
|
43
|
+
try {
|
|
44
|
+
const release = JSON.parse(data);
|
|
45
|
+
|
|
46
|
+
// Check if the API returned an error
|
|
47
|
+
if (release.message) {
|
|
48
|
+
console.log(`⚠️ Release v${version} not found on GitHub`);
|
|
49
|
+
console.log(` This is normal during development before publishing`);
|
|
50
|
+
console.log(` The codex-cli binary will be available after creating a GitHub release`);
|
|
51
|
+
process.exit(0); // Don't fail, just skip
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!release.assets || !Array.isArray(release.assets)) {
|
|
55
|
+
console.log(`⚠️ Invalid release data: no assets found`);
|
|
56
|
+
process.exit(0); // Don't fail, just skip
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Find the correct binary for this platform/arch
|
|
60
|
+
const pattern = `codexdb_${version}_${osName}_${arch}`;
|
|
61
|
+
const asset = release.assets.find(a => a.name.includes(pattern));
|
|
62
|
+
|
|
63
|
+
if (!asset) {
|
|
64
|
+
console.log(`⚠️ No binary found for ${osName}/${arch}`);
|
|
65
|
+
console.log(` Expected pattern: ${pattern}`);
|
|
66
|
+
console.log(` Available assets: ${release.assets.map(a => a.name).join(', ')}`);
|
|
67
|
+
process.exit(0); // Don't fail, just skip
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
console.log(`Downloading ${asset.name}...`);
|
|
71
|
+
|
|
72
|
+
// Create temp directory
|
|
73
|
+
if (!fs.existsSync(tempDir)) {
|
|
74
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const tempFile = path.join(tempDir, asset.name);
|
|
78
|
+
|
|
79
|
+
https.get(asset.browser_download_url, (res) => {
|
|
80
|
+
if (res.statusCode !== 200) {
|
|
81
|
+
console.log(`⚠️ Failed to download binary: ${res.statusCode}`);
|
|
82
|
+
process.exit(0); // Don't fail, just skip
|
|
83
|
+
}
|
|
84
|
+
const file = fs.createWriteStream(tempFile);
|
|
85
|
+
res.pipe(file);
|
|
86
|
+
file.on('finish', () => {
|
|
87
|
+
file.close(() => {
|
|
88
|
+
extractAndInstall(tempFile, asset.name, dest, tempDir);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}).on('error', (err) => {
|
|
92
|
+
console.log(`⚠️ Download error: ${err.message}`);
|
|
93
|
+
process.exit(0); // Don't fail, just skip
|
|
94
|
+
});
|
|
95
|
+
} catch (err) {
|
|
96
|
+
console.log(`⚠️ Failed to parse release info: ${err.message}`);
|
|
97
|
+
process.exit(0); // Don't fail, just skip
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}).on('error', (err) => {
|
|
101
|
+
console.log(`⚠️ API error: ${err.message}`);
|
|
102
|
+
console.log(` The codex-cli binary must be downloaded manually or will be installed on first use`);
|
|
103
|
+
process.exit(0); // Don't fail, just skip
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
function extractAndInstall(archivePath, archiveName, destPath, tempDir) {
|
|
107
|
+
try {
|
|
108
|
+
console.log(`Extracting ${archiveName}...`);
|
|
109
|
+
|
|
110
|
+
if (archiveName.endsWith('.tar.gz')) {
|
|
111
|
+
execSync(`tar -xzf ${archivePath} -C ${tempDir}`);
|
|
112
|
+
} else if (archiveName.endsWith('.zip')) {
|
|
113
|
+
execSync(`unzip -q ${archivePath} -d ${tempDir}`);
|
|
114
|
+
} else if (archiveName.endsWith('.deb')) {
|
|
115
|
+
// For .deb files, extract the data
|
|
116
|
+
execSync(`ar x ${archivePath} data.tar.xz -o ${tempDir}/data.tar.xz`);
|
|
117
|
+
execSync(`tar -xf ${tempDir}/data.tar.xz -C ${tempDir}`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Find the binary in the extracted files
|
|
121
|
+
const files = execSync(`find ${tempDir} -type f -name 'codex-cli*' -o -name 'codexdb' 2>/dev/null`, { encoding: 'utf-8' }).trim().split('\n').filter(f => f);
|
|
122
|
+
|
|
123
|
+
if (files.length === 0) {
|
|
124
|
+
console.log('⚠️ Binary not found in archive');
|
|
125
|
+
process.exit(0); // Don't fail, just skip
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const binaryPath = files[0];
|
|
129
|
+
fs.copyFileSync(binaryPath, destPath);
|
|
130
|
+
fs.chmodSync(destPath, 0o755);
|
|
131
|
+
|
|
132
|
+
// Cleanup
|
|
133
|
+
execSync(`rm -rf ${tempDir}`);
|
|
134
|
+
|
|
135
|
+
console.log('✓ codex-cli installed to', destPath);
|
|
136
|
+
process.exit(0);
|
|
137
|
+
} catch (err) {
|
|
138
|
+
console.log(`⚠️ Extraction error: ${err.message}`);
|
|
139
|
+
process.exit(0); // Don't fail, just skip
|
|
140
|
+
}
|
|
141
|
+
}
|