agent-notify 0.2.3 → 0.2.5

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.
Files changed (2) hide show
  1. package/package.json +2 -1
  2. package/scripts/install.js +64 -2
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "agent-notify",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
+ "agentnotifyversion": "0.2.4",
4
5
  "description": "Agent notification tool with Feishu integration",
5
6
  "bin": {
6
7
  "agent-notify": "./bin/agent-notify.js"
@@ -7,9 +7,43 @@ const path = require('path');
7
7
  const os = require('os');
8
8
  const { execSync } = require('child_process');
9
9
 
10
- const PACKAGE_VERSION = require('../package.json').version;
10
+ const PACKAGE_VERSION = require('../package.json').agentnotifyversion;
11
11
  const GITHUB_REPO = 'hellolib/agent-notify';
12
12
 
13
+ // Possible locations where agent-notify might be installed
14
+ function getCommonBinaryDirs() {
15
+ const dirs = [];
16
+ const binaryName = os.platform() === 'win32' ? 'agent-notify.exe' : 'agent-notify';
17
+
18
+ // GOPATH/bin
19
+ if (process.env.GOPATH) {
20
+ dirs.push(path.join(process.env.GOPATH, 'bin'));
21
+ }
22
+ // GOBIN
23
+ if (process.env.GOBIN) {
24
+ dirs.push(process.env.GOBIN);
25
+ }
26
+ // Default Go bin directory
27
+ dirs.push(path.join(os.homedir(), 'go', 'bin'));
28
+ // ~/.local/bin
29
+ dirs.push(path.join(os.homedir(), '.local', 'bin'));
30
+ // /usr/local/bin
31
+ dirs.push('/usr/local/bin');
32
+
33
+ return dirs;
34
+ }
35
+
36
+ function findExistingBinary(binaryName) {
37
+ const dirs = getCommonBinaryDirs();
38
+ for (const dir of dirs) {
39
+ const binaryPath = path.join(dir, binaryName);
40
+ if (fs.existsSync(binaryPath)) {
41
+ return binaryPath;
42
+ }
43
+ }
44
+ return null;
45
+ }
46
+
13
47
  function getBinaryDir() {
14
48
  // Try to get npm global bin directory
15
49
  // npm bin -g is deprecated, use npm prefix -g instead
@@ -108,7 +142,7 @@ async function install() {
108
142
  const localBinaryName = getLocalBinaryName();
109
143
  const binaryPath = path.join(BINARY_DIR, localBinaryName);
110
144
 
111
- // Check if binary already exists with correct version
145
+ // Check if binary already exists in npm bin directory with correct version
112
146
  if (fs.existsSync(binaryPath)) {
113
147
  const installedVersion = getInstalledVersion(binaryPath);
114
148
  if (installedVersion === PACKAGE_VERSION) {
@@ -116,6 +150,34 @@ async function install() {
116
150
  return;
117
151
  }
118
152
  console.log(`Updating binary from v${installedVersion || 'unknown'} to v${PACKAGE_VERSION}...`);
153
+ } else {
154
+ // Check if binary exists in other common directories
155
+ const existingBinary = findExistingBinary(localBinaryName);
156
+ if (existingBinary) {
157
+ const existingVersion = getInstalledVersion(existingBinary);
158
+ if (existingVersion === PACKAGE_VERSION) {
159
+ // Same version, copy/link to npm bin directory
160
+ console.log(`Found existing binary at ${existingBinary} (v${PACKAGE_VERSION})`);
161
+ console.log(`Copying to npm bin directory: ${binaryPath}`);
162
+
163
+ if (!fs.existsSync(BINARY_DIR)) {
164
+ fs.mkdirSync(BINARY_DIR, { recursive: true });
165
+ }
166
+
167
+ fs.copyFileSync(existingBinary, binaryPath);
168
+ if (os.platform() !== 'win32') {
169
+ fs.chmodSync(binaryPath, 0o755);
170
+ }
171
+ console.log('Done!');
172
+ return;
173
+ } else if (existingVersion) {
174
+ console.log(`Found existing binary at ${existingBinary} (v${existingVersion}), but need v${PACKAGE_VERSION}`);
175
+ console.log('Installing new version to npm bin directory...');
176
+ } else {
177
+ console.log(`Found existing binary at ${existingBinary}, but version unknown`);
178
+ console.log('Installing to npm bin directory...');
179
+ }
180
+ }
119
181
  }
120
182
 
121
183
  // Create binary directory