@frumu/tandem 0.4.43 → 0.4.44
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/install.js +65 -5
package/package.json
CHANGED
package/scripts/install.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const https = require('https');
|
|
4
|
-
const { execSync } = require('child_process');
|
|
4
|
+
const { execFileSync, execSync } = require('child_process');
|
|
5
5
|
|
|
6
6
|
// Configuration
|
|
7
7
|
const REPO = "frumu-ai/tandem";
|
|
@@ -70,9 +70,47 @@ if (!fs.existsSync(binDir)) {
|
|
|
70
70
|
fs.mkdirSync(binDir, { recursive: true });
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
function parseVersion(raw) {
|
|
74
|
+
const match = String(raw || '').match(/\b(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)\b/);
|
|
75
|
+
return match ? match[1] : "";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function installedBinaryVersion(binaryPath, execFile = execFileSync) {
|
|
79
|
+
if (!fs.existsSync(binaryPath)) return "";
|
|
80
|
+
try {
|
|
81
|
+
const output = execFile(binaryPath, ['--version'], {
|
|
82
|
+
encoding: 'utf8',
|
|
83
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
84
|
+
timeout: 5000,
|
|
85
|
+
});
|
|
86
|
+
return parseVersion(output);
|
|
87
|
+
} catch {
|
|
88
|
+
return "";
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function shouldDownloadBinary(binaryPath, packageVersion, readVersion = installedBinaryVersion) {
|
|
93
|
+
if (!fs.existsSync(binaryPath)) {
|
|
94
|
+
return { download: true, reason: "missing" };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const stats = fs.statSync(binaryPath);
|
|
98
|
+
if (stats.size < MIN_SIZE) {
|
|
99
|
+
return { download: true, reason: `too small (${stats.size} bytes)` };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const installedVersion = readVersion(binaryPath);
|
|
103
|
+
if (!installedVersion) {
|
|
104
|
+
return { download: true, reason: "version check failed" };
|
|
105
|
+
}
|
|
106
|
+
if (installedVersion !== packageVersion) {
|
|
107
|
+
return {
|
|
108
|
+
download: true,
|
|
109
|
+
reason: `version mismatch (${installedVersion} != ${packageVersion})`,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return { download: false, reason: `version ${installedVersion} already installed` };
|
|
76
114
|
}
|
|
77
115
|
|
|
78
116
|
// Helper to fetch JSON from GitHub API
|
|
@@ -190,4 +228,26 @@ async function extract(archivePath) {
|
|
|
190
228
|
}
|
|
191
229
|
}
|
|
192
230
|
|
|
193
|
-
|
|
231
|
+
async function main() {
|
|
232
|
+
const packageVersion = require('../package.json').version;
|
|
233
|
+
const decision = shouldDownloadBinary(destPath, packageVersion);
|
|
234
|
+
if (!decision.download) {
|
|
235
|
+
console.log(`Binary already present (${decision.reason}).`);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (decision.reason !== "missing") {
|
|
239
|
+
console.log(`Existing binary will be replaced: ${decision.reason}.`);
|
|
240
|
+
}
|
|
241
|
+
const archivePath = await download();
|
|
242
|
+
await extract(archivePath);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (require.main === module) {
|
|
246
|
+
main().catch(warnAndExit);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
module.exports = {
|
|
250
|
+
installedBinaryVersion,
|
|
251
|
+
parseVersion,
|
|
252
|
+
shouldDownloadBinary,
|
|
253
|
+
};
|