codebuff-cli 1.0.17 → 1.0.18
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/cli/bin/codebuff.cjs
CHANGED
|
@@ -12,6 +12,7 @@ const REPO = 'Marcus-Mok-GH/codebuff-cli';
|
|
|
12
12
|
const moduleBinary = path.join(__dirname, process.platform === 'win32' ? `${BINARY_NAME}.exe` : BINARY_NAME);
|
|
13
13
|
const localDir = path.join(os.homedir(), '.codebuff', 'bin');
|
|
14
14
|
const localBinary = path.join(localDir, process.platform === 'win32' ? `${BINARY_NAME}.exe` : BINARY_NAME);
|
|
15
|
+
const VERSION_FILE = path.join(localDir, '.version');
|
|
15
16
|
|
|
16
17
|
function resolveBinaryPath() {
|
|
17
18
|
if (fs.existsSync(localBinary)) return localBinary;
|
|
@@ -33,6 +34,22 @@ function getVersion() {
|
|
|
33
34
|
return null;
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
function getCachedVersion() {
|
|
38
|
+
try {
|
|
39
|
+
return fs.readFileSync(VERSION_FILE, 'utf8').trim();
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function writeVersionFile(version) {
|
|
46
|
+
try {
|
|
47
|
+
fs.writeFileSync(VERSION_FILE, version, 'utf8');
|
|
48
|
+
} catch (err) {
|
|
49
|
+
// Ignore write errors - version file is best-effort
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
36
53
|
function download(url, dest) {
|
|
37
54
|
return new Promise((resolve, reject) => {
|
|
38
55
|
const client = url.startsWith('https:') ? https : http;
|
|
@@ -134,6 +151,16 @@ function runBinary(binaryPath) {
|
|
|
134
151
|
}
|
|
135
152
|
|
|
136
153
|
async function main() {
|
|
154
|
+
const pkgVersion = getVersion();
|
|
155
|
+
const cachedVersion = getCachedVersion();
|
|
156
|
+
|
|
157
|
+
// Check if local cache is stale
|
|
158
|
+
if (fs.existsSync(localBinary) && pkgVersion && cachedVersion !== pkgVersion) {
|
|
159
|
+
console.log(`Binary cache outdated (${cachedVersion || 'none'} → ${pkgVersion}). Re-downloading...`);
|
|
160
|
+
try { fs.unlinkSync(localBinary); } catch {}
|
|
161
|
+
try { fs.unlinkSync(VERSION_FILE); } catch {}
|
|
162
|
+
}
|
|
163
|
+
|
|
137
164
|
let binaryPath = resolveBinaryPath();
|
|
138
165
|
|
|
139
166
|
if (binaryPath) {
|
|
@@ -145,6 +172,7 @@ async function main() {
|
|
|
145
172
|
|
|
146
173
|
try {
|
|
147
174
|
await downloadBinary(localBinary);
|
|
175
|
+
if (pkgVersion) writeVersionFile(pkgVersion);
|
|
148
176
|
binaryPath = localBinary;
|
|
149
177
|
} catch (err) {
|
|
150
178
|
console.error('Failed to download codebuff:', err.message);
|
|
@@ -143,6 +143,13 @@ async function main() {
|
|
|
143
143
|
|
|
144
144
|
if (await downloadWithRetry(url, binaryPath)) {
|
|
145
145
|
console.log('Download complete.');
|
|
146
|
+
const versionFile = path.join(path.dirname(binaryPath), '.version');
|
|
147
|
+
try {
|
|
148
|
+
fs.writeFileSync(versionFile, version, 'utf8');
|
|
149
|
+
console.log('Version file written.');
|
|
150
|
+
} catch (err) {
|
|
151
|
+
console.warn('Warning: could not write version file:', err.message);
|
|
152
|
+
}
|
|
146
153
|
} else {
|
|
147
154
|
console.error('\nUnable to download the codebuff binary.');
|
|
148
155
|
console.error('You can try installing manually from:');
|