thoth-cli 0.2.0 → 0.2.2
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 +3 -2
- package/scripts/postinstall.js +102 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "thoth-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "𓅝 Astrological calculations from the command line. Swiss Ephemeris precision. Built for humans and agents.",
|
|
5
5
|
"author": "AKLO <aklo@aklolabs.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"dist",
|
|
15
|
-
"bin"
|
|
15
|
+
"bin",
|
|
16
|
+
"scripts"
|
|
16
17
|
],
|
|
17
18
|
"scripts": {
|
|
18
19
|
"build": "tsup src/index.ts src/bin.ts --format esm --dts --clean",
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Postinstall script - downloads the correct thoth-core binary
|
|
4
|
+
* 𓅝
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { platform, arch } from 'os';
|
|
8
|
+
import { join, dirname } from 'path';
|
|
9
|
+
import { existsSync, mkdirSync, createWriteStream, chmodSync } from 'fs';
|
|
10
|
+
import { fileURLToPath } from 'url';
|
|
11
|
+
import https from 'https';
|
|
12
|
+
|
|
13
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
|
|
15
|
+
const VERSION = '0.1.0';
|
|
16
|
+
const REPO = 'aklo/thoth-cli';
|
|
17
|
+
const BASE_URL = `https://github.com/${REPO}/releases/download/v${VERSION}`;
|
|
18
|
+
|
|
19
|
+
function getPlatformKey() {
|
|
20
|
+
const p = platform();
|
|
21
|
+
const a = arch();
|
|
22
|
+
|
|
23
|
+
const platformMap = {
|
|
24
|
+
'darwin': 'darwin',
|
|
25
|
+
'linux': 'linux',
|
|
26
|
+
'win32': 'win32',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const archMap = {
|
|
30
|
+
'x64': 'x64',
|
|
31
|
+
'arm64': 'arm64',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return `${platformMap[p]}-${archMap[a]}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getBinaryName() {
|
|
38
|
+
return platform() === 'win32' ? 'thoth-core.exe' : 'thoth-core';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function download(url, dest) {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const file = createWriteStream(dest);
|
|
44
|
+
|
|
45
|
+
https.get(url, (response) => {
|
|
46
|
+
// Handle redirects
|
|
47
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
48
|
+
download(response.headers.location, dest).then(resolve).catch(reject);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (response.statusCode !== 200) {
|
|
53
|
+
reject(new Error(`Failed to download: ${response.statusCode}`));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
response.pipe(file);
|
|
58
|
+
file.on('finish', () => {
|
|
59
|
+
file.close();
|
|
60
|
+
resolve();
|
|
61
|
+
});
|
|
62
|
+
}).on('error', reject);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function main() {
|
|
67
|
+
const platformKey = getPlatformKey();
|
|
68
|
+
const binaryName = getBinaryName();
|
|
69
|
+
const binDir = join(__dirname, '..', 'bin', platformKey);
|
|
70
|
+
const binaryPath = join(binDir, binaryName);
|
|
71
|
+
|
|
72
|
+
// Skip if binary already exists
|
|
73
|
+
if (existsSync(binaryPath)) {
|
|
74
|
+
console.log(`✓ thoth-core binary already exists`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
console.log(`Downloading thoth-core for ${platformKey}...`);
|
|
79
|
+
|
|
80
|
+
// Create bin directory
|
|
81
|
+
mkdirSync(binDir, { recursive: true });
|
|
82
|
+
|
|
83
|
+
// Download binary
|
|
84
|
+
const url = `${BASE_URL}/thoth-core-${platformKey}${platform() === 'win32' ? '.exe' : ''}`;
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
await download(url, binaryPath);
|
|
88
|
+
|
|
89
|
+
// Make executable on Unix
|
|
90
|
+
if (platform() !== 'win32') {
|
|
91
|
+
chmodSync(binaryPath, 0o755);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
console.log(`✓ Downloaded thoth-core to ${binaryPath}`);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.warn(`⚠ Could not download binary: ${error.message}`);
|
|
97
|
+
console.warn(` You can run in development mode with Python installed.`);
|
|
98
|
+
console.warn(` Install thoth-core: pip install thoth-core`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
main().catch(console.error);
|