@sachinthapa572/fast 0.1.4-rc

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/cli.js ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ const { spawnSync } = require("child_process");
3
+ const { existsSync } = require("fs");
4
+ const { join } = require("path");
5
+
6
+ const binName = process.platform === "win32" ? "fast.exe" : "fast";
7
+ const binPath = join(__dirname, "bin", binName);
8
+
9
+ if (!existsSync(binPath)) {
10
+ console.error(
11
+ "fast binary not found. Run `npm rebuild` or reinstall the package."
12
+ );
13
+ process.exit(1);
14
+ }
15
+
16
+ const result = spawnSync(binPath, process.argv.slice(2), {
17
+ stdio: "inherit",
18
+ });
19
+
20
+ process.exit(result.status ?? 1);
package/install.js ADDED
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env node
2
+ const { execSync } = require("child_process");
3
+ const { createWriteStream, existsSync, mkdirSync } = require("fs");
4
+ const { chmod, unlink } = require("fs").promises;
5
+ const { join } = require("path");
6
+ const { platform, arch } = require("os");
7
+ const https = require("https");
8
+ const http = require("http");
9
+
10
+ const pkg = require("./package.json");
11
+ const BIN_DIR = join(__dirname, "bin");
12
+ const BINARY_NAME = process.platform === "win32" ? "fast.exe" : "fast";
13
+ const BINARY_PATH = join(BIN_DIR, BINARY_NAME);
14
+
15
+ const OS_MAP = { win32: "Windows", darwin: "Darwin", linux: "Linux" };
16
+ const ARCH_MAP = { x64: "x86_64", arm64: "aarch64" };
17
+ const EXT_MAP = { win32: ".zip", darwin: ".tar.gz", linux: ".tar.gz" };
18
+
19
+ // This gets replaced at publish time with the actual Tigris URL base.
20
+ // Override via FAST_DOWNLOAD_URL env var for custom hosting.
21
+ const DOWNLOAD_BASE = process.env.FAST_DOWNLOAD_URL || "https://t3.storage.dev/sachinthapa-fast/fast";
22
+
23
+ function downloadUrl() {
24
+ const os = OS_MAP[platform()];
25
+ const cpu = ARCH_MAP[arch()];
26
+ const ext = EXT_MAP[platform()];
27
+
28
+ if (!os || !cpu) {
29
+ throw new Error(`Unsupported platform: ${platform()}/${arch()}`);
30
+ }
31
+
32
+ return `${DOWNLOAD_BASE}/v${pkg.version}/fast_${os}_${cpu}${ext}`;
33
+ }
34
+
35
+ function download(url, dest) {
36
+ return new Promise((resolve, reject) => {
37
+ const mod = url.startsWith("https") ? https : http;
38
+ mod.get(url, (res) => {
39
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
40
+ download(res.headers.location, dest).then(resolve).catch(reject);
41
+ return;
42
+ }
43
+ if (res.statusCode !== 200) {
44
+ reject(new Error(`Download failed: HTTP ${res.statusCode} for ${url}`));
45
+ return;
46
+ }
47
+ const file = createWriteStream(dest);
48
+ res.pipe(file);
49
+ file.on("finish", () => file.close(resolve));
50
+ file.on("error", reject);
51
+ }).on("error", reject);
52
+ });
53
+ }
54
+
55
+ function extractArchive(src, dest) {
56
+ if (process.platform === "win32") {
57
+ execSync(
58
+ `powershell -NoProfile -Command "Expand-Archive -Path '${src}' -DestinationPath '${dest}' -Force"`,
59
+ { stdio: "ignore" }
60
+ );
61
+ return;
62
+ }
63
+ execSync(`tar xzf "${src}" -C "${dest}" --strip-components 1`, {
64
+ stdio: "ignore",
65
+ });
66
+ }
67
+
68
+ async function install() {
69
+ if (!existsSync(BIN_DIR)) mkdirSync(BIN_DIR, { recursive: true });
70
+
71
+ const url = downloadUrl();
72
+ const ext = EXT_MAP[platform()];
73
+ const tmpArchive = join(BIN_DIR, `download${ext}`);
74
+
75
+ console.log(`Downloading fast v${pkg.version}...`);
76
+ await download(url, tmpArchive);
77
+
78
+ console.log("Extracting...");
79
+ extractArchive(tmpArchive, BIN_DIR);
80
+
81
+ await unlink(tmpArchive);
82
+
83
+ if (process.platform !== "win32") {
84
+ await chmod(BINARY_PATH, 0o755);
85
+ }
86
+
87
+ console.log("fast installed successfully.");
88
+ }
89
+
90
+ install().catch((err) => {
91
+ console.error("Failed to install fast binary:", err.message);
92
+ process.exit(1);
93
+ });
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@sachinthapa572/fast",
3
+ "version": "0.1.4-rc",
4
+ "description": "Test your internet speed from the command-line",
5
+ "bin": {
6
+ "fast": "cli.js"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node install.js",
10
+ "preuninstall": "node uninstall.js"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/sachinthapa572/fast-speed"
15
+ },
16
+ "homepage": "https://github.com/sachinthapa572/fast-speed",
17
+ "license": "MIT",
18
+ "keywords": [
19
+ "cli",
20
+ "speed-test",
21
+ "fast",
22
+ "netflix",
23
+ "internet-speed",
24
+ "bandwidth"
25
+ ]
26
+ }
package/uninstall.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ const { existsSync, rmSync } = require("fs");
3
+ const { join } = require("path");
4
+
5
+ const BIN_DIR = join(__dirname, "bin");
6
+
7
+ if (existsSync(BIN_DIR)) {
8
+ rmSync(BIN_DIR, { recursive: true, force: true });
9
+ console.log("Removed fast binary.");
10
+ }