agent-notify 0.2.1 → 0.2.3

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 +1 -1
  2. package/scripts/install.js +98 -50
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-notify",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Agent notification tool with Feishu integration",
5
5
  "bin": {
6
6
  "agent-notify": "./bin/agent-notify.js"
@@ -40,7 +40,7 @@ function getInstalledVersion(binaryPath) {
40
40
  }
41
41
  }
42
42
 
43
- function getRemoteBinaryName(version) {
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
- const binaryName = platform === 'win32'
66
- ? `agent-notify-v${version}-${mappedPlatform}-${mappedArch}.exe`
67
- : `agent-notify-v${version}-${mappedPlatform}-${mappedArch}`;
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
- return binaryName;
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(binaryName, version) {
77
- return `https://github.com/${GITHUB_REPO}/releases/download/v${version}/${binaryName}`;
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);