librats 0.3.1 → 0.5.1
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/README.md +405 -405
- package/binding.gyp +96 -95
- package/lib/index.d.ts +522 -522
- package/lib/index.js +82 -82
- package/native-src/3rdparty/android/ifaddrs-android.c +600 -0
- package/native-src/3rdparty/android/ifaddrs-android.h +54 -0
- package/native-src/CMakeLists.txt +360 -0
- package/native-src/LICENSE +21 -0
- package/native-src/src/bencode.cpp +485 -0
- package/native-src/src/bencode.h +145 -0
- package/native-src/src/bittorrent.cpp +3682 -0
- package/native-src/src/bittorrent.h +731 -0
- package/native-src/src/dht.cpp +2342 -0
- package/native-src/src/dht.h +501 -0
- package/native-src/src/encrypted_socket.cpp +817 -0
- package/native-src/src/encrypted_socket.h +239 -0
- package/native-src/src/file_transfer.cpp +1808 -0
- package/native-src/src/file_transfer.h +567 -0
- package/native-src/src/fs.cpp +639 -0
- package/native-src/src/fs.h +108 -0
- package/native-src/src/gossipsub.cpp +1137 -0
- package/native-src/src/gossipsub.h +403 -0
- package/native-src/src/ice.cpp +1386 -0
- package/native-src/src/ice.h +328 -0
- package/native-src/src/json.hpp +25526 -0
- package/native-src/src/krpc.cpp +558 -0
- package/native-src/src/krpc.h +145 -0
- package/native-src/src/librats.cpp +2715 -0
- package/native-src/src/librats.h +1729 -0
- package/native-src/src/librats_bittorrent.cpp +167 -0
- package/native-src/src/librats_c.cpp +1317 -0
- package/native-src/src/librats_c.h +237 -0
- package/native-src/src/librats_encryption.cpp +123 -0
- package/native-src/src/librats_file_transfer.cpp +226 -0
- package/native-src/src/librats_gossipsub.cpp +293 -0
- package/native-src/src/librats_ice.cpp +515 -0
- package/native-src/src/librats_logging.cpp +158 -0
- package/native-src/src/librats_mdns.cpp +171 -0
- package/native-src/src/librats_nat.cpp +571 -0
- package/native-src/src/librats_persistence.cpp +815 -0
- package/native-src/src/logger.h +412 -0
- package/native-src/src/mdns.cpp +1178 -0
- package/native-src/src/mdns.h +253 -0
- package/native-src/src/network_utils.cpp +598 -0
- package/native-src/src/network_utils.h +162 -0
- package/native-src/src/noise.cpp +981 -0
- package/native-src/src/noise.h +227 -0
- package/native-src/src/os.cpp +371 -0
- package/native-src/src/os.h +40 -0
- package/native-src/src/rats_export.h +17 -0
- package/native-src/src/sha1.cpp +163 -0
- package/native-src/src/sha1.h +42 -0
- package/native-src/src/socket.cpp +1376 -0
- package/native-src/src/socket.h +309 -0
- package/native-src/src/stun.cpp +484 -0
- package/native-src/src/stun.h +349 -0
- package/native-src/src/threadmanager.cpp +105 -0
- package/native-src/src/threadmanager.h +53 -0
- package/native-src/src/tracker.cpp +1110 -0
- package/native-src/src/tracker.h +268 -0
- package/native-src/src/version.cpp +24 -0
- package/native-src/src/version.h.in +45 -0
- package/native-src/version.rc.in +31 -0
- package/package.json +62 -68
- package/scripts/build-librats.js +241 -194
- package/scripts/postinstall.js +52 -52
- package/scripts/prepare-package.js +187 -91
- package/scripts/verify-installation.js +119 -119
- package/src/librats_node.cpp +1174 -1174
package/scripts/build-librats.js
CHANGED
|
@@ -1,194 +1,241 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { execSync } = require('child_process');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const os = require('os');
|
|
7
|
-
|
|
8
|
-
// Determine platform
|
|
9
|
-
const isWindows = process.platform === 'win32';
|
|
10
|
-
const isMac = process.platform === 'darwin';
|
|
11
|
-
const isLinux = process.platform === 'linux';
|
|
12
|
-
|
|
13
|
-
// Paths
|
|
14
|
-
const nodejsRoot = path.resolve(__dirname, '..');
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
console.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
console.error('
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
console.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
]
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
console.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
console.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execSync } = require('child_process');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
|
|
8
|
+
// Determine platform
|
|
9
|
+
const isWindows = process.platform === 'win32';
|
|
10
|
+
const isMac = process.platform === 'darwin';
|
|
11
|
+
const isLinux = process.platform === 'linux';
|
|
12
|
+
|
|
13
|
+
// Paths
|
|
14
|
+
const nodejsRoot = path.resolve(__dirname, '..');
|
|
15
|
+
const buildDir = path.resolve(nodejsRoot, 'build-native');
|
|
16
|
+
|
|
17
|
+
// Determine source location:
|
|
18
|
+
// 1. When installed from npm: sources are in nodejs/native-src/
|
|
19
|
+
// 2. When developing locally: sources are in project root (../../ from scripts)
|
|
20
|
+
let projectRoot;
|
|
21
|
+
let srcDir;
|
|
22
|
+
let cmakeLists;
|
|
23
|
+
|
|
24
|
+
const nativeSrcDir = path.resolve(nodejsRoot, 'native-src');
|
|
25
|
+
const devProjectRoot = path.resolve(__dirname, '..', '..');
|
|
26
|
+
|
|
27
|
+
if (fs.existsSync(path.join(nativeSrcDir, 'CMakeLists.txt'))) {
|
|
28
|
+
// npm install scenario: use native-src directory
|
|
29
|
+
projectRoot = nativeSrcDir;
|
|
30
|
+
srcDir = path.resolve(nativeSrcDir, 'src');
|
|
31
|
+
cmakeLists = path.resolve(nativeSrcDir, 'CMakeLists.txt');
|
|
32
|
+
console.log('Using bundled source files from native-src/');
|
|
33
|
+
} else if (fs.existsSync(path.join(devProjectRoot, 'CMakeLists.txt'))) {
|
|
34
|
+
// Development scenario: use parent directory
|
|
35
|
+
projectRoot = devProjectRoot;
|
|
36
|
+
srcDir = path.resolve(devProjectRoot, 'src');
|
|
37
|
+
cmakeLists = path.resolve(devProjectRoot, 'CMakeLists.txt');
|
|
38
|
+
console.log('Using source files from project root (development mode)');
|
|
39
|
+
} else {
|
|
40
|
+
console.error('ERROR: Cannot find librats source files.');
|
|
41
|
+
console.error('');
|
|
42
|
+
console.error('Checked locations:');
|
|
43
|
+
console.error(` - ${nativeSrcDir} (npm install)`);
|
|
44
|
+
console.error(` - ${devProjectRoot} (development)`);
|
|
45
|
+
console.error('');
|
|
46
|
+
console.error('If you installed from npm, the package may be corrupted.');
|
|
47
|
+
console.error('Try: npm cache clean --force && npm install librats');
|
|
48
|
+
console.error('');
|
|
49
|
+
console.error('If you are developing locally, make sure you are in the librats repository.');
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
console.log('Building librats native library...');
|
|
54
|
+
console.log(`Platform: ${process.platform}`);
|
|
55
|
+
console.log(`Source root: ${projectRoot}`);
|
|
56
|
+
console.log(`Build directory: ${buildDir}`);
|
|
57
|
+
|
|
58
|
+
// Check if CMake is installed
|
|
59
|
+
try {
|
|
60
|
+
execSync('cmake --version', { stdio: 'pipe' });
|
|
61
|
+
console.log('✓ CMake found');
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error('\n❌ ERROR: CMake is not installed or not in PATH');
|
|
64
|
+
console.error('\nCMake is required to build librats.');
|
|
65
|
+
console.error('Please install CMake:');
|
|
66
|
+
if (isWindows) {
|
|
67
|
+
console.error(' - Download from: https://cmake.org/download/');
|
|
68
|
+
console.error(' - Or use: winget install Kitware.CMake');
|
|
69
|
+
console.error(' - Or use: choco install cmake');
|
|
70
|
+
} else if (isMac) {
|
|
71
|
+
console.error(' - Use Homebrew: brew install cmake');
|
|
72
|
+
console.error(' - Or download from: https://cmake.org/download/');
|
|
73
|
+
} else if (isLinux) {
|
|
74
|
+
console.error(' - Use: sudo apt install cmake');
|
|
75
|
+
console.error(' - Or: sudo yum install cmake');
|
|
76
|
+
console.error(' - Or download from: https://cmake.org/download/');
|
|
77
|
+
}
|
|
78
|
+
console.error('\nAfter installing CMake, run: npm install\n');
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Verify CMakeLists.txt exists
|
|
83
|
+
if (!fs.existsSync(cmakeLists)) {
|
|
84
|
+
console.error('ERROR: CMakeLists.txt not found.');
|
|
85
|
+
console.error(`Expected at: ${cmakeLists}`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Verify src directory exists
|
|
90
|
+
if (!fs.existsSync(srcDir)) {
|
|
91
|
+
console.error('ERROR: src directory not found.');
|
|
92
|
+
console.error(`Expected at: ${srcDir}`);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Create build directory if it doesn't exist
|
|
97
|
+
if (!fs.existsSync(buildDir)) {
|
|
98
|
+
console.log(`Creating build directory: ${buildDir}`);
|
|
99
|
+
fs.mkdirSync(buildDir, { recursive: true });
|
|
100
|
+
} else {
|
|
101
|
+
// Clear CMake cache if it exists to avoid source directory mismatch errors
|
|
102
|
+
const cmakeCache = path.join(buildDir, 'CMakeCache.txt');
|
|
103
|
+
if (fs.existsSync(cmakeCache)) {
|
|
104
|
+
console.log('Clearing existing CMake cache...');
|
|
105
|
+
fs.unlinkSync(cmakeCache);
|
|
106
|
+
|
|
107
|
+
// Also remove CMakeFiles directory for a clean reconfigure
|
|
108
|
+
const cmakeFiles = path.join(buildDir, 'CMakeFiles');
|
|
109
|
+
if (fs.existsSync(cmakeFiles)) {
|
|
110
|
+
fs.rmSync(cmakeFiles, { recursive: true, force: true });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Helper function to execute commands
|
|
116
|
+
function exec(command, options = {}) {
|
|
117
|
+
console.log(`> ${command}`);
|
|
118
|
+
try {
|
|
119
|
+
execSync(command, {
|
|
120
|
+
cwd: buildDir,
|
|
121
|
+
stdio: 'inherit',
|
|
122
|
+
...options
|
|
123
|
+
});
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error(`Command failed: ${command}`);
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
// Configure CMake with appropriate options
|
|
132
|
+
console.log('\nConfiguring CMake...');
|
|
133
|
+
|
|
134
|
+
let cmakeArgs = [
|
|
135
|
+
'-DRATS_BUILD_TESTS=OFF',
|
|
136
|
+
'-DRATS_BUILD_EXAMPLES=OFF',
|
|
137
|
+
'-DRATS_STATIC_LIBRARY=ON',
|
|
138
|
+
'-DRATS_BINDINGS=ON',
|
|
139
|
+
'-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL'
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
// Add platform-specific CMake arguments
|
|
143
|
+
if (isWindows) {
|
|
144
|
+
// Try to detect Visual Studio version
|
|
145
|
+
const vsVersions = ['2022', '2019', '2017'];
|
|
146
|
+
let generator = null;
|
|
147
|
+
|
|
148
|
+
for (const version of vsVersions) {
|
|
149
|
+
try {
|
|
150
|
+
execSync(`where "C:\\Program Files\\Microsoft Visual Studio\\${version}"`, { stdio: 'ignore' });
|
|
151
|
+
generator = `Visual Studio ${version === '2022' ? '17' : version === '2019' ? '16' : '15'} ${version}`;
|
|
152
|
+
break;
|
|
153
|
+
} catch (e) {
|
|
154
|
+
// Try next version
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (generator) {
|
|
159
|
+
cmakeArgs.push(`-G "${generator}"`);
|
|
160
|
+
cmakeArgs.push('-A x64');
|
|
161
|
+
}
|
|
162
|
+
} else if (isMac) {
|
|
163
|
+
// Use Unix Makefiles on macOS
|
|
164
|
+
cmakeArgs.push('-G "Unix Makefiles"');
|
|
165
|
+
} else if (isLinux) {
|
|
166
|
+
// Use Unix Makefiles on Linux
|
|
167
|
+
cmakeArgs.push('-G "Unix Makefiles"');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Calculate the relative path from build directory to source root
|
|
171
|
+
const relativePath = path.relative(buildDir, projectRoot);
|
|
172
|
+
const cmakeConfigCmd = `cmake ${cmakeArgs.join(' ')} "${relativePath}"`;
|
|
173
|
+
exec(cmakeConfigCmd);
|
|
174
|
+
|
|
175
|
+
// Build the library
|
|
176
|
+
console.log('\nBuilding librats library...');
|
|
177
|
+
|
|
178
|
+
if (isWindows) {
|
|
179
|
+
// Build both Debug and Release configurations on Windows
|
|
180
|
+
exec('cmake --build . --config Debug --parallel');
|
|
181
|
+
exec('cmake --build . --config Release --parallel');
|
|
182
|
+
console.log('\nLibrats built successfully (Debug and Release)');
|
|
183
|
+
} else {
|
|
184
|
+
exec('cmake --build . -- -j4');
|
|
185
|
+
console.log('\nLibrats built successfully');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Verify the library was built
|
|
189
|
+
const expectedLibPaths = isWindows
|
|
190
|
+
? [
|
|
191
|
+
path.join(buildDir, 'lib', 'Debug', 'rats.lib'),
|
|
192
|
+
path.join(buildDir, 'lib', 'Release', 'rats.lib')
|
|
193
|
+
]
|
|
194
|
+
: [
|
|
195
|
+
path.join(buildDir, 'lib', 'librats.a')
|
|
196
|
+
];
|
|
197
|
+
|
|
198
|
+
console.log('\nBuild directory:', buildDir);
|
|
199
|
+
|
|
200
|
+
let foundLib = false;
|
|
201
|
+
for (const libPath of expectedLibPaths) {
|
|
202
|
+
if (fs.existsSync(libPath)) {
|
|
203
|
+
console.log(`✓ Found library: ${libPath}`);
|
|
204
|
+
foundLib = true;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (!foundLib) {
|
|
209
|
+
console.warn('WARNING: Could not find built library files.');
|
|
210
|
+
console.warn('Expected paths:');
|
|
211
|
+
expectedLibPaths.forEach(p => console.warn(` - ${p}`));
|
|
212
|
+
console.warn('The build may have failed. Check the output above.');
|
|
213
|
+
// Don't exit with error - let node-gyp try anyway
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
console.log('\n✓ Librats build completed successfully!\n');
|
|
217
|
+
|
|
218
|
+
} catch (error) {
|
|
219
|
+
console.error('\n✗ Failed to build librats library');
|
|
220
|
+
console.error('Error:', error.message);
|
|
221
|
+
|
|
222
|
+
// Provide helpful error messages
|
|
223
|
+
console.error('\nTroubleshooting:');
|
|
224
|
+
|
|
225
|
+
if (isWindows) {
|
|
226
|
+
console.error('- Ensure Visual Studio Build Tools or Visual Studio is installed');
|
|
227
|
+
console.error('- Download from: https://visualstudio.microsoft.com/downloads/');
|
|
228
|
+
console.error('- Or run: npm install --global windows-build-tools');
|
|
229
|
+
} else if (isMac) {
|
|
230
|
+
console.error('- Ensure Xcode Command Line Tools are installed');
|
|
231
|
+
console.error('- Run: xcode-select --install');
|
|
232
|
+
} else if (isLinux) {
|
|
233
|
+
console.error('- Ensure build-essential is installed');
|
|
234
|
+
console.error('- Run: sudo apt install build-essential cmake');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
console.error('- Ensure CMake is installed and available in PATH');
|
|
238
|
+
console.error('- CMake download: https://cmake.org/download/');
|
|
239
|
+
|
|
240
|
+
process.exit(1);
|
|
241
|
+
}
|
package/scripts/postinstall.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
|
|
6
|
-
// Check if we're in a development install (node_modules doesn't contain librats)
|
|
7
|
-
const isDev = !__dirname.includes('node_modules');
|
|
8
|
-
|
|
9
|
-
if (isDev) {
|
|
10
|
-
console.log('\n✨ Development installation detected');
|
|
11
|
-
console.log(' Librats native addon has been built for local development\n');
|
|
12
|
-
} else {
|
|
13
|
-
console.log('\n✅ Librats installed successfully!');
|
|
14
|
-
console.log(' Native addon is ready to use\n');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Check if the addon was built successfully
|
|
18
|
-
const possiblePaths = [
|
|
19
|
-
path.join(__dirname, '..', 'build', 'Release', 'librats.node'),
|
|
20
|
-
path.join(__dirname, '..', 'build', 'Debug', 'librats.node'),
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
let addonFound = false;
|
|
24
|
-
for (const addonPath of possiblePaths) {
|
|
25
|
-
if (fs.existsSync(addonPath)) {
|
|
26
|
-
addonFound = true;
|
|
27
|
-
if (process.env.LIBRATS_DEBUG) {
|
|
28
|
-
console.log(` Native addon: ${addonPath}`);
|
|
29
|
-
}
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (!addonFound) {
|
|
35
|
-
console.warn('⚠️ Warning: Native addon not found');
|
|
36
|
-
console.warn(' The build may have failed. Try running:');
|
|
37
|
-
console.warn(' npm rebuild librats\n');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Show quick start example
|
|
41
|
-
if (!process.env.CI && !process.env.npm_config_global) {
|
|
42
|
-
console.log('Verify installation:');
|
|
43
|
-
console.log(' npm run verify\n');
|
|
44
|
-
console.log('Quick start:');
|
|
45
|
-
console.log('```javascript');
|
|
46
|
-
console.log("const { RatsClient } = require('librats');");
|
|
47
|
-
console.log('const client = new RatsClient(8080);');
|
|
48
|
-
console.log('client.start();');
|
|
49
|
-
console.log('```\n');
|
|
50
|
-
console.log('Documentation: https://github.com/librats/librats/tree/main/nodejs\n');
|
|
51
|
-
}
|
|
52
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
// Check if we're in a development install (node_modules doesn't contain librats)
|
|
7
|
+
const isDev = !__dirname.includes('node_modules');
|
|
8
|
+
|
|
9
|
+
if (isDev) {
|
|
10
|
+
console.log('\n✨ Development installation detected');
|
|
11
|
+
console.log(' Librats native addon has been built for local development\n');
|
|
12
|
+
} else {
|
|
13
|
+
console.log('\n✅ Librats installed successfully!');
|
|
14
|
+
console.log(' Native addon is ready to use\n');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Check if the addon was built successfully
|
|
18
|
+
const possiblePaths = [
|
|
19
|
+
path.join(__dirname, '..', 'build', 'Release', 'librats.node'),
|
|
20
|
+
path.join(__dirname, '..', 'build', 'Debug', 'librats.node'),
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
let addonFound = false;
|
|
24
|
+
for (const addonPath of possiblePaths) {
|
|
25
|
+
if (fs.existsSync(addonPath)) {
|
|
26
|
+
addonFound = true;
|
|
27
|
+
if (process.env.LIBRATS_DEBUG) {
|
|
28
|
+
console.log(` Native addon: ${addonPath}`);
|
|
29
|
+
}
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!addonFound) {
|
|
35
|
+
console.warn('⚠️ Warning: Native addon not found');
|
|
36
|
+
console.warn(' The build may have failed. Try running:');
|
|
37
|
+
console.warn(' npm rebuild librats\n');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Show quick start example
|
|
41
|
+
if (!process.env.CI && !process.env.npm_config_global) {
|
|
42
|
+
console.log('Verify installation:');
|
|
43
|
+
console.log(' npm run verify\n');
|
|
44
|
+
console.log('Quick start:');
|
|
45
|
+
console.log('```javascript');
|
|
46
|
+
console.log("const { RatsClient } = require('librats');");
|
|
47
|
+
console.log('const client = new RatsClient(8080);');
|
|
48
|
+
console.log('client.start();');
|
|
49
|
+
console.log('```\n');
|
|
50
|
+
console.log('Documentation: https://github.com/librats/librats/tree/main/nodejs\n');
|
|
51
|
+
}
|
|
52
|
+
|