agent-notify 0.2.1 → 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/scripts/install.js +98 -50
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
|
|
package/package.json
CHANGED
package/scripts/install.js
CHANGED
|
@@ -40,7 +40,7 @@ function getInstalledVersion(binaryPath) {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
function
|
|
43
|
+
function getRemoteArchiveName(version) {
|
|
44
44
|
const platform = os.platform();
|
|
45
45
|
const arch = os.arch();
|
|
46
46
|
|
|
@@ -62,19 +62,110 @@ function getRemoteBinaryName(version) {
|
|
|
62
62
|
throw new Error(`Unsupported platform: ${platform} ${arch}`);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
return `agent-notify-v${version}-${mappedPlatform}-${mappedArch}.tar.gz`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getBinaryNameInArchive(version) {
|
|
69
|
+
const platform = os.platform();
|
|
70
|
+
const arch = os.arch();
|
|
71
|
+
|
|
72
|
+
const platformMap = {
|
|
73
|
+
darwin: 'darwin',
|
|
74
|
+
linux: 'linux',
|
|
75
|
+
win32: 'windows'
|
|
76
|
+
};
|
|
68
77
|
|
|
69
|
-
|
|
78
|
+
const archMap = {
|
|
79
|
+
x64: 'amd64',
|
|
80
|
+
arm64: 'arm64'
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const mappedPlatform = platformMap[platform];
|
|
84
|
+
const mappedArch = archMap[arch];
|
|
85
|
+
|
|
86
|
+
if (platform === 'win32') {
|
|
87
|
+
return `agent-notify-v${version}-${mappedPlatform}-${mappedArch}.exe`;
|
|
88
|
+
}
|
|
89
|
+
return `agent-notify-v${version}-${mappedPlatform}-${mappedArch}`;
|
|
70
90
|
}
|
|
71
91
|
|
|
72
92
|
function getLocalBinaryName() {
|
|
73
93
|
return os.platform() === 'win32' ? 'agent-notify.exe' : 'agent-notify';
|
|
74
94
|
}
|
|
75
95
|
|
|
76
|
-
function getDownloadUrl(
|
|
77
|
-
return `https://github.com/${GITHUB_REPO}/releases/download/v${version}/${
|
|
96
|
+
function getDownloadUrl(archiveName, version) {
|
|
97
|
+
return `https://github.com/${GITHUB_REPO}/releases/download/v${version}/${archiveName}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function extractTarGz(archivePath, destDir) {
|
|
101
|
+
// Use tar command (available on macOS, Linux, and Windows 10+)
|
|
102
|
+
execSync(`tar -xzf "${archivePath}" -C "${destDir}"`, { stdio: 'inherit' });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function install() {
|
|
106
|
+
const archiveName = getRemoteArchiveName(PACKAGE_VERSION);
|
|
107
|
+
const binaryNameInArchive = getBinaryNameInArchive(PACKAGE_VERSION);
|
|
108
|
+
const localBinaryName = getLocalBinaryName();
|
|
109
|
+
const binaryPath = path.join(BINARY_DIR, localBinaryName);
|
|
110
|
+
|
|
111
|
+
// Check if binary already exists with correct version
|
|
112
|
+
if (fs.existsSync(binaryPath)) {
|
|
113
|
+
const installedVersion = getInstalledVersion(binaryPath);
|
|
114
|
+
if (installedVersion === PACKAGE_VERSION) {
|
|
115
|
+
console.log(`Binary already exists at ${binaryPath} (v${PACKAGE_VERSION})`);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
console.log(`Updating binary from v${installedVersion || 'unknown'} to v${PACKAGE_VERSION}...`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Create binary directory
|
|
122
|
+
if (!fs.existsSync(BINARY_DIR)) {
|
|
123
|
+
fs.mkdirSync(BINARY_DIR, { recursive: true });
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const url = getDownloadUrl(archiveName, PACKAGE_VERSION);
|
|
127
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-notify-'));
|
|
128
|
+
const archivePath = path.join(tempDir, archiveName);
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
// Download archive
|
|
132
|
+
await downloadFile(url, archivePath);
|
|
133
|
+
|
|
134
|
+
// Extract archive
|
|
135
|
+
console.log('Extracting...');
|
|
136
|
+
extractTarGz(archivePath, tempDir);
|
|
137
|
+
|
|
138
|
+
// Move binary to destination (use copy + unlink for cross-device support)
|
|
139
|
+
const extractedBinaryPath = path.join(tempDir, binaryNameInArchive);
|
|
140
|
+
if (fs.existsSync(binaryPath)) {
|
|
141
|
+
fs.unlinkSync(binaryPath);
|
|
142
|
+
}
|
|
143
|
+
fs.copyFileSync(extractedBinaryPath, binaryPath);
|
|
144
|
+
fs.unlinkSync(extractedBinaryPath);
|
|
145
|
+
|
|
146
|
+
// Make binary executable (Unix)
|
|
147
|
+
if (os.platform() !== 'win32') {
|
|
148
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
console.log(`Successfully installed binary to ${binaryPath}`);
|
|
152
|
+
console.log(`Ensure ${BINARY_DIR} is in your PATH.`);
|
|
153
|
+
} catch (err) {
|
|
154
|
+
console.error(`Failed to download binary: ${err.message}`);
|
|
155
|
+
console.error('');
|
|
156
|
+
console.error('Please ensure the release exists at:');
|
|
157
|
+
console.error(` ${url}`);
|
|
158
|
+
|
|
159
|
+
// Don't fail the install, let user download manually
|
|
160
|
+
process.exit(0);
|
|
161
|
+
} finally {
|
|
162
|
+
// Cleanup temp directory
|
|
163
|
+
try {
|
|
164
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
165
|
+
} catch (e) {
|
|
166
|
+
// Ignore cleanup errors
|
|
167
|
+
}
|
|
168
|
+
}
|
|
78
169
|
}
|
|
79
170
|
|
|
80
171
|
function downloadFile(url, dest) {
|
|
@@ -132,49 +223,6 @@ function downloadFile(url, dest) {
|
|
|
132
223
|
});
|
|
133
224
|
}
|
|
134
225
|
|
|
135
|
-
async function install() {
|
|
136
|
-
const remoteBinaryName = getRemoteBinaryName(PACKAGE_VERSION);
|
|
137
|
-
const localBinaryName = getLocalBinaryName();
|
|
138
|
-
const binaryPath = path.join(BINARY_DIR, localBinaryName);
|
|
139
|
-
|
|
140
|
-
// Check if binary already exists with correct version
|
|
141
|
-
if (fs.existsSync(binaryPath)) {
|
|
142
|
-
const installedVersion = getInstalledVersion(binaryPath);
|
|
143
|
-
if (installedVersion === PACKAGE_VERSION) {
|
|
144
|
-
console.log(`Binary already exists at ${binaryPath} (v${PACKAGE_VERSION})`);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
console.log(`Updating binary from v${installedVersion || 'unknown'} to v${PACKAGE_VERSION}...`);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Create binary directory
|
|
151
|
-
if (!fs.existsSync(BINARY_DIR)) {
|
|
152
|
-
fs.mkdirSync(BINARY_DIR, { recursive: true });
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const url = getDownloadUrl(remoteBinaryName, PACKAGE_VERSION);
|
|
156
|
-
|
|
157
|
-
try {
|
|
158
|
-
await downloadFile(url, binaryPath);
|
|
159
|
-
|
|
160
|
-
// Make binary executable (Unix)
|
|
161
|
-
if (os.platform() !== 'win32') {
|
|
162
|
-
fs.chmodSync(binaryPath, 0o755);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
console.log(`Successfully installed binary to ${binaryPath}`);
|
|
166
|
-
console.log(`Ensure ${BINARY_DIR} is in your PATH.`);
|
|
167
|
-
} catch (err) {
|
|
168
|
-
console.error(`Failed to download binary: ${err.message}`);
|
|
169
|
-
console.error('');
|
|
170
|
-
console.error('Please ensure the release exists at:');
|
|
171
|
-
console.error(` ${url}`);
|
|
172
|
-
|
|
173
|
-
// Don't fail the install, let user download manually
|
|
174
|
-
process.exit(0);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
226
|
install().catch((err) => {
|
|
179
227
|
console.error(err.message);
|
|
180
228
|
process.exit(1);
|