@launchtunnel/cli 0.1.0

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/lt ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const { execFileSync } = require("child_process");
6
+ const path = require("path");
7
+ const fs = require("fs");
8
+
9
+ const ext = process.platform === "win32" ? ".exe" : "";
10
+ const binPath = path.join(__dirname, `lt${ext}`);
11
+
12
+ if (!fs.existsSync(binPath)) {
13
+ console.error(
14
+ "LaunchTunnel binary not found. Try reinstalling: npm install -g @launchtunnel/cli"
15
+ );
16
+ process.exit(1);
17
+ }
18
+
19
+ try {
20
+ execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
21
+ } catch (err) {
22
+ process.exit(err.status ?? 1);
23
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@launchtunnel/cli",
3
+ "version": "0.1.0",
4
+ "description": "LaunchTunnel CLI — expose localhost to the internet",
5
+ "bin": {
6
+ "lt": "bin/lt"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node scripts/postinstall.js"
10
+ },
11
+ "os": [
12
+ "darwin",
13
+ "linux",
14
+ "win32"
15
+ ],
16
+ "cpu": [
17
+ "x64",
18
+ "arm64"
19
+ ],
20
+ "engines": {
21
+ "node": ">=16"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/launchtunnel/launchtunnel"
26
+ },
27
+ "homepage": "https://launchtunnel.dev",
28
+ "license": "MIT",
29
+ "keywords": [
30
+ "tunnel",
31
+ "localhost",
32
+ "ngrok",
33
+ "webhook",
34
+ "dev-tools"
35
+ ]
36
+ }
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+
3
+ const https = require("https");
4
+ const http = require("http");
5
+ const fs = require("fs");
6
+ const path = require("path");
7
+
8
+ const BASE_URL = "https://api.launchtunnel.dev/download";
9
+
10
+ const PLATFORM_MAP = {
11
+ darwin: "darwin",
12
+ linux: "linux",
13
+ win32: "windows",
14
+ };
15
+
16
+ const ARCH_MAP = {
17
+ x64: "amd64",
18
+ arm64: "arm64",
19
+ };
20
+
21
+ function getBinaryName() {
22
+ const platform = PLATFORM_MAP[process.platform];
23
+ const arch = ARCH_MAP[process.arch];
24
+
25
+ if (!platform) {
26
+ throw new Error(
27
+ `Unsupported platform: ${process.platform}. LaunchTunnel supports macOS, Linux, and Windows.`
28
+ );
29
+ }
30
+ if (!arch) {
31
+ throw new Error(
32
+ `Unsupported architecture: ${process.arch}. LaunchTunnel supports x64 and arm64.`
33
+ );
34
+ }
35
+
36
+ const ext = process.platform === "win32" ? ".exe" : "";
37
+ return `lt-${platform}-${arch}${ext}`;
38
+ }
39
+
40
+ function getOutputPath() {
41
+ const binDir = path.join(__dirname, "..", "bin");
42
+ const ext = process.platform === "win32" ? ".exe" : "";
43
+ return path.join(binDir, `lt${ext}`);
44
+ }
45
+
46
+ function fetch(url) {
47
+ return new Promise((resolve, reject) => {
48
+ const mod = url.startsWith("https") ? https : http;
49
+ mod
50
+ .get(url, (res) => {
51
+ // Follow redirects
52
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
53
+ return fetch(res.headers.location).then(resolve, reject);
54
+ }
55
+
56
+ if (res.statusCode !== 200) {
57
+ reject(new Error(`Download failed with status ${res.statusCode}`));
58
+ return;
59
+ }
60
+
61
+ resolve(res);
62
+ })
63
+ .on("error", reject);
64
+ });
65
+ }
66
+
67
+ async function download(url, dest) {
68
+ const res = await fetch(url);
69
+
70
+ const dir = path.dirname(dest);
71
+ if (!fs.existsSync(dir)) {
72
+ fs.mkdirSync(dir, { recursive: true });
73
+ }
74
+
75
+ return new Promise((resolve, reject) => {
76
+ const file = fs.createWriteStream(dest);
77
+ res.pipe(file);
78
+ file.on("finish", () => {
79
+ file.close(resolve);
80
+ });
81
+ file.on("error", (err) => {
82
+ fs.unlink(dest, () => {});
83
+ reject(err);
84
+ });
85
+ });
86
+ }
87
+
88
+ async function main() {
89
+ const binaryName = getBinaryName();
90
+ const url = `${BASE_URL}/${binaryName}`;
91
+ const outputPath = getOutputPath();
92
+
93
+ console.log(`Downloading LaunchTunnel CLI (${binaryName})...`);
94
+
95
+ await download(url, outputPath);
96
+
97
+ // Make executable on Unix
98
+ if (process.platform !== "win32") {
99
+ fs.chmodSync(outputPath, 0o755);
100
+ }
101
+
102
+ console.log("LaunchTunnel CLI installed successfully.");
103
+ }
104
+
105
+ main().catch((err) => {
106
+ console.error(`Failed to install LaunchTunnel CLI: ${err.message}`);
107
+ console.error(
108
+ "You can download it manually from https://launchtunnel.dev/docs/quickstart"
109
+ );
110
+ process.exit(1);
111
+ });