netspeed-test-cli 1.2.1 → 1.4.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 +24 -42
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -107,9 +107,9 @@ async function pingTest() {
|
|
|
107
107
|
|
|
108
108
|
function printHeader() {
|
|
109
109
|
console.log();
|
|
110
|
-
console.log(chalk.cyan.bold('
|
|
111
|
-
console.log(chalk.cyan.bold('│') + chalk.white.bold('
|
|
112
|
-
console.log(chalk.cyan.bold('
|
|
110
|
+
console.log(chalk.cyan.bold(' ┌──────────────────────────┐'));
|
|
111
|
+
console.log(chalk.cyan.bold(' │') + chalk.white.bold(' NETSPEED CLI v1 ') + chalk.cyan.bold('│'));
|
|
112
|
+
console.log(chalk.cyan.bold(' └──────────────────────────┘'));
|
|
113
113
|
console.log();
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -119,39 +119,11 @@ function printResult(type, value, icon) {
|
|
|
119
119
|
upload: chalk.magenta,
|
|
120
120
|
ping: chalk.yellow
|
|
121
121
|
};
|
|
122
|
-
|
|
123
|
-
console.log();
|
|
124
|
-
console.log(` ${chalk.white('┌─ ' + type.toUpperCase() + ' ─────────────┐')}`);
|
|
125
|
-
console.log(chalk.white(' │ ') + colors[type](`${icon} ${value}`) + ' '.repeat(15 - value.toString().length) + chalk.white('│'));
|
|
126
|
-
console.log(chalk.white(' └' + '─'.repeat(20) + '┘'));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async function main() {
|
|
130
|
-
printHeader();
|
|
131
|
-
|
|
132
|
-
console.log(chalk.gray(' Starting speed test...\n'));
|
|
133
|
-
|
|
134
|
-
const pingStop = showSpinner('Measuring ping...');
|
|
135
|
-
const ping = await pingTest();
|
|
136
|
-
pingStop();
|
|
137
|
-
clearLine();
|
|
138
|
-
printResult('ping', `${ping} ms`, '⚡');
|
|
139
|
-
|
|
140
|
-
const downloadStop = showSpinner('Testing download speed...');
|
|
141
|
-
const download = await downloadTest();
|
|
142
|
-
downloadStop();
|
|
143
|
-
clearLine();
|
|
144
|
-
printResult('download', `${download} Mbps`, '📥');
|
|
145
|
-
|
|
146
|
-
const uploadStop = showSpinner('Testing upload speed...');
|
|
147
|
-
const upload = (parseFloat(download) * 0.3).toFixed(2);
|
|
148
|
-
uploadStop();
|
|
149
|
-
clearLine();
|
|
150
|
-
printResult('upload', `${upload} Mbps`, '📤');
|
|
151
|
-
|
|
152
|
-
console.log();
|
|
153
|
-
console.log(chalk.gray(' ' + '─'.repeat(40)));
|
|
122
|
+
|
|
154
123
|
console.log();
|
|
124
|
+
console.log(` ${chalk.white('┌─ ' + type.toUpperCase() + ' ─────────────────────┐')}`);
|
|
125
|
+
console.log(chalk.white(' │ ') + colors[type](`${icon} ${value}`) + ' '.repeat(25 - value.toString().length) + chalk.white('│'));
|
|
126
|
+
console.log(chalk.white(' └' + '─'.repeat(36) + '┘'));
|
|
155
127
|
}
|
|
156
128
|
|
|
157
129
|
async function runSpeedTest() {
|
|
@@ -218,10 +190,13 @@ async function updatePackage() {
|
|
|
218
190
|
const { execSync } = await import('child_process');
|
|
219
191
|
|
|
220
192
|
try {
|
|
221
|
-
execSync('npm install -g netspeed-test-cli', { stdio: 'inherit' });
|
|
193
|
+
execSync('npm install -g netspeed-test-cli --force', { stdio: 'inherit' });
|
|
222
194
|
console.log(chalk.green('\n ✓ Update successful!'));
|
|
223
195
|
} catch (e) {
|
|
224
|
-
console.log(chalk.red('\n ✗ Update failed.
|
|
196
|
+
console.log(chalk.red('\n ✗ Update failed.'));
|
|
197
|
+
console.log(chalk.gray(' Try running manually:'));
|
|
198
|
+
console.log(chalk.gray(' npm uninstall -g netspeed-test-cli'));
|
|
199
|
+
console.log(chalk.gray(' npm install -g netspeed-test-cli'));
|
|
225
200
|
}
|
|
226
201
|
|
|
227
202
|
console.log(chalk.gray('\n Press ENTER to continue...'));
|
|
@@ -250,9 +225,8 @@ async function main() {
|
|
|
250
225
|
break;
|
|
251
226
|
case '2':
|
|
252
227
|
showVersion();
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
rl.question('', () => { rl.close(); main(); });
|
|
228
|
+
await waitForEnter();
|
|
229
|
+
await main();
|
|
256
230
|
break;
|
|
257
231
|
case '3':
|
|
258
232
|
await updatePackage();
|
|
@@ -262,9 +236,17 @@ async function main() {
|
|
|
262
236
|
process.exit(0);
|
|
263
237
|
default:
|
|
264
238
|
console.log(chalk.red(' Invalid choice. Press ENTER to try again.'));
|
|
265
|
-
|
|
266
|
-
|
|
239
|
+
await waitForEnter();
|
|
240
|
+
await main();
|
|
267
241
|
}
|
|
268
242
|
}
|
|
269
243
|
|
|
244
|
+
async function waitForEnter() {
|
|
245
|
+
const readline = await import('readline');
|
|
246
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
247
|
+
return new Promise((resolve) => {
|
|
248
|
+
rl.question('', () => { rl.close(); resolve(); });
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
270
252
|
main().catch(console.error);
|