agent-notify 0.2.3 → 0.2.4
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/bin/agent-notify.js +50 -14
- package/package.json +1 -1
package/bin/agent-notify.js
CHANGED
|
@@ -6,26 +6,58 @@ const path = require('path');
|
|
|
6
6
|
const os = require('os');
|
|
7
7
|
const fs = require('fs');
|
|
8
8
|
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
function getBinaryName() {
|
|
10
|
+
return os.platform() === 'win32' ? 'agent-notify.exe' : 'agent-notify';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getBinaryPath() {
|
|
14
|
+
const binaryName = getBinaryName();
|
|
15
|
+
const searchPaths = [];
|
|
16
|
+
|
|
17
|
+
// 1. npm global bin directory
|
|
12
18
|
try {
|
|
13
19
|
const prefix = execSync('npm prefix -g', { encoding: 'utf8' }).trim();
|
|
14
|
-
|
|
20
|
+
if (os.platform() === 'win32') {
|
|
21
|
+
searchPaths.push(prefix);
|
|
22
|
+
} else {
|
|
23
|
+
searchPaths.push(path.join(prefix, 'bin'));
|
|
24
|
+
}
|
|
15
25
|
} catch (e) {
|
|
16
|
-
//
|
|
17
|
-
return path.join(os.homedir(), '.local', 'bin');
|
|
26
|
+
// npm not available
|
|
18
27
|
}
|
|
19
|
-
}
|
|
20
28
|
|
|
21
|
-
|
|
29
|
+
// 2. GOPATH/bin
|
|
30
|
+
if (process.env.GOPATH) {
|
|
31
|
+
searchPaths.push(path.join(process.env.GOPATH, 'bin'));
|
|
32
|
+
}
|
|
22
33
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
34
|
+
// 3. HOME/go/bin (default GOPATH)
|
|
35
|
+
searchPaths.push(path.join(os.homedir(), 'go', 'bin'));
|
|
26
36
|
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
// 4. ~/.local/bin
|
|
38
|
+
searchPaths.push(path.join(os.homedir(), '.local', 'bin'));
|
|
39
|
+
|
|
40
|
+
// 5. Search in PATH
|
|
41
|
+
try {
|
|
42
|
+
const whichCmd = os.platform() === 'win32' ? 'where' : 'which';
|
|
43
|
+
const result = execSync(`${whichCmd} ${binaryName}`, { encoding: 'utf8' }).trim();
|
|
44
|
+
if (result) {
|
|
45
|
+
return result.split('\n')[0].trim();
|
|
46
|
+
}
|
|
47
|
+
} catch (e) {
|
|
48
|
+
// Not found in PATH
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Return first existing path or first search path as default
|
|
52
|
+
for (const searchPath of searchPaths) {
|
|
53
|
+
const binaryPath = path.join(searchPath, binaryName);
|
|
54
|
+
if (fs.existsSync(binaryPath)) {
|
|
55
|
+
return binaryPath;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Fallback to npm global bin
|
|
60
|
+
return path.join(searchPaths[0] || path.join(os.homedir(), '.local', 'bin'), binaryName);
|
|
29
61
|
}
|
|
30
62
|
|
|
31
63
|
function run() {
|
|
@@ -33,7 +65,11 @@ function run() {
|
|
|
33
65
|
|
|
34
66
|
if (!fs.existsSync(binaryPath)) {
|
|
35
67
|
console.error(`Binary not found at ${binaryPath}`);
|
|
36
|
-
console.error('
|
|
68
|
+
console.error('');
|
|
69
|
+
console.error('Please install agent-notify first:');
|
|
70
|
+
console.error(' npx agent-notify # auto-download');
|
|
71
|
+
console.error(' or');
|
|
72
|
+
console.error(' go install github.com/hellolib/agent-notify/cmd/agent-notify@latest');
|
|
37
73
|
process.exit(1);
|
|
38
74
|
}
|
|
39
75
|
|