mysshx 0.0.0-stage → 1.0.1

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/mysshx.js ADDED
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env node
2
+ import { exec } from 'node:child_process';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+ const args = process.argv.slice(2);
10
+
11
+ function hasFlag(flag) {
12
+ return args.includes(flag);
13
+ }
14
+
15
+ function getValue(flag, fallback) {
16
+ const idx = args.indexOf(flag);
17
+ if (idx !== -1 && args[idx + 1]) return args[idx + 1];
18
+ const withEq = args.find((a) => a.startsWith(`${flag}=`));
19
+ if (withEq) return withEq.split('=')[1];
20
+ return fallback;
21
+ }
22
+
23
+ if (hasFlag('--help') || hasFlag('-h')) {
24
+ console.log(`mysshx - SSH / SFTP 管理器
25
+
26
+ 用法:
27
+ npx mysshx [选项]
28
+
29
+ 选项:
30
+ --port, -p <端口> 监听端口 (默认 3011)
31
+ --host <地址> 监听地址 (默认 0.0.0.0)
32
+ --no-open 启动后不自动打开浏览器
33
+ --data-dir <目录> 数据目录 (默认 ~/.mysshx)
34
+ -h, --help 显示帮助
35
+
36
+ 环境变量:
37
+ PORT, HOST, MYSSHX_DATA_DIR
38
+ `);
39
+ process.exit(0);
40
+ }
41
+
42
+ // 抑制 node:sqlite 的实验性警告
43
+ const originalEmitWarning = process.emitWarning.bind(process);
44
+ process.emitWarning = (warning, ...rest) => {
45
+ const type = typeof rest[0] === 'string' ? rest[0] : rest[0]?.type || warning?.name;
46
+ if (type === 'ExperimentalWarning') return;
47
+ return originalEmitWarning(warning, ...rest);
48
+ };
49
+
50
+ const distIndex = path.join(__dirname, '..', 'client', 'dist', 'index.html');
51
+ if (!fs.existsSync(distIndex)) {
52
+ console.error('未找到前端构建产物 client/dist,请先在项目根目录运行: npm run build');
53
+ process.exit(1);
54
+ }
55
+
56
+ const dataDir = getValue('--data-dir', process.env.MYSSHX_DATA_DIR || process.env.MYSSH_DATA_DIR);
57
+ if (dataDir) process.env.MYSSHX_DATA_DIR = dataDir;
58
+
59
+ const port = Number(getValue('--port', getValue('-p', process.env.PORT || 3011)));
60
+ const host = getValue('--host', process.env.HOST || '0.0.0.0');
61
+ const noOpen = hasFlag('--no-open');
62
+
63
+ const { startServer } = await import('../server/index.js');
64
+
65
+ try {
66
+ const { port: actualPort } = await startServer({ port, host });
67
+ const url = `http://localhost:${actualPort}`;
68
+ console.log(
69
+ `数据目录: ${process.env.MYSSHX_DATA_DIR || process.env.MYSSH_DATA_DIR || path.join(os.homedir(), '.mysshx')}`
70
+ );
71
+ console.log(`请在浏览器打开: ${url}`);
72
+ if (!noOpen) openBrowser(url);
73
+ } catch (err) {
74
+ console.error('启动失败:', err.message);
75
+ process.exit(1);
76
+ }
77
+
78
+ function openBrowser(url) {
79
+ const cmd =
80
+ process.platform === 'win32'
81
+ ? `start "" "${url}"`
82
+ : process.platform === 'darwin'
83
+ ? `open "${url}"`
84
+ : `xdg-open "${url}"`;
85
+ exec(cmd, () => {});
86
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Copyright (c) 2014 The xterm.js authors. All rights reserved.
3
+ * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
4
+ * https://github.com/chjj/term.js
5
+ * @license MIT
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ *
25
+ * Originally forked from (with the author's permission):
26
+ * Fabrice Bellard's javascript vt100 for jslinux:
27
+ * http://bellard.org/jslinux/
28
+ * Copyright (c) 2011 Fabrice Bellard
29
+ * The original design remains. The terminal itself
30
+ * has been extended to include xterm CSI codes, among
31
+ * other features.
32
+ */.xterm{cursor:text;position:relative;user-select:none;-ms-user-select:none;-webkit-user-select:none}.xterm.focus,.xterm:focus{outline:none}.xterm .xterm-helpers{position:absolute;top:0;z-index:5}.xterm .xterm-helper-textarea{padding:0;border:0;margin:0;position:absolute;opacity:0;left:-9999em;top:0;width:0;height:0;z-index:-5;white-space:nowrap;overflow:hidden;resize:none}.xterm .composition-view{background:#000;color:#fff;display:none;position:absolute;white-space:nowrap;z-index:1}.xterm .composition-view.active{display:block}.xterm .xterm-viewport{background-color:#000;overflow-y:scroll;cursor:default;position:absolute;right:0;left:0;top:0;bottom:0}.xterm .xterm-screen{position:relative}.xterm .xterm-screen canvas{position:absolute;left:0;top:0}.xterm .xterm-scroll-area{visibility:hidden}.xterm-char-measure-element{display:inline-block;visibility:hidden;position:absolute;top:0;left:-9999em;line-height:normal}.xterm.enable-mouse-events{cursor:default}.xterm.xterm-cursor-pointer,.xterm .xterm-cursor-pointer{cursor:pointer}.xterm.column-select.focus{cursor:crosshair}.xterm .xterm-accessibility:not(.debug),.xterm .xterm-message{position:absolute;left:0;top:0;bottom:0;right:0;z-index:10;color:transparent;pointer-events:none}.xterm .xterm-accessibility-tree:not(.debug) *::selection{color:transparent}.xterm .xterm-accessibility-tree{-webkit-user-select:text;user-select:text;white-space:pre}.xterm .live-region{position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden}.xterm-dim{opacity:1!important}.xterm-underline-1{text-decoration:underline}.xterm-underline-2{text-decoration:double underline}.xterm-underline-3{text-decoration:wavy underline}.xterm-underline-4{text-decoration:dotted underline}.xterm-underline-5{text-decoration:dashed underline}.xterm-overline{text-decoration:overline}.xterm-overline.xterm-underline-1{text-decoration:overline underline}.xterm-overline.xterm-underline-2{text-decoration:overline double underline}.xterm-overline.xterm-underline-3{text-decoration:overline wavy underline}.xterm-overline.xterm-underline-4{text-decoration:overline dotted underline}.xterm-overline.xterm-underline-5{text-decoration:overline dashed underline}.xterm-strikethrough{text-decoration:line-through}.xterm-screen .xterm-decoration-container .xterm-decoration{z-index:6;position:absolute}.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer{z-index:7}.xterm-decoration-overview-ruler{z-index:8;position:absolute;top:0;right:0;pointer-events:none}.xterm-decoration-top{z-index:2;position:relative}