agent-notify 0.2.0 → 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.
- package/package.json +1 -1
- package/scripts/install.js +109 -46
package/package.json
CHANGED
package/scripts/install.js
CHANGED
|
@@ -29,7 +29,18 @@ function getBinaryDir() {
|
|
|
29
29
|
|
|
30
30
|
const BINARY_DIR = getBinaryDir();
|
|
31
31
|
|
|
32
|
-
function
|
|
32
|
+
function getInstalledVersion(binaryPath) {
|
|
33
|
+
try {
|
|
34
|
+
const version = execSync(`"${binaryPath}" --version`, { encoding: 'utf8', timeout: 5000 }).trim();
|
|
35
|
+
// version output like: agent-notify version 0.1.0
|
|
36
|
+
const match = version.match(/(\d+\.\d+\.\d+)/);
|
|
37
|
+
return match ? match[1] : null;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getRemoteArchiveName(version) {
|
|
33
44
|
const platform = os.platform();
|
|
34
45
|
const arch = os.arch();
|
|
35
46
|
|
|
@@ -51,19 +62,110 @@ function getRemoteBinaryName(version) {
|
|
|
51
62
|
throw new Error(`Unsupported platform: ${platform} ${arch}`);
|
|
52
63
|
}
|
|
53
64
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
: `agent-notify-v${version}-${mappedPlatform}-${mappedArch}`;
|
|
65
|
+
return `agent-notify-v${version}-${mappedPlatform}-${mappedArch}.tar.gz`;
|
|
66
|
+
}
|
|
57
67
|
|
|
58
|
-
|
|
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
|
+
};
|
|
77
|
+
|
|
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}`;
|
|
59
90
|
}
|
|
60
91
|
|
|
61
92
|
function getLocalBinaryName() {
|
|
62
93
|
return os.platform() === 'win32' ? 'agent-notify.exe' : 'agent-notify';
|
|
63
94
|
}
|
|
64
95
|
|
|
65
|
-
function getDownloadUrl(
|
|
66
|
-
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
|
+
}
|
|
67
169
|
}
|
|
68
170
|
|
|
69
171
|
function downloadFile(url, dest) {
|
|
@@ -121,45 +223,6 @@ function downloadFile(url, dest) {
|
|
|
121
223
|
});
|
|
122
224
|
}
|
|
123
225
|
|
|
124
|
-
async function install() {
|
|
125
|
-
const remoteBinaryName = getRemoteBinaryName(PACKAGE_VERSION);
|
|
126
|
-
const localBinaryName = getLocalBinaryName();
|
|
127
|
-
const binaryPath = path.join(BINARY_DIR, localBinaryName);
|
|
128
|
-
|
|
129
|
-
// Check if binary already exists
|
|
130
|
-
if (fs.existsSync(binaryPath)) {
|
|
131
|
-
console.log(`Binary already exists at ${binaryPath}`);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Create binary directory
|
|
136
|
-
if (!fs.existsSync(BINARY_DIR)) {
|
|
137
|
-
fs.mkdirSync(BINARY_DIR, { recursive: true });
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const url = getDownloadUrl(remoteBinaryName, PACKAGE_VERSION);
|
|
141
|
-
|
|
142
|
-
try {
|
|
143
|
-
await downloadFile(url, binaryPath);
|
|
144
|
-
|
|
145
|
-
// Make binary executable (Unix)
|
|
146
|
-
if (os.platform() !== 'win32') {
|
|
147
|
-
fs.chmodSync(binaryPath, 0o755);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
console.log(`Successfully installed binary to ${binaryPath}`);
|
|
151
|
-
console.log(`Ensure ${BINARY_DIR} is in your PATH.`);
|
|
152
|
-
} catch (err) {
|
|
153
|
-
console.error(`Failed to download binary: ${err.message}`);
|
|
154
|
-
console.error('');
|
|
155
|
-
console.error('Please ensure the release exists at:');
|
|
156
|
-
console.error(` ${url}`);
|
|
157
|
-
|
|
158
|
-
// Don't fail the install, let user download manually
|
|
159
|
-
process.exit(0);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
226
|
install().catch((err) => {
|
|
164
227
|
console.error(err.message);
|
|
165
228
|
process.exit(1);
|