about-system 0.0.12 → 0.0.15
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 +0 -0
- package/package.json +1 -1
- package/src/about-system.js +256 -221
- package/src/test-speed-cloudflare.js +0 -51
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import ora from 'ora';
|
|
2
|
-
import { spawn, execSync } from 'child_process';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Tests the download speed in MB/s using Cloudflare's speed test.
|
|
7
|
-
* Optionally displays a spinner message during the test.
|
|
8
|
-
* Their official package is @cloudflare/speedtest and it shows errors and too much output.
|
|
9
|
-
* This script uses a process to hide the errors and give speed in MB/s via CLI or import.
|
|
10
|
-
* @param {boolean} [showMessage=true] - Whether to show explanation message while testing.
|
|
11
|
-
* @returns {Promise<string>} The measured download speed in MB/s as a string (e.g., "12.3").
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* import { testDownloadSpeed } from './test-speed-cloudflare.js';
|
|
15
|
-
* const downloadSpeed = await testDownloadSpeed(false);
|
|
16
|
-
* console.log(downloadSpeed); // e.g., "12.3"
|
|
17
|
-
*/
|
|
18
|
-
export async function testDownloadSpeed(showMessage = true) {
|
|
19
|
-
var spinner;
|
|
20
|
-
if (showMessage)
|
|
21
|
-
spinner = ora('Testing download speed in MB/s using Cloudflare, runs for 1 minute').start();
|
|
22
|
-
|
|
23
|
-
// globally install @cloudflare/speedtest
|
|
24
|
-
await execSync('npm i -g @cloudflare/speedtest');
|
|
25
|
-
|
|
26
|
-
const result = await new Promise((resolve) => {
|
|
27
|
-
const child = spawn('node', [
|
|
28
|
-
'-e',
|
|
29
|
-
"import SpeedTest from '@cloudflare/speedtest'; new SpeedTest({iterations: 1}).onFinish = r => console.log((r.getDownloadBandwidth() / 8388608).toFixed(1))"
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
let output = '';
|
|
33
|
-
child.stdout.on('data', (data) => {
|
|
34
|
-
output += data.toString();
|
|
35
|
-
});
|
|
36
|
-
// Extract last number from output
|
|
37
|
-
child.on('close', () => {
|
|
38
|
-
resolve(output.trim().split('\n').pop().match(/(\d+(\.\d+)?)/)?.[0]);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
if (showMessage) spinner.succeed(result + ' MB/s');
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// try{
|
|
48
|
-
// run if file is executed directly
|
|
49
|
-
// if (process?.env.npm_lifecycle_event?.length > 0 || import.meta.url === `file://${process.argv[1]}` || import.meta.url === process.argv[1] || import.meta.url === `file://${process.cwd()}/${process.argv[1]}`)
|
|
50
|
-
testDownloadSpeed();
|
|
51
|
-
// } catch { }
|