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