portless-rs 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/.gitkeep ADDED
File without changes
package/bin/portless ADDED
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+ # This file is replaced by the real binary during postinstall.
3
+ # If you see this message, postinstall may have failed.
4
+ # Try: npm install -g portless-rs --ignore-scripts && portless-rs-install
5
+ echo "portless binary not installed yet. Run: npm install -g portless-rs" >&2
6
+ exit 1
package/install.js ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const https = require("https");
6
+ const fs = require("fs");
7
+ const path = require("path");
8
+ const zlib = require("zlib");
9
+ const { execSync } = require("child_process");
10
+
11
+ const REPO = "lusons/portless-rs";
12
+ const BIN_DIR = path.join(__dirname, "bin");
13
+ const BIN_PATH = path.join(BIN_DIR, "portless");
14
+
15
+ function getPlatformTarget() {
16
+ const platform = process.platform;
17
+ const arch = process.arch;
18
+
19
+ if (platform === "darwin" && arch === "arm64") return "aarch64-apple-darwin";
20
+ if (platform === "darwin" && arch === "x64") return "x86_64-apple-darwin";
21
+ if (platform === "linux" && arch === "x64") return "x86_64-unknown-linux-gnu";
22
+ if (platform === "linux" && arch === "arm64") return "aarch64-unknown-linux-gnu";
23
+
24
+ throw new Error(
25
+ `Unsupported platform: ${platform} ${arch}.\n` +
26
+ `Please install portless via cargo: cargo install portless\n` +
27
+ `Or download manually from: https://github.com/${REPO}/releases`
28
+ );
29
+ }
30
+
31
+ function getVersion() {
32
+ const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8"));
33
+ return pkg.version;
34
+ }
35
+
36
+ function download(url, dest) {
37
+ return new Promise((resolve, reject) => {
38
+ const follow = (url) => {
39
+ https.get(url, { headers: { "User-Agent": "portless-rs-npm-installer" } }, (res) => {
40
+ if (res.statusCode === 301 || res.statusCode === 302) {
41
+ return follow(res.headers.location);
42
+ }
43
+ if (res.statusCode !== 200) {
44
+ return reject(new Error(`Download failed: HTTP ${res.statusCode} for ${url}`));
45
+ }
46
+ const file = fs.createWriteStream(dest);
47
+ res.pipe(file);
48
+ file.on("finish", () => file.close(resolve));
49
+ file.on("error", reject);
50
+ }).on("error", reject);
51
+ };
52
+ follow(url);
53
+ });
54
+ }
55
+
56
+ function extractTarGz(archivePath, destDir) {
57
+ // Use system tar — available on macOS and all Linux distros
58
+ execSync(`tar -xzf "${archivePath}" -C "${destDir}"`, { stdio: "inherit" });
59
+ }
60
+
61
+ async function main() {
62
+ const target = getPlatformTarget();
63
+ const version = getVersion();
64
+ const archiveName = `portless-${target}.tar.gz`;
65
+ const url = `https://github.com/${REPO}/releases/download/v${version}/${archiveName}`;
66
+ const tmpArchive = path.join(BIN_DIR, archiveName);
67
+
68
+ console.log(`Installing portless v${version} for ${target}...`);
69
+
70
+ if (!fs.existsSync(BIN_DIR)) {
71
+ fs.mkdirSync(BIN_DIR, { recursive: true });
72
+ }
73
+
74
+ try {
75
+ await download(url, tmpArchive);
76
+ extractTarGz(tmpArchive, BIN_DIR);
77
+ fs.unlinkSync(tmpArchive);
78
+ fs.chmodSync(BIN_PATH, 0o755);
79
+ console.log(`portless installed successfully -> ${BIN_PATH}`);
80
+ } catch (err) {
81
+ // Clean up partial download
82
+ if (fs.existsSync(tmpArchive)) fs.unlinkSync(tmpArchive);
83
+ console.error(`\nFailed to install portless: ${err.message}`);
84
+ console.error(`You can install manually via cargo: cargo install portless`);
85
+ console.error(`Or download from: https://github.com/${REPO}/releases/tag/v${version}`);
86
+ process.exit(1);
87
+ }
88
+ }
89
+
90
+ main();
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "portless-rs",
3
+ "version": "0.1.0",
4
+ "description": "Replace port numbers with stable .localhost URLs for local development",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/lusons/portless-rs.git"
9
+ },
10
+ "homepage": "https://github.com/lusons/portless-rs",
11
+ "keywords": [
12
+ "portless",
13
+ "portless-rs",
14
+ "proxy",
15
+ "localhost",
16
+ "dev",
17
+ "tunnel",
18
+ "port",
19
+ "reverse-proxy"
20
+ ],
21
+ "bin": {
22
+ "portless": "bin/portless"
23
+ },
24
+ "scripts": {
25
+ "postinstall": "node install.js"
26
+ },
27
+ "engines": {
28
+ "node": ">=14"
29
+ },
30
+ "files": [
31
+ "bin/",
32
+ "install.js"
33
+ ]
34
+ }