@merlean/analyzer 2.3.0 → 3.0.0

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.
@@ -1,156 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Postinstall script - Downloads the correct binary for the user's platform
5
- * from GitHub Releases
6
- */
7
-
8
- const https = require('https');
9
- const fs = require('fs');
10
- const path = require('path');
11
- const { execSync } = require('child_process');
12
-
13
- const REPO = 'zmaren/merlean';
14
- const BINARY_NAME = 'ai-bot-analyze';
15
- const VERSION = require('../package.json').version;
16
-
17
- // Map Node.js platform/arch to binary names
18
- function getBinaryName() {
19
- const platform = process.platform;
20
- const arch = process.arch;
21
-
22
- const platformMap = {
23
- 'darwin-arm64': 'ai-bot-analyze-macos-arm64',
24
- 'darwin-x64': 'ai-bot-analyze-macos-x64',
25
- 'linux-x64': 'ai-bot-analyze-linux-x64',
26
- 'win32-x64': 'ai-bot-analyze-win-x64.exe'
27
- };
28
-
29
- const key = `${platform}-${arch}`;
30
- const binaryName = platformMap[key];
31
-
32
- if (!binaryName) {
33
- console.error(`❌ Unsupported platform: ${platform}-${arch}`);
34
- console.error(' Supported: darwin-arm64, darwin-x64, linux-x64, win32-x64');
35
- console.error(' Falling back to source mode (requires Node.js)');
36
- return null;
37
- }
38
-
39
- return binaryName;
40
- }
41
-
42
- // Download binary from GitHub Releases
43
- async function downloadBinary(binaryName) {
44
- const binDir = path.join(__dirname, '..', 'bin');
45
- const binaryPath = path.join(binDir, process.platform === 'win32' ? `${BINARY_NAME}.exe` : BINARY_NAME);
46
-
47
- // Skip if binary already exists
48
- if (fs.existsSync(binaryPath)) {
49
- console.log('✓ Binary already exists');
50
- return true;
51
- }
52
-
53
- const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${binaryName}`;
54
-
55
- console.log(`📦 Downloading ${binaryName}...`);
56
- console.log(` From: ${url}`);
57
-
58
- return new Promise((resolve) => {
59
- const download = (downloadUrl, redirectCount = 0) => {
60
- if (redirectCount > 5) {
61
- console.error('❌ Too many redirects');
62
- resolve(false);
63
- return;
64
- }
65
-
66
- const protocol = downloadUrl.startsWith('https') ? https : require('http');
67
-
68
- protocol.get(downloadUrl, (response) => {
69
- // Handle redirects (GitHub releases redirect to S3)
70
- if (response.statusCode === 301 || response.statusCode === 302) {
71
- download(response.headers.location, redirectCount + 1);
72
- return;
73
- }
74
-
75
- if (response.statusCode === 404) {
76
- console.log(`⚠️ Binary not found for v${VERSION}`);
77
- console.log(' Falling back to source mode');
78
- resolve(false);
79
- return;
80
- }
81
-
82
- if (response.statusCode !== 200) {
83
- console.error(`❌ Download failed: HTTP ${response.statusCode}`);
84
- resolve(false);
85
- return;
86
- }
87
-
88
- // Ensure bin directory exists
89
- if (!fs.existsSync(binDir)) {
90
- fs.mkdirSync(binDir, { recursive: true });
91
- }
92
-
93
- const file = fs.createWriteStream(binaryPath);
94
- response.pipe(file);
95
-
96
- file.on('finish', () => {
97
- file.close();
98
-
99
- // Make executable on Unix
100
- if (process.platform !== 'win32') {
101
- fs.chmodSync(binaryPath, 0o755);
102
- }
103
-
104
- console.log('✓ Binary downloaded successfully');
105
- resolve(true);
106
- });
107
-
108
- file.on('error', (err) => {
109
- fs.unlink(binaryPath, () => {}); // Clean up
110
- console.error(`❌ Write error: ${err.message}`);
111
- resolve(false);
112
- });
113
-
114
- }).on('error', (err) => {
115
- console.error(`❌ Download error: ${err.message}`);
116
- resolve(false);
117
- });
118
- };
119
-
120
- download(url);
121
- });
122
- }
123
-
124
- // Mark that we're using source mode
125
- function setSourceMode() {
126
- const flagPath = path.join(__dirname, '..', '.source-mode');
127
- fs.writeFileSync(flagPath, 'true');
128
- }
129
-
130
- // Main
131
- async function main() {
132
- // Skip in CI environments during package build
133
- if (process.env.CI || process.env.PKG_EXECPATH) {
134
- console.log('⏭️ Skipping binary download (CI/build environment)');
135
- return;
136
- }
137
-
138
- const binaryName = getBinaryName();
139
-
140
- if (!binaryName) {
141
- setSourceMode();
142
- return;
143
- }
144
-
145
- const success = await downloadBinary(binaryName);
146
-
147
- if (!success) {
148
- setSourceMode();
149
- }
150
- }
151
-
152
- main().catch((err) => {
153
- console.error('Postinstall error:', err.message);
154
- // Don't fail install, fall back to source mode
155
- });
156
-