@lijuneleven/easy-terminal 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/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # easy-terminal
2
+
3
+ Install:
4
+
5
+ ```sh
6
+ npm install -g @lijuneleven/easy-terminal
7
+ easy-terminal
8
+ ```
9
+
10
+ The CLI starts the local `easy_terminal` service. Pass server flags directly:
11
+
12
+ ```sh
13
+ easy-terminal --port 9090
14
+ ```
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { spawn } = require("child_process");
6
+
7
+ const exeName = process.platform === "win32" ? "easy_terminal.exe" : "easy_terminal";
8
+ const binaryPath = process.env.EASY_TERMINAL_BINARY
9
+ ? path.resolve(process.env.EASY_TERMINAL_BINARY)
10
+ : path.resolve(__dirname, "..", "vendor", exeName);
11
+
12
+ if (!fs.existsSync(binaryPath)) {
13
+ console.error(
14
+ "easy-terminal binary is missing. Reinstall the package or set EASY_TERMINAL_BINARY to a local binary."
15
+ );
16
+ process.exit(1);
17
+ }
18
+
19
+ const child = spawn(binaryPath, process.argv.slice(2), {
20
+ stdio: "inherit",
21
+ env: process.env
22
+ });
23
+
24
+ child.on("exit", (code, signal) => {
25
+ if (signal) {
26
+ process.kill(process.pid, signal);
27
+ return;
28
+ }
29
+ process.exit(code ?? 0);
30
+ });
31
+
32
+ child.on("error", (err) => {
33
+ console.error(err.message);
34
+ process.exit(1);
35
+ });
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@lijuneleven/easy-terminal",
3
+ "version": "0.1.0",
4
+ "description": "Local web terminal with Feishu remote session control.",
5
+ "license": "MIT",
6
+ "bin": {
7
+ "easy-terminal": "bin/easy-terminal.js"
8
+ },
9
+ "files": [
10
+ "bin/",
11
+ "scripts/",
12
+ "vendor/",
13
+ "README.md"
14
+ ],
15
+ "scripts": {
16
+ "postinstall": "node scripts/install.js"
17
+ },
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/elevenlj/easy_terminal.git"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/elevenlj/easy_terminal/issues"
27
+ },
28
+ "homepage": "https://github.com/elevenlj/easy_terminal#readme"
29
+ }
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const os = require("os");
5
+ const path = require("path");
6
+ const https = require("https");
7
+ const { pipeline } = require("stream/promises");
8
+ const { createWriteStream } = require("fs");
9
+
10
+ const packageJson = require("../package.json");
11
+
12
+ const owner = process.env.EASY_TERMINAL_GITHUB_OWNER || "elevenlj";
13
+ const repo = process.env.EASY_TERMINAL_GITHUB_REPO || "easy_terminal";
14
+ const version = packageJson.version;
15
+ const platform = process.platform;
16
+ const arch = process.arch;
17
+
18
+ const platformMap = {
19
+ darwin: "darwin",
20
+ linux: "linux",
21
+ win32: "windows"
22
+ };
23
+
24
+ const archMap = {
25
+ x64: "amd64",
26
+ arm64: "arm64"
27
+ };
28
+
29
+ function fail(message) {
30
+ console.error(`easy-terminal install failed: ${message}`);
31
+ process.exit(1);
32
+ }
33
+
34
+ if (process.env.EASY_TERMINAL_SKIP_DOWNLOAD === "1") {
35
+ process.exit(0);
36
+ }
37
+
38
+ const targetPlatform = platformMap[platform];
39
+ const targetArch = archMap[arch];
40
+
41
+ if (!targetPlatform || !targetArch) {
42
+ fail(`unsupported platform: ${platform}/${arch}`);
43
+ }
44
+
45
+ const ext = targetPlatform === "windows" ? ".exe" : "";
46
+ const assetName = `easy_terminal-${targetPlatform}-${targetArch}${ext}`;
47
+ const url = `https://github.com/${owner}/${repo}/releases/download/v${version}/${assetName}`;
48
+ const vendorDir = path.resolve(__dirname, "..", "vendor");
49
+ const outPath = path.join(vendorDir, targetPlatform === "windows" ? "easy_terminal.exe" : "easy_terminal");
50
+
51
+ async function download(downloadUrl, redirects = 0) {
52
+ if (redirects > 5) {
53
+ fail("too many redirects while downloading binary");
54
+ }
55
+
56
+ await fs.promises.mkdir(vendorDir, { recursive: true });
57
+
58
+ await new Promise((resolve, reject) => {
59
+ https
60
+ .get(downloadUrl, (res) => {
61
+ if ([301, 302, 303, 307, 308].includes(res.statusCode || 0)) {
62
+ res.resume();
63
+ download(res.headers.location, redirects + 1).then(resolve, reject);
64
+ return;
65
+ }
66
+
67
+ if (res.statusCode !== 200) {
68
+ res.resume();
69
+ reject(new Error(`download returned HTTP ${res.statusCode}`));
70
+ return;
71
+ }
72
+
73
+ pipeline(res, createWriteStream(outPath)).then(resolve, reject);
74
+ })
75
+ .on("error", reject);
76
+ });
77
+
78
+ if (targetPlatform !== "windows") {
79
+ await fs.promises.chmod(outPath, 0o755);
80
+ }
81
+ }
82
+
83
+ download(url).catch((err) => {
84
+ try {
85
+ fs.rmSync(outPath, { force: true });
86
+ } catch (_) {
87
+ }
88
+ fail(`${err.message}. URL: ${url}`);
89
+ });