termify-agent 1.0.10 → 1.0.12
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 +5 -3
- package/scripts/postinstall.js +148 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "termify-agent",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "Termify Agent CLI - Connect your local terminal to Termify",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"dev": "tsc --watch",
|
|
13
13
|
"start": "node dist/index.js",
|
|
14
14
|
"lint": "eslint src --ext .ts",
|
|
15
|
-
"clean": "rm -rf dist"
|
|
15
|
+
"clean": "rm -rf dist",
|
|
16
|
+
"postinstall": "node scripts/postinstall.js"
|
|
16
17
|
},
|
|
17
18
|
"keywords": [
|
|
18
19
|
"termify",
|
|
@@ -43,6 +44,7 @@
|
|
|
43
44
|
},
|
|
44
45
|
"files": [
|
|
45
46
|
"dist",
|
|
46
|
-
"bin"
|
|
47
|
+
"bin",
|
|
48
|
+
"scripts"
|
|
47
49
|
]
|
|
48
50
|
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Termify Agent - Postinstall Script
|
|
5
|
+
*
|
|
6
|
+
* Runs automatically after `npm install` to:
|
|
7
|
+
* 1. Rebuild node-pty native module for the current platform
|
|
8
|
+
* 2. Download the stats-agent binary for system monitoring
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { execSync } from 'child_process';
|
|
12
|
+
import { createWriteStream, mkdirSync, chmodSync, existsSync } from 'fs';
|
|
13
|
+
import { join } from 'path';
|
|
14
|
+
import { homedir, platform, arch } from 'os';
|
|
15
|
+
import { get } from 'https';
|
|
16
|
+
|
|
17
|
+
const DOWNLOAD_BASE_URL = 'https://termify.justdiego.com/api/downloads/stats-agent';
|
|
18
|
+
const TERMIFY_DIR = join(homedir(), '.termify');
|
|
19
|
+
const STATS_AGENT_PATH = join(TERMIFY_DIR, 'stats-agent');
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Step 1: Rebuild node-pty
|
|
23
|
+
*/
|
|
24
|
+
function rebuildNodePty() {
|
|
25
|
+
console.log('[termify-agent] Rebuilding node-pty for your platform...');
|
|
26
|
+
try {
|
|
27
|
+
execSync('npm rebuild node-pty', {
|
|
28
|
+
stdio: 'pipe',
|
|
29
|
+
timeout: 120000,
|
|
30
|
+
});
|
|
31
|
+
console.log('[termify-agent] node-pty rebuilt successfully.');
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.warn('[termify-agent] Warning: Failed to rebuild node-pty.');
|
|
34
|
+
console.warn('[termify-agent] Terminal features may not work. Try running: npm rebuild node-pty');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Step 2: Download stats-agent binary
|
|
40
|
+
*/
|
|
41
|
+
async function downloadStatsAgent() {
|
|
42
|
+
const plat = platform();
|
|
43
|
+
const ar = arch();
|
|
44
|
+
|
|
45
|
+
// Map Node.js platform/arch to our binary names
|
|
46
|
+
const platformMap = {
|
|
47
|
+
'darwin-arm64': 'darwin-arm64',
|
|
48
|
+
'darwin-x64': 'darwin-x64',
|
|
49
|
+
'linux-x64': 'linux-x64',
|
|
50
|
+
'linux-arm64': 'linux-arm64',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const key = `${plat}-${ar}`;
|
|
54
|
+
const binaryName = platformMap[key];
|
|
55
|
+
|
|
56
|
+
if (!binaryName) {
|
|
57
|
+
console.warn(`[termify-agent] Warning: No stats-agent binary available for ${key}.`);
|
|
58
|
+
console.warn('[termify-agent] System stats collection will be disabled.');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Skip if already exists
|
|
63
|
+
if (existsSync(STATS_AGENT_PATH)) {
|
|
64
|
+
console.log('[termify-agent] stats-agent binary already exists, skipping download.');
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
console.log(`[termify-agent] Downloading stats-agent for ${binaryName}...`);
|
|
69
|
+
|
|
70
|
+
// Ensure ~/.termify directory exists
|
|
71
|
+
mkdirSync(TERMIFY_DIR, { recursive: true });
|
|
72
|
+
|
|
73
|
+
const url = `${DOWNLOAD_BASE_URL}/${binaryName}`;
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
await downloadFile(url, STATS_AGENT_PATH);
|
|
77
|
+
chmodSync(STATS_AGENT_PATH, 0o755);
|
|
78
|
+
console.log(`[termify-agent] stats-agent installed to ${STATS_AGENT_PATH}`);
|
|
79
|
+
} catch (err) {
|
|
80
|
+
console.warn(`[termify-agent] Warning: Failed to download stats-agent: ${err.message}`);
|
|
81
|
+
console.warn('[termify-agent] System stats collection will be disabled.');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Download a file following redirects (up to 5)
|
|
87
|
+
*/
|
|
88
|
+
function downloadFile(url, dest, redirects = 0) {
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
if (redirects > 5) {
|
|
91
|
+
return reject(new Error('Too many redirects'));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const request = get(url, (response) => {
|
|
95
|
+
// Handle redirects
|
|
96
|
+
if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
|
|
97
|
+
return downloadFile(response.headers.location, dest, redirects + 1)
|
|
98
|
+
.then(resolve)
|
|
99
|
+
.catch(reject);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (response.statusCode !== 200) {
|
|
103
|
+
return reject(new Error(`HTTP ${response.statusCode}`));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const file = createWriteStream(dest);
|
|
107
|
+
response.pipe(file);
|
|
108
|
+
file.on('finish', () => {
|
|
109
|
+
file.close();
|
|
110
|
+
resolve();
|
|
111
|
+
});
|
|
112
|
+
file.on('error', (err) => {
|
|
113
|
+
file.close();
|
|
114
|
+
reject(err);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
request.on('error', reject);
|
|
119
|
+
request.setTimeout(60000, () => {
|
|
120
|
+
request.destroy();
|
|
121
|
+
reject(new Error('Download timed out'));
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Main
|
|
128
|
+
*/
|
|
129
|
+
async function main() {
|
|
130
|
+
console.log('[termify-agent] Running postinstall...');
|
|
131
|
+
|
|
132
|
+
rebuildNodePty();
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
await downloadStatsAgent();
|
|
136
|
+
} catch (err) {
|
|
137
|
+
// Non-fatal - stats is optional
|
|
138
|
+
console.warn(`[termify-agent] Warning: ${err.message}`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
console.log('[termify-agent] Postinstall complete.');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
main().catch((err) => {
|
|
145
|
+
console.warn(`[termify-agent] Postinstall warning: ${err.message}`);
|
|
146
|
+
// Never fail the install - postinstall errors should be warnings only
|
|
147
|
+
process.exit(0);
|
|
148
|
+
});
|