@dongnanyang/deploy-cli 0.12.0 → 0.13.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/dist/bin.js CHANGED
@@ -3,8 +3,9 @@
3
3
  function resolveEntry(argv) {
4
4
  switch (argv[0]) {
5
5
  case void 0:
6
- case "tui": return "tui";
7
- case "--tui-next": return "tui-next";
6
+ case "tui":
7
+ case "--tui-next": return "tui";
8
+ case "--legacy-tui": return "legacy-tui";
8
9
  default: return "cli";
9
10
  }
10
11
  }
@@ -12,13 +13,13 @@ function resolveEntry(argv) {
12
13
  async function runEntry(argv = process.argv.slice(2)) {
13
14
  switch (resolveEntry(argv)) {
14
15
  case "tui":
15
- await import("./main.js");
16
- break;
17
- case "tui-next":
18
16
  await import("./tui/main.js");
19
17
  break;
18
+ case "legacy-tui":
19
+ await import("./main.js");
20
+ break;
20
21
  case "cli": {
21
- const cli = await import("./cli-BxZa7ok5.js");
22
+ const cli = await import("./cli-DuwAYtpm.js");
22
23
  process.exitCode = await cli.main(argv);
23
24
  break;
24
25
  }
@@ -1,6 +1,6 @@
1
1
  import { C as run, S as execFailureMessage, _ as acmeProbeCommand, c as loadProject, f as removeProject, g as ACME_BIN, r as addProject, s as listProjects, v as certbotProbeCommand, x as resolveNginxPaths, y as createNginx } from "./project-BL00JHAo.js";
2
2
  import { n as loadConfig, r as saveConfig, t as expandPath } from "./config-xUl8Oa3T.js";
3
- import { a as createDocker, i as findProjectContainers, n as runDeploy, o as logsArgs, r as checkProjectHealth, t as buildSpec } from "./deploy-DNT8Hzl1.js";
3
+ import { c as createDocker, l as logsArgs, o as checkProjectHealth, r as runDeploy, s as findProjectContainers, t as buildSpec } from "./deploy-DuQKdGV9.js";
4
4
  import { accessSync, constants, existsSync, readFileSync } from "node:fs";
5
5
  import { dirname, join } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
@@ -1,6 +1,8 @@
1
1
  import { C as run, S as execFailureMessage, a as generateCompose, h as PROJECT_LABEL, m as COMPOSE_SERVICE_LABEL, o as hasComposeMarker, t as COMPOSE_MARKER, y as createNginx } from "./project-BL00JHAo.js";
2
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
3
- import { resolve } from "node:path";
2
+ import { t as expandPath } from "./config-xUl8Oa3T.js";
3
+ import { existsSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
4
+ import { dirname, join, resolve } from "node:path";
5
+ import { spawn } from "node:child_process";
4
6
  //#region src/core/docker.ts
5
7
  /** docker 调用默认超时(F5:docker daemon 挂起不得永久挂死 CLI),与流水线 600s 长步档同口径;--follow 流式豁免 */
6
8
  const DOCKER_TIMEOUT_MS = 6e5;
@@ -372,5 +374,54 @@ async function runDeploy(project, opts) {
372
374
  }
373
375
  return { ok: true };
374
376
  }
377
+ /** 扫描项目的部署脚本(v0.1.0 discoverScripts 迁移:*.sh 按名排序,目录不存在=空表) */
378
+ function discoverScripts(project) {
379
+ const projectPath = expandPath(project.path);
380
+ const deployPath = resolve(projectPath, project.deployDir);
381
+ let files;
382
+ try {
383
+ files = readdirSync(deployPath);
384
+ } catch {
385
+ return [];
386
+ }
387
+ return files.filter((f) => f.endsWith(".sh")).map((f) => ({
388
+ project: project.name,
389
+ name: f,
390
+ path: join(deployPath, f)
391
+ })).sort((a, b) => a.name.localeCompare(b.name));
392
+ }
393
+ /** 执行部署脚本(v0.1.0 runDeployScript 迁移:cwd=deploy 目录,stdout/stderr 逐行回调,exit 回调收尾) */
394
+ function runDeployScript(script, args, onOutput, onExit) {
395
+ const cwd = dirname(script.path);
396
+ const child = spawn("bash", [script.name, ...args], {
397
+ cwd,
398
+ stdio: [
399
+ "pipe",
400
+ "pipe",
401
+ "pipe"
402
+ ],
403
+ env: { ...process.env }
404
+ });
405
+ const handleStream = (stream) => {
406
+ let buffer = "";
407
+ stream.on("data", (chunk) => {
408
+ buffer += chunk.toString();
409
+ const lines = buffer.split("\n");
410
+ buffer = lines.pop() || "";
411
+ for (const line of lines) if (line.trim()) onOutput(line);
412
+ });
413
+ stream.on("end", () => {
414
+ if (buffer.trim()) onOutput(buffer);
415
+ });
416
+ };
417
+ handleStream(child.stdout);
418
+ handleStream(child.stderr);
419
+ child.on("exit", onExit);
420
+ }
421
+ /** 记录脚本执行结果(v0.1.0 saveScriptResult 迁移:就地更新 lastRun/lastResult) */
422
+ function saveScriptResult(script, success) {
423
+ script.lastRun = (/* @__PURE__ */ new Date()).toISOString();
424
+ script.lastResult = success ? "success" : "fail";
425
+ }
375
426
  //#endregion
376
- export { createDocker as a, findProjectContainers as i, runDeploy as n, logsArgs as o, checkProjectHealth as r, buildSpec as t };
427
+ export { saveScriptResult as a, createDocker as c, runDeployScript as i, logsArgs as l, discoverScripts as n, checkProjectHealth as o, runDeploy as r, findProjectContainers as s, buildSpec as t };
package/dist/tui/main.js CHANGED
@@ -1,11 +1,14 @@
1
1
  import { a as generateCompose, b as isValidSlug, i as createManagedProject, l as managedComposeExists, s as listProjects, u as managedDir } from "../project-BL00JHAo.js";
2
2
  import { n as loadConfig, t as expandPath } from "../config-xUl8Oa3T.js";
3
3
  import { t as export_helper_default } from "../export-helper-CIEcxb5I.js";
4
- import { a as createDocker, n as runDeploy, r as checkProjectHealth } from "../deploy-DNT8Hzl1.js";
4
+ import { a as saveScriptResult, c as createDocker, i as runDeployScript, n as discoverScripts, o as checkProjectHealth, r as runDeploy } from "../deploy-DuQKdGV9.js";
5
+ import { readFileSync } from "fs";
5
6
  import { stringify } from "yaml";
6
7
  import { Box, Text, createApp, useApp, useInput } from "@vue-tui/runtime";
7
- import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createTextVNode, createVNode, defineComponent, onScopeDispose, openBlock, reactive, ref, renderList, shallowRef, toDisplayString, toValue, watch, withCtx } from "vue";
8
+ import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createTextVNode, createVNode, defineComponent, onMounted, onScopeDispose, onUnmounted, openBlock, reactive, ref, renderList, shallowRef, toDisplayString, toValue, watch, withCtx } from "vue";
8
9
  import { ScrollBox } from "@vue-tui/components";
10
+ import { createServer } from "net";
11
+ import { Client } from "ssh2";
9
12
  //#region src/tui/composables/useKeymap.ts
10
13
  /** 六面板(spec 6.4):键位 1-6 与数组序一一对应 */
11
14
  const PANEL_IDS = [
@@ -86,7 +89,7 @@ function useKeymap(handlers) {
86
89
  * 键位:y/enter 确认、n/escape 取消;不可见时不响应。
87
90
  * R17:visible 期间挂模态闸——全局键 1-6/q/? 一并停用(弹窗独占输入)。
88
91
  */
89
- const _sfc_main$8 = /*@__PURE__*/ defineComponent({
92
+ const _sfc_main$10 = /*@__PURE__*/ defineComponent({
90
93
  __name: "ConfirmModal",
91
94
  props: {
92
95
  visible: {
@@ -127,7 +130,7 @@ const _sfc_main$8 = /*@__PURE__*/ defineComponent({
127
130
  return __returned__;
128
131
  }
129
132
  });
130
- function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
133
+ function _sfc_render$10(_ctx, _cache, $props, $setup, $data, $options) {
131
134
  return $setup.props.visible ? (openBlock(), createBlock($setup["Box"], {
132
135
  key: 0,
133
136
  flexDirection: "column",
@@ -156,10 +159,10 @@ function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
156
159
  _: 1
157
160
  })) : createCommentVNode("v-if", true);
158
161
  }
159
- var ConfirmModal_default = /*#__PURE__*/ export_helper_default(_sfc_main$8, [["render", _sfc_render$8], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/ConfirmModal.vue"]]);
162
+ var ConfirmModal_default = /*#__PURE__*/ export_helper_default(_sfc_main$10, [["render", _sfc_render$10], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/ConfirmModal.vue"]]);
160
163
  //#endregion
161
164
  //#region src/tui/components/ContainersPanel.vue
162
- const _sfc_main$7 = /*@__PURE__*/ defineComponent({
165
+ const _sfc_main$9 = /*@__PURE__*/ defineComponent({
163
166
  __name: "ContainersPanel",
164
167
  props: {
165
168
  rows: {
@@ -250,7 +253,7 @@ const _sfc_main$7 = /*@__PURE__*/ defineComponent({
250
253
  return __returned__;
251
254
  }
252
255
  });
253
- function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
256
+ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
254
257
  return openBlock(), createBlock($setup["Box"], {
255
258
  flexDirection: "column",
256
259
  flexGrow: 1,
@@ -391,7 +394,7 @@ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
391
394
  _: 1
392
395
  });
393
396
  }
394
- var ContainersPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$7, [["render", _sfc_render$7], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/ContainersPanel.vue"]]);
397
+ var ContainersPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$9, [["render", _sfc_render$9], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/ContainersPanel.vue"]]);
395
398
  //#endregion
396
399
  //#region src/tui/components/DeployPanel.vue
397
400
  /**
@@ -399,7 +402,7 @@ var ContainersPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$7, [
399
402
  * 只吃 ViewModel(useDeployRun);发起部署入口在 Projects 面板 d(App 接线)。
400
403
  * 失败即停视觉呈现:fail 步标「失败」,其后步骤标「跳过」。
401
404
  */
402
- const _sfc_main$6 = /*@__PURE__*/ defineComponent({
405
+ const _sfc_main$8 = /*@__PURE__*/ defineComponent({
403
406
  __name: "DeployPanel",
404
407
  props: {
405
408
  projectName: {
@@ -469,7 +472,7 @@ const _sfc_main$6 = /*@__PURE__*/ defineComponent({
469
472
  return __returned__;
470
473
  }
471
474
  });
472
- function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
475
+ function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
473
476
  return openBlock(), createBlock($setup["Box"], {
474
477
  flexDirection: "column",
475
478
  flexGrow: 1,
@@ -590,7 +593,7 @@ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
590
593
  _: 1
591
594
  });
592
595
  }
593
- var DeployPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$6, [["render", _sfc_render$6], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/DeployPanel.vue"]]);
596
+ var DeployPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$8, [["render", _sfc_render$8], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/DeployPanel.vue"]]);
594
597
  //#endregion
595
598
  //#region src/tui/components/OutputPanel.vue
596
599
  /**
@@ -598,7 +601,7 @@ var DeployPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$6, [["re
598
601
  * 滚动/截断(T4#4 递延项):ScrollBox 有界视口(内容超高即截断)+ 旧 TUI g/G 键位语义(g 到顶、G 回底跟随)、↑/↓ 逐行;
599
602
  * 列表上限在 useLogs(LOGS_LIMIT 环形截断),此处只管视口。
600
603
  */
601
- const _sfc_main$5 = /*@__PURE__*/ defineComponent({
604
+ const _sfc_main$7 = /*@__PURE__*/ defineComponent({
602
605
  __name: "OutputPanel",
603
606
  props: { logs: {
604
607
  type: Array,
@@ -641,7 +644,7 @@ const _sfc_main$5 = /*@__PURE__*/ defineComponent({
641
644
  return __returned__;
642
645
  }
643
646
  });
644
- function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
647
+ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
645
648
  return openBlock(), createBlock($setup["Box"], {
646
649
  flexDirection: "column",
647
650
  flexGrow: 1,
@@ -691,14 +694,14 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
691
694
  _: 1
692
695
  });
693
696
  }
694
- var OutputPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$5, [["render", _sfc_render$5], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/OutputPanel.vue"]]);
697
+ var OutputPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$7, [["render", _sfc_render$7], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/OutputPanel.vue"]]);
695
698
  //#endregion
696
699
  //#region src/tui/components/ProjectsPanel.vue
697
700
  /**
698
701
  * Projects 面板(spec 6.4):项目列表 NAME/PATH/TYPE/ERROR + 动作事件出口。
699
702
  * 只吃 ViewModel(rows);动作经 emit 交 App 接线(部署等 T6 接线)。
700
703
  */
701
- const _sfc_main$4 = /*@__PURE__*/ defineComponent({
704
+ const _sfc_main$6 = /*@__PURE__*/ defineComponent({
702
705
  __name: "ProjectsPanel",
703
706
  props: {
704
707
  rows: {
@@ -750,7 +753,7 @@ const _sfc_main$4 = /*@__PURE__*/ defineComponent({
750
753
  return __returned__;
751
754
  }
752
755
  });
753
- function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
756
+ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
754
757
  return openBlock(), createBlock($setup["Box"], {
755
758
  flexDirection: "column",
756
759
  flexGrow: 1,
@@ -875,14 +878,239 @@ function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
875
878
  _: 1
876
879
  });
877
880
  }
878
- var ProjectsPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$4, [["render", _sfc_render$4], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/ProjectsPanel.vue"]]);
881
+ var ProjectsPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$6, [["render", _sfc_render$6], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/ProjectsPanel.vue"]]);
882
+ //#endregion
883
+ //#region src/tui/components/ScriptsPanel.vue
884
+ /**
885
+ * Scripts 面板(M2-T7 自 v0.1.0 DeployPanel 迁移):j/k/Enter/p 语义原样保留;
886
+ * p 开参数弹窗(旧 InputModal 语义:输入参数、Enter 执行、Esc 取消)。
887
+ * 只吃 ViewModel(rows/running);动作经 emit 交 App 接线(useScripts)。
888
+ */
889
+ const _sfc_main$5 = /*@__PURE__*/ defineComponent({
890
+ __name: "ScriptsPanel",
891
+ props: {
892
+ rows: {
893
+ type: Array,
894
+ required: true
895
+ },
896
+ running: {
897
+ type: [String, null],
898
+ required: true
899
+ }
900
+ },
901
+ emits: ["run", "refresh"],
902
+ setup(__props, { expose: __expose, emit: __emit }) {
903
+ __expose();
904
+ const props = __props;
905
+ const emit = __emit;
906
+ const sel = ref(0);
907
+ watch(() => props.rows.length, () => {
908
+ sel.value = Math.min(sel.value, Math.max(0, props.rows.length - 1));
909
+ });
910
+ /** 传参弹窗(旧 App paramModal 归入面板):打开期间挂模态闸,列表键不触达 */
911
+ const paramsFor = ref(null);
912
+ const paramsText = ref("");
913
+ const paramsOpen = computed(() => paramsFor.value !== null);
914
+ useModalGate(paramsOpen);
915
+ function closeParams() {
916
+ paramsFor.value = null;
917
+ paramsText.value = "";
918
+ }
919
+ useInput((event) => {
920
+ const name = keyName(event);
921
+ const char = event.type === "text" ? event.text : event.type === "key" ? event.key.character : void 0;
922
+ if (paramsOpen.value) {
923
+ if (name === "enter") {
924
+ const script = paramsFor.value;
925
+ const args = paramsText.value.trim().split(/\s+/).filter(Boolean);
926
+ closeParams();
927
+ emit("run", script, args);
928
+ } else if (name === "escape") closeParams();
929
+ else if (name === "backspace") paramsText.value = paramsText.value.slice(0, -1);
930
+ else if (char) paramsText.value += char;
931
+ return;
932
+ }
933
+ if (props.rows.length === 0) return;
934
+ if (name === "j" || name === "down") sel.value = Math.min(sel.value + 1, props.rows.length - 1);
935
+ else if (name === "k" || name === "up") sel.value = Math.max(sel.value - 1, 0);
936
+ else if (name === "enter") emit("run", props.rows[sel.value], []);
937
+ else if (name === "p") {
938
+ paramsFor.value = props.rows[sel.value];
939
+ paramsText.value = "";
940
+ } else if (name === "f") emit("refresh");
941
+ });
942
+ function key(script) {
943
+ return `${script.project}/${script.name}`;
944
+ }
945
+ const __returned__ = {
946
+ props,
947
+ emit,
948
+ sel,
949
+ paramsFor,
950
+ paramsText,
951
+ paramsOpen,
952
+ closeParams,
953
+ key,
954
+ get Box() {
955
+ return Box;
956
+ },
957
+ get Text() {
958
+ return Text;
959
+ }
960
+ };
961
+ Object.defineProperty(__returned__, "__isScriptSetup", {
962
+ enumerable: false,
963
+ value: true
964
+ });
965
+ return __returned__;
966
+ }
967
+ });
968
+ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
969
+ return openBlock(), createBlock($setup["Box"], {
970
+ flexDirection: "column",
971
+ flexGrow: 1,
972
+ borderStyle: "round",
973
+ borderColor: "cyan",
974
+ padding: 1
975
+ }, {
976
+ default: withCtx(() => [
977
+ createVNode($setup["Text"], {
978
+ bold: "",
979
+ color: "cyan"
980
+ }, {
981
+ default: withCtx(() => [..._cache[0] || (_cache[0] = [createTextVNode("Scripts 脚本(deploy/ 目录)", -1)])]),
982
+ _: 1
983
+ }),
984
+ $setup.props.rows.length === 0 ? (openBlock(), createBlock($setup["Text"], {
985
+ key: 0,
986
+ dimColor: ""
987
+ }, {
988
+ default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode("(暂无部署脚本)——在项目 deploy/ 目录放置 *.sh 后按 [f] 重扫", -1)])]),
989
+ _: 1
990
+ })) : createCommentVNode("v-if", true),
991
+ (openBlock(true), createElementBlock(Fragment, null, renderList($setup.props.rows, (s, i) => {
992
+ return openBlock(), createBlock($setup["Box"], {
993
+ key: $setup.key(s),
994
+ flexDirection: "row",
995
+ flexShrink: 0
996
+ }, {
997
+ default: withCtx(() => [
998
+ createVNode($setup["Box"], { width: 2 }, {
999
+ default: withCtx(() => [createVNode($setup["Text"], { color: i === $setup.sel ? "cyan" : void 0 }, {
1000
+ default: withCtx(() => [createTextVNode(toDisplayString(i === $setup.sel ? ">" : " "), 1)]),
1001
+ _: 2
1002
+ }, 1032, ["color"])]),
1003
+ _: 2
1004
+ }, 1024),
1005
+ createVNode($setup["Box"], { width: 2 }, {
1006
+ default: withCtx(() => [$setup.props.running === $setup.key(s) ? (openBlock(), createBlock($setup["Text"], {
1007
+ key: 0,
1008
+ color: "yellow"
1009
+ }, {
1010
+ default: withCtx(() => [..._cache[2] || (_cache[2] = [createTextVNode("▸", -1)])]),
1011
+ _: 1
1012
+ })) : s.lastResult === "success" ? (openBlock(), createBlock($setup["Text"], {
1013
+ key: 1,
1014
+ color: "green"
1015
+ }, {
1016
+ default: withCtx(() => [..._cache[3] || (_cache[3] = [createTextVNode("✓", -1)])]),
1017
+ _: 1
1018
+ })) : s.lastResult === "fail" ? (openBlock(), createBlock($setup["Text"], {
1019
+ key: 2,
1020
+ color: "red"
1021
+ }, {
1022
+ default: withCtx(() => [..._cache[4] || (_cache[4] = [createTextVNode("✗", -1)])]),
1023
+ _: 1
1024
+ })) : (openBlock(), createBlock($setup["Text"], { key: 3 }))]),
1025
+ _: 2
1026
+ }, 1024),
1027
+ createVNode($setup["Box"], { flexGrow: 1 }, {
1028
+ default: withCtx(() => [createVNode($setup["Text"], {
1029
+ wrap: "truncate",
1030
+ bold: i === $setup.sel,
1031
+ color: i === $setup.sel ? "cyan" : void 0
1032
+ }, {
1033
+ default: withCtx(() => [createTextVNode(toDisplayString($setup.key(s)), 1)]),
1034
+ _: 2
1035
+ }, 1032, ["bold", "color"])]),
1036
+ _: 2
1037
+ }, 1024),
1038
+ createVNode($setup["Box"], { flexShrink: 0 }, {
1039
+ default: withCtx(() => [$setup.props.running === $setup.key(s) ? (openBlock(), createBlock($setup["Text"], {
1040
+ key: 0,
1041
+ color: "yellow"
1042
+ }, {
1043
+ default: withCtx(() => [..._cache[5] || (_cache[5] = [createTextVNode("running...", -1)])]),
1044
+ _: 1
1045
+ })) : createCommentVNode("v-if", true)]),
1046
+ _: 2
1047
+ }, 1024)
1048
+ ]),
1049
+ _: 2
1050
+ }, 1024);
1051
+ }), 128)),
1052
+ createVNode($setup["Text"], { dimColor: "" }, {
1053
+ default: withCtx(() => [..._cache[6] || (_cache[6] = [createTextVNode("j/k 选择 · Enter 执行 · p 传参执行 · f 重扫", -1)])]),
1054
+ _: 1
1055
+ }),
1056
+ createCommentVNode(" 传参弹窗(旧 InputModal 文案) "),
1057
+ $setup.paramsFor ? (openBlock(), createBlock($setup["Box"], {
1058
+ key: 1,
1059
+ flexDirection: "column",
1060
+ borderStyle: "round",
1061
+ borderColor: "cyan",
1062
+ padding: 1
1063
+ }, {
1064
+ default: withCtx(() => [
1065
+ createVNode($setup["Text"], {
1066
+ bold: "",
1067
+ color: "cyan"
1068
+ }, {
1069
+ default: withCtx(() => [createTextVNode("执行: " + toDisplayString($setup.paramsFor.project) + "/" + toDisplayString($setup.paramsFor.name), 1)]),
1070
+ _: 1
1071
+ }),
1072
+ createVNode($setup["Box"], {
1073
+ flexDirection: "row",
1074
+ marginTop: 1,
1075
+ gap: 1
1076
+ }, {
1077
+ default: withCtx(() => [createVNode($setup["Text"], { dimColor: "" }, {
1078
+ default: withCtx(() => [..._cache[7] || (_cache[7] = [createTextVNode("参数:", -1)])]),
1079
+ _: 1
1080
+ }), createVNode($setup["Text"], {
1081
+ bold: "",
1082
+ color: "cyan"
1083
+ }, {
1084
+ default: withCtx(() => [createTextVNode(toDisplayString($setup.paramsText) + "_", 1)]),
1085
+ _: 1
1086
+ })]),
1087
+ _: 1
1088
+ }),
1089
+ createVNode($setup["Box"], {
1090
+ flexDirection: "row",
1091
+ marginTop: 1
1092
+ }, {
1093
+ default: withCtx(() => [createVNode($setup["Text"], { dimColor: "" }, {
1094
+ default: withCtx(() => [..._cache[8] || (_cache[8] = [createTextVNode("[Enter] 执行 [Esc] 取消", -1)])]),
1095
+ _: 1
1096
+ })]),
1097
+ _: 1
1098
+ })
1099
+ ]),
1100
+ _: 1
1101
+ })) : createCommentVNode("v-if", true)
1102
+ ]),
1103
+ _: 1
1104
+ });
1105
+ }
1106
+ var ScriptsPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$5, [["render", _sfc_render$5], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/ScriptsPanel.vue"]]);
879
1107
  //#endregion
880
1108
  //#region src/tui/components/StatusPanel.vue
881
1109
  /**
882
1110
  * Status 面板(spec 6.4):项目健康聚合 CONTAINERS/HTTP/NGINX(口径同 CLI status 表格)。
883
1111
  * 只吃 ViewModel(rows);单行错误降级展示(检查失败/配置不可用行 + 继续,M2-T2 #10 的 UI 面)。
884
1112
  */
885
- const _sfc_main$3 = /*@__PURE__*/ defineComponent({
1113
+ const _sfc_main$4 = /*@__PURE__*/ defineComponent({
886
1114
  __name: "StatusPanel",
887
1115
  props: {
888
1116
  rows: {
@@ -919,7 +1147,7 @@ const _sfc_main$3 = /*@__PURE__*/ defineComponent({
919
1147
  return __returned__;
920
1148
  }
921
1149
  });
922
- function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
1150
+ function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
923
1151
  return openBlock(), createBlock($setup["Box"], {
924
1152
  flexDirection: "column",
925
1153
  flexGrow: 1,
@@ -1043,10 +1271,10 @@ function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
1043
1271
  _: 1
1044
1272
  });
1045
1273
  }
1046
- var StatusPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$3, [["render", _sfc_render$3], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/StatusPanel.vue"]]);
1274
+ var StatusPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$4, [["render", _sfc_render$4], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/StatusPanel.vue"]]);
1047
1275
  //#endregion
1048
1276
  //#region src/tui/components/StatusBar.vue
1049
- const _sfc_main$2 = /*@__PURE__*/ defineComponent({
1277
+ const _sfc_main$3 = /*@__PURE__*/ defineComponent({
1050
1278
  __name: "StatusBar",
1051
1279
  props: {
1052
1280
  activePanel: {
@@ -1079,7 +1307,7 @@ const _sfc_main$2 = /*@__PURE__*/ defineComponent({
1079
1307
  return __returned__;
1080
1308
  }
1081
1309
  });
1082
- function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
1310
+ function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
1083
1311
  return openBlock(), createBlock($setup["Box"], {
1084
1312
  paddingX: 1,
1085
1313
  flexDirection: "row",
@@ -1099,7 +1327,172 @@ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
1099
1327
  _: 1
1100
1328
  });
1101
1329
  }
1102
- var StatusBar_default = /*#__PURE__*/ export_helper_default(_sfc_main$2, [["render", _sfc_render$2], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/StatusBar.vue"]]);
1330
+ var StatusBar_default = /*#__PURE__*/ export_helper_default(_sfc_main$3, [["render", _sfc_render$3], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/StatusBar.vue"]]);
1331
+ //#endregion
1332
+ //#region src/tui/components/TunnelsPanel.vue
1333
+ /**
1334
+ * Tunnels 面板(spec 6.4 面板 5):旧 v0.1.0 TunnelPanel 迁移——j/k/s/x/a 语义原样保留。
1335
+ * 只吃 ViewModel(rows);动作经 emit 交 App 接线(useTunnels)。
1336
+ */
1337
+ const _sfc_main$2 = /*@__PURE__*/ defineComponent({
1338
+ __name: "TunnelsPanel",
1339
+ props: { rows: {
1340
+ type: Array,
1341
+ required: true
1342
+ } },
1343
+ emits: [
1344
+ "start",
1345
+ "stop",
1346
+ "startAll"
1347
+ ],
1348
+ setup(__props, { expose: __expose, emit: __emit }) {
1349
+ __expose();
1350
+ const props = __props;
1351
+ const emit = __emit;
1352
+ const sel = ref(0);
1353
+ watch(() => props.rows.length, () => {
1354
+ sel.value = Math.min(sel.value, Math.max(0, props.rows.length - 1));
1355
+ });
1356
+ useInput((event) => {
1357
+ const name = keyName(event);
1358
+ if (name === "a") emit("startAll");
1359
+ if (props.rows.length === 0) return;
1360
+ if (name === "j" || name === "down") sel.value = Math.min(sel.value + 1, props.rows.length - 1);
1361
+ else if (name === "k" || name === "up") sel.value = Math.max(sel.value - 1, 0);
1362
+ else if (name === "s") emit("start", props.rows[sel.value].name);
1363
+ else if (name === "x") emit("stop", props.rows[sel.value].name);
1364
+ });
1365
+ const __returned__ = {
1366
+ props,
1367
+ emit,
1368
+ sel,
1369
+ STATUS_MARK: {
1370
+ running: "●",
1371
+ error: "✗",
1372
+ stopped: "○"
1373
+ },
1374
+ STATUS_COLOR: {
1375
+ running: "green",
1376
+ error: "red",
1377
+ stopped: "gray"
1378
+ },
1379
+ get Box() {
1380
+ return Box;
1381
+ },
1382
+ get Text() {
1383
+ return Text;
1384
+ }
1385
+ };
1386
+ Object.defineProperty(__returned__, "__isScriptSetup", {
1387
+ enumerable: false,
1388
+ value: true
1389
+ });
1390
+ return __returned__;
1391
+ }
1392
+ });
1393
+ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
1394
+ return openBlock(), createBlock($setup["Box"], {
1395
+ flexDirection: "column",
1396
+ flexGrow: 1,
1397
+ borderStyle: "round",
1398
+ borderColor: "cyan",
1399
+ padding: 1
1400
+ }, {
1401
+ default: withCtx(() => [
1402
+ createVNode($setup["Text"], {
1403
+ bold: "",
1404
+ color: "cyan"
1405
+ }, {
1406
+ default: withCtx(() => [..._cache[0] || (_cache[0] = [createTextVNode("5. Tunnels 隧道", -1)])]),
1407
+ _: 1
1408
+ }),
1409
+ $setup.props.rows.length === 0 ? (openBlock(), createBlock($setup["Text"], {
1410
+ key: 0,
1411
+ dimColor: ""
1412
+ }, {
1413
+ default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode("(暂无隧道配置)", -1)])]),
1414
+ _: 1
1415
+ })) : createCommentVNode("v-if", true),
1416
+ $setup.props.rows.length === 0 ? (openBlock(), createBlock($setup["Text"], {
1417
+ key: 1,
1418
+ dimColor: ""
1419
+ }, {
1420
+ default: withCtx(() => [..._cache[2] || (_cache[2] = [createTextVNode("编辑 ~/.deploy-cli/config.json 添加", -1)])]),
1421
+ _: 1
1422
+ })) : createCommentVNode("v-if", true),
1423
+ (openBlock(true), createElementBlock(Fragment, null, renderList($setup.props.rows, (t, i) => {
1424
+ return openBlock(), createBlock($setup["Box"], {
1425
+ key: t.name,
1426
+ flexDirection: "row",
1427
+ flexShrink: 0
1428
+ }, {
1429
+ default: withCtx(() => [
1430
+ createVNode($setup["Box"], { width: 2 }, {
1431
+ default: withCtx(() => [createVNode($setup["Text"], { color: i === $setup.sel ? "cyan" : void 0 }, {
1432
+ default: withCtx(() => [createTextVNode(toDisplayString(i === $setup.sel ? ">" : " "), 1)]),
1433
+ _: 2
1434
+ }, 1032, ["color"])]),
1435
+ _: 2
1436
+ }, 1024),
1437
+ createVNode($setup["Box"], { width: 2 }, {
1438
+ default: withCtx(() => [createVNode($setup["Text"], { color: $setup.STATUS_COLOR[t.status] }, {
1439
+ default: withCtx(() => [createTextVNode(toDisplayString($setup.STATUS_MARK[t.status]), 1)]),
1440
+ _: 2
1441
+ }, 1032, ["color"])]),
1442
+ _: 2
1443
+ }, 1024),
1444
+ createVNode($setup["Box"], { width: 24 }, {
1445
+ default: withCtx(() => [createVNode($setup["Text"], {
1446
+ wrap: "truncate",
1447
+ bold: i === $setup.sel,
1448
+ color: i === $setup.sel ? "cyan" : void 0
1449
+ }, {
1450
+ default: withCtx(() => [createTextVNode(toDisplayString(t.name), 1)]),
1451
+ _: 2
1452
+ }, 1032, ["bold", "color"])]),
1453
+ _: 2
1454
+ }, 1024),
1455
+ createVNode($setup["Box"], { flexShrink: 0 }, {
1456
+ default: withCtx(() => [createVNode($setup["Text"], { dimColor: "" }, {
1457
+ default: withCtx(() => [createTextVNode(":" + toDisplayString(t.localPort) + " -> " + toDisplayString(t.remoteHost) + ":" + toDisplayString(t.remotePort), 1)]),
1458
+ _: 2
1459
+ }, 1024)]),
1460
+ _: 2
1461
+ }, 1024),
1462
+ createVNode($setup["Box"], { flexShrink: 0 }, {
1463
+ default: withCtx(() => [t.autoStart ? (openBlock(), createBlock($setup["Text"], {
1464
+ key: 0,
1465
+ dimColor: ""
1466
+ }, {
1467
+ default: withCtx(() => [..._cache[3] || (_cache[3] = [createTextVNode(" (auto)", -1)])]),
1468
+ _: 1
1469
+ })) : createCommentVNode("v-if", true)]),
1470
+ _: 2
1471
+ }, 1024),
1472
+ createVNode($setup["Box"], { flexGrow: 1 }, {
1473
+ default: withCtx(() => [t.message ? (openBlock(), createBlock($setup["Text"], {
1474
+ key: 0,
1475
+ color: "red",
1476
+ wrap: "truncate"
1477
+ }, {
1478
+ default: withCtx(() => [createTextVNode(toDisplayString(t.message), 1)]),
1479
+ _: 2
1480
+ }, 1024)) : createCommentVNode("v-if", true)]),
1481
+ _: 2
1482
+ }, 1024)
1483
+ ]),
1484
+ _: 2
1485
+ }, 1024);
1486
+ }), 128)),
1487
+ createVNode($setup["Text"], { dimColor: "" }, {
1488
+ default: withCtx(() => [..._cache[4] || (_cache[4] = [createTextVNode("j/k 选择 · s 启动 · x 停止 · a 全部启动", -1)])]),
1489
+ _: 1
1490
+ })
1491
+ ]),
1492
+ _: 1
1493
+ });
1494
+ }
1495
+ var TunnelsPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$2, [["render", _sfc_render$2], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/TunnelsPanel.vue"]]);
1103
1496
  //#endregion
1104
1497
  //#region src/tui/composables/useWizard.ts
1105
1498
  /** 类型步选项(顺序=spec 6.1 compose|image|static) */
@@ -1269,8 +1662,10 @@ function toCreateInput(type, values) {
1269
1662
  name: (values["name"] ?? "").trim(),
1270
1663
  type
1271
1664
  };
1272
- const services = splitList(values["services"] ?? "");
1273
- if (services !== void 0) input.services = services;
1665
+ if (type === "compose") {
1666
+ const services = splitList(values["services"] ?? "");
1667
+ if (services !== void 0) input.services = services;
1668
+ }
1274
1669
  if (type === "image") {
1275
1670
  input.image = (values["image"] ?? "").trim();
1276
1671
  const ports = splitList(values["ports"] ?? "");
@@ -1431,6 +1826,11 @@ function useWizard(opts = {}) {
1431
1826
  /** 落盘(ConfirmModal y):走 createManagedProject;失败降级 message 留在预览步可重试 */
1432
1827
  function confirm() {
1433
1828
  confirmOpen.value = false;
1829
+ if (projectType.value === "compose" && !composeExists(values["name"] ?? "")) {
1830
+ composeReady.value = false;
1831
+ message.value = "compose 文件未就位(状态已变化):请重新放入后按 c 重检,再确认创建";
1832
+ return;
1833
+ }
1434
1834
  try {
1435
1835
  const result = create(toCreateInput(projectType.value, values));
1436
1836
  created.value = result;
@@ -2082,6 +2482,292 @@ function useProjects(opts = {}) {
2082
2482
  };
2083
2483
  }
2084
2484
  //#endregion
2485
+ //#region src/tui/composables/useScripts.ts
2486
+ /**
2487
+ * Scripts 面板数据面(M2-T7,自 v0.1.0 useDeploy + deploy-runner 迁移):
2488
+ * 扫描各项目 deploy/ 目录 → 行;执行走 core runDeployScript,输出/结果日志口径与 v0.1.0 逐字一致。
2489
+ */
2490
+ function useScripts(opts = {}) {
2491
+ const { info, success, warn, error: logError } = useLogs();
2492
+ const config = opts.load ? opts.load() : loadConfig();
2493
+ const rows = ref([]);
2494
+ const running = ref(null);
2495
+ function scan() {
2496
+ const all = [];
2497
+ for (const project of config.projects) all.push(...discoverScripts(project));
2498
+ rows.value = all;
2499
+ info(`扫描完成: ${config.projects.length} 个项目, ${all.length} 个脚本`);
2500
+ }
2501
+ function run(script, args = []) {
2502
+ const key = `${script.project}/${script.name}`;
2503
+ if (running.value !== null) {
2504
+ warn(`已有脚本在运行: ${running.value}`);
2505
+ return Promise.resolve();
2506
+ }
2507
+ running.value = key;
2508
+ info(`▸ ${key}${args.length ? " " + args.join(" ") : ""}`);
2509
+ return new Promise((settle) => {
2510
+ (opts.run ?? runDeployScript)(script, args, (line) => {
2511
+ info(` ${line}`);
2512
+ }, (code) => {
2513
+ const ok = code === 0;
2514
+ saveScriptResult(script, ok);
2515
+ if (ok) success(`✓ ${key} 完成`);
2516
+ else logError(`✗ ${key} 失败 (exit ${code})`);
2517
+ running.value = null;
2518
+ settle();
2519
+ });
2520
+ });
2521
+ }
2522
+ return {
2523
+ rows,
2524
+ running,
2525
+ scan,
2526
+ run
2527
+ };
2528
+ }
2529
+ //#endregion
2530
+ //#region src/core/tunnel.ts
2531
+ /** 读取私钥文件内容(v0.1.0 readPrivateKey 迁移:~ 展开后读盘) */
2532
+ function readPrivateKey(keyPath) {
2533
+ const expanded = expandPath(keyPath);
2534
+ return readFileSync(expanded, "utf-8");
2535
+ }
2536
+ /** 建立 SSH 连接(v0.1.0 createSSHConn 迁移:readyTimeout 10s + 12s 整体超时) */
2537
+ function createSSHConn(server) {
2538
+ return new Promise((resolve, reject) => {
2539
+ const conn = new Client();
2540
+ const config = {
2541
+ host: server.host,
2542
+ port: server.port,
2543
+ username: server.username,
2544
+ readyTimeout: 1e4
2545
+ };
2546
+ if (server.privateKey) config.privateKey = readPrivateKey(server.privateKey);
2547
+ else if (server.password) config.password = server.password;
2548
+ const timer = setTimeout(() => reject(/* @__PURE__ */ new Error("SSH 连接超时")), 12e3);
2549
+ conn.on("ready", () => {
2550
+ clearTimeout(timer);
2551
+ resolve(conn);
2552
+ });
2553
+ conn.on("error", (err) => {
2554
+ clearTimeout(timer);
2555
+ reject(err);
2556
+ });
2557
+ conn.connect(config);
2558
+ });
2559
+ }
2560
+ /** 隧道管理器实现 */
2561
+ var TunnelManagerImpl = class {
2562
+ config;
2563
+ activeTunnels = /* @__PURE__ */ new Map();
2564
+ /** 失败/断开原因(states() 行 overlay;成功启动/手动停止时清除) */
2565
+ lastError = /* @__PURE__ */ new Map();
2566
+ handlers = /* @__PURE__ */ new Set();
2567
+ constructor(config) {
2568
+ this.config = config;
2569
+ }
2570
+ emit(event) {
2571
+ for (const handler of [...this.handlers]) handler(event);
2572
+ }
2573
+ log(level, message) {
2574
+ this.emit({
2575
+ type: "log",
2576
+ level,
2577
+ message
2578
+ });
2579
+ }
2580
+ async start(name) {
2581
+ try {
2582
+ await this.startInner(name);
2583
+ this.lastError.delete(name);
2584
+ } catch (error) {
2585
+ this.lastError.set(name, error instanceof Error ? error.message : String(error));
2586
+ throw error;
2587
+ }
2588
+ }
2589
+ async startInner(name) {
2590
+ const tunnel = this.config.tunnels.find((t) => t.name === name);
2591
+ if (!tunnel) throw new Error(`未找到隧道: ${name}`);
2592
+ if (this.activeTunnels.has(name)) throw new Error(`隧道 "${name}" 已在运行`);
2593
+ const server = this.config.servers.find((s) => s.name === tunnel.server);
2594
+ if (!server) throw new Error(`找不到服务器: ${tunnel.server}`);
2595
+ this.log("info", `正在连接 ${server.host}...`);
2596
+ const conn = await createSSHConn(server);
2597
+ this.log("info", `SSH 已连接 ${server.username}@${server.host}`);
2598
+ const netServer = createServer((socket) => {
2599
+ conn.forwardOut(socket.remoteAddress || "127.0.0.1", socket.remotePort || 0, tunnel.remoteHost, tunnel.remotePort, (err, stream) => {
2600
+ if (err) {
2601
+ socket.destroy();
2602
+ return;
2603
+ }
2604
+ socket.pipe(stream);
2605
+ stream.pipe(socket);
2606
+ socket.on("error", () => stream.end());
2607
+ socket.on("close", () => stream.end());
2608
+ stream.on("error", () => socket.destroy());
2609
+ stream.on("close", () => socket.destroy());
2610
+ });
2611
+ });
2612
+ try {
2613
+ await new Promise((resolve, reject) => {
2614
+ netServer.on("error", reject);
2615
+ netServer.listen(tunnel.localPort, "127.0.0.1", resolve);
2616
+ });
2617
+ } catch (error) {
2618
+ conn.end();
2619
+ throw error;
2620
+ }
2621
+ conn.on("close", () => {
2622
+ if (!this.activeTunnels.has(name)) return;
2623
+ this.stop(name);
2624
+ this.lastError.set(name, "SSH 连接断开");
2625
+ this.log("warn", `隧道 "${name}" SSH 连接断开`);
2626
+ this.emit({
2627
+ type: "stopped",
2628
+ name,
2629
+ reason: "disconnect"
2630
+ });
2631
+ });
2632
+ conn.on("error", () => {
2633
+ if (!this.activeTunnels.has(name)) return;
2634
+ this.stop(name);
2635
+ this.lastError.set(name, "SSH 错误");
2636
+ this.log("error", `隧道 "${name}" SSH 错误`);
2637
+ this.emit({
2638
+ type: "stopped",
2639
+ name,
2640
+ reason: "error"
2641
+ });
2642
+ });
2643
+ this.activeTunnels.set(name, {
2644
+ server: netServer,
2645
+ conn
2646
+ });
2647
+ this.log("success", `隧道 "${name}" 已启动: localhost:${tunnel.localPort} -> ${tunnel.remoteHost}:${tunnel.remotePort}`);
2648
+ }
2649
+ stop(name) {
2650
+ const active = this.activeTunnels.get(name);
2651
+ if (!active) return;
2652
+ active.server.close();
2653
+ active.conn.end();
2654
+ this.activeTunnels.delete(name);
2655
+ this.lastError.delete(name);
2656
+ }
2657
+ stopAll() {
2658
+ for (const name of [...this.activeTunnels.keys()]) this.stop(name);
2659
+ }
2660
+ status(name) {
2661
+ return this.activeTunnels.has(name) ? "running" : "stopped";
2662
+ }
2663
+ states() {
2664
+ return this.config.tunnels.map((t) => {
2665
+ const running = this.activeTunnels.has(t.name);
2666
+ const error = running ? void 0 : this.lastError.get(t.name);
2667
+ return {
2668
+ name: t.name,
2669
+ server: t.server,
2670
+ localPort: t.localPort,
2671
+ remoteHost: t.remoteHost,
2672
+ remotePort: t.remotePort,
2673
+ autoStart: t.autoStart,
2674
+ status: running ? "running" : error !== void 0 ? "error" : "stopped",
2675
+ message: error
2676
+ };
2677
+ });
2678
+ }
2679
+ async autoStart() {
2680
+ for (const tunnel of this.config.tunnels) {
2681
+ if (!tunnel.autoStart) continue;
2682
+ if (this.activeTunnels.has(tunnel.name)) continue;
2683
+ try {
2684
+ await this.start(tunnel.name);
2685
+ } catch (error) {
2686
+ const message = error instanceof Error ? error.message : String(error);
2687
+ this.log("error", `隧道 "${tunnel.name}" 启动失败: ${message}`);
2688
+ }
2689
+ }
2690
+ }
2691
+ onEvent(handler) {
2692
+ this.handlers.add(handler);
2693
+ return () => {
2694
+ this.handlers.delete(handler);
2695
+ };
2696
+ }
2697
+ };
2698
+ /** 创建隧道管理器(ssh2 隧道沿用 v0.1.0 逻辑重构——spec 6.2 core/tunnel.ts) */
2699
+ function createTunnelManager(config) {
2700
+ return new TunnelManagerImpl(config);
2701
+ }
2702
+ //#endregion
2703
+ //#region src/tui/composables/useTunnels.ts
2704
+ /**
2705
+ * Tunnels 面板数据面(M2-T7,自 v0.1.0 useTunnels 迁移):core/tunnel 事件 → 响应式行 + 全局日志。
2706
+ * - manager log 事件 → useLogs(旧 onLog 归宿);stopped 事件(SSH 断开/错误)→ 行转 error 带原因。
2707
+ * - 行为基线 = v0.1.0 useTunnels;两处意图行为修正:重复启动只 warn 不误标 error 行、
2708
+ * SSH 断开行不再残留 running(旧实现状态漂移)。
2709
+ */
2710
+ function useTunnels(opts = {}) {
2711
+ const { info, success, warn, error: logError } = useLogs();
2712
+ const config = opts.load ? opts.load() : loadConfig();
2713
+ const manager = opts.manager ?? createTunnelManager(config);
2714
+ const tunnels = ref(manager.states());
2715
+ manager.onEvent((event) => {
2716
+ if (event.type === "log") if (event.level === "info") info(event.message);
2717
+ else if (event.level === "success") success(event.message);
2718
+ else if (event.level === "warn") warn(event.message);
2719
+ else logError(event.message);
2720
+ else tunnels.value = manager.states();
2721
+ });
2722
+ async function start(name) {
2723
+ const tunnel = config.tunnels.find((t) => t.name === name);
2724
+ if (!tunnel) return;
2725
+ if (!config.servers.find((s) => s.name === tunnel.server)) {
2726
+ logError(`找不到服务器: ${tunnel.server}`);
2727
+ return;
2728
+ }
2729
+ if (manager.status(name) === "running") {
2730
+ warn(`隧道 "${name}" 已在运行`);
2731
+ return;
2732
+ }
2733
+ const row = tunnels.value.find((t) => t.name === name);
2734
+ if (row) row.status = "running";
2735
+ try {
2736
+ await manager.start(name);
2737
+ } catch (error) {
2738
+ const message = error instanceof Error ? error.message : String(error);
2739
+ logError(`隧道 "${name}" 启动失败: ${message}`);
2740
+ }
2741
+ tunnels.value = manager.states();
2742
+ }
2743
+ function stop(name) {
2744
+ manager.stop(name);
2745
+ tunnels.value = manager.states();
2746
+ info(`隧道 "${name}" 已停止`);
2747
+ }
2748
+ async function startAll() {
2749
+ for (const t of tunnels.value) {
2750
+ if (t.status === "running") continue;
2751
+ await start(t.name);
2752
+ }
2753
+ }
2754
+ async function autoStart() {
2755
+ await manager.autoStart();
2756
+ tunnels.value = manager.states();
2757
+ }
2758
+ function cleanup() {
2759
+ manager.stopAll();
2760
+ }
2761
+ return {
2762
+ tunnels,
2763
+ start,
2764
+ stop,
2765
+ startAll,
2766
+ autoStart,
2767
+ cleanup
2768
+ };
2769
+ }
2770
+ //#endregion
2085
2771
  //#region src/tui/App.vue
2086
2772
  const _sfc_main = /*@__PURE__*/ defineComponent({
2087
2773
  __name: "App",
@@ -2093,6 +2779,8 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
2093
2779
  const { rows: containerRows, error: containerError, following, refresh: refreshContainers, restart, stop, remove, followLogs } = useContainers();
2094
2780
  const { rows: healthRows, error: healthError, refresh: refreshHealth } = useHealth();
2095
2781
  const { projectName: deployProject, steps: deploySteps, lines: deployLines, running: deployRunning, done: deployDone, failedStep: deployFailedStep, start: startDeploy } = useDeployRun();
2782
+ const { tunnels: tunnelRows, start: startTunnel, stop: stopTunnel, startAll: startAllTunnels, autoStart: autoStartTunnels, cleanup: cleanupTunnels } = useTunnels();
2783
+ const { rows: scriptRows, running: scriptRunning, scan: scanScripts, run: runScript } = useScripts();
2096
2784
  const activePanel = ref("projects");
2097
2785
  const helpVisible = ref(false);
2098
2786
  const wizardOpen = ref(false);
@@ -2101,11 +2789,21 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
2101
2789
  activePanel.value = panel;
2102
2790
  helpVisible.value = false;
2103
2791
  },
2104
- onQuit: () => exit(),
2792
+ onQuit: () => {
2793
+ cleanupTunnels();
2794
+ exit();
2795
+ },
2105
2796
  onHelp: () => {
2106
2797
  helpVisible.value = !helpVisible.value;
2107
2798
  }
2108
2799
  });
2800
+ onMounted(() => {
2801
+ scanScripts();
2802
+ autoStartTunnels();
2803
+ });
2804
+ onUnmounted(() => {
2805
+ cleanupTunnels();
2806
+ });
2109
2807
  watch(activePanel, (panel) => {
2110
2808
  if (panel === "projects") refreshProjects();
2111
2809
  else if (panel === "containers") refreshContainers();
@@ -2174,6 +2872,16 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
2174
2872
  deployDone,
2175
2873
  deployFailedStep,
2176
2874
  startDeploy,
2875
+ tunnelRows,
2876
+ startTunnel,
2877
+ stopTunnel,
2878
+ startAllTunnels,
2879
+ autoStartTunnels,
2880
+ cleanupTunnels,
2881
+ scriptRows,
2882
+ scriptRunning,
2883
+ scanScripts,
2884
+ runScript,
2177
2885
  activePanel,
2178
2886
  helpVisible,
2179
2887
  wizardOpen,
@@ -2183,7 +2891,6 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
2183
2891
  onDeploy,
2184
2892
  onWizardCreated,
2185
2893
  onWizardClose,
2186
- panelTitle: computed(() => `${PANEL_IDS.indexOf(activePanel.value) + 1}. ${PANEL_TITLES[activePanel.value]}`),
2187
2894
  get Box() {
2188
2895
  return Box;
2189
2896
  },
@@ -2194,8 +2901,10 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
2194
2901
  DeployPanel: DeployPanel_default,
2195
2902
  OutputPanel: OutputPanel_default,
2196
2903
  ProjectsPanel: ProjectsPanel_default,
2904
+ ScriptsPanel: ScriptsPanel_default,
2197
2905
  StatusPanel: StatusPanel_default,
2198
2906
  StatusBar: StatusBar_default,
2907
+ TunnelsPanel: TunnelsPanel_default,
2199
2908
  WizardPanel: WizardPanel_default,
2200
2909
  get PANEL_IDS() {
2201
2910
  return PANEL_IDS;
@@ -2236,7 +2945,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
2236
2945
  })]),
2237
2946
  _: 1
2238
2947
  }),
2239
- createCommentVNode(" 主面板区:1/2/3/4/6 实装,5 Tunnels(T7)骨架占位;创建向导(n)打开时独占主区 "),
2948
+ createCommentVNode(" 主面板区:六面板全部实装(T7 隧道/脚本迁移收尾);创建向导(n)打开时独占主区 "),
2240
2949
  createVNode($setup["Box"], {
2241
2950
  flexDirection: "column",
2242
2951
  flexGrow: 1,
@@ -2272,22 +2981,38 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
2272
2981
  "error",
2273
2982
  "following",
2274
2983
  "onRefresh"
2275
- ])) : $setup.activePanel === "deploy" ? (openBlock(), createBlock($setup["DeployPanel"], {
2276
- key: 3,
2277
- "project-name": $setup.deployProject,
2278
- steps: $setup.deploySteps,
2279
- lines: $setup.deployLines,
2280
- running: $setup.deployRunning,
2281
- done: $setup.deployDone,
2282
- "failed-step": $setup.deployFailedStep
2283
- }, null, 8, [
2284
- "project-name",
2285
- "steps",
2286
- "lines",
2287
- "running",
2288
- "done",
2289
- "failed-step"
2290
- ])) : $setup.activePanel === "status" ? (openBlock(), createBlock($setup["StatusPanel"], {
2984
+ ])) : $setup.activePanel === "deploy" ? (openBlock(), createElementBlock(Fragment, { key: 3 }, [createCommentVNode(" 面板 3 Deploy:流水线(T6)+ 脚本区(T7,v0.1.0 DeployPanel 语义)复合;\n gap=0 + 脚本区单行空态:80x24 终端部署进行时 21 行恰好放下(部署框 15 + 脚本框 6) "), createVNode($setup["Box"], {
2985
+ flexDirection: "column",
2986
+ flexGrow: 1,
2987
+ gap: 0
2988
+ }, {
2989
+ default: withCtx(() => [createVNode($setup["DeployPanel"], {
2990
+ "project-name": $setup.deployProject,
2991
+ steps: $setup.deploySteps,
2992
+ lines: $setup.deployLines,
2993
+ running: $setup.deployRunning,
2994
+ done: $setup.deployDone,
2995
+ "failed-step": $setup.deployFailedStep
2996
+ }, null, 8, [
2997
+ "project-name",
2998
+ "steps",
2999
+ "lines",
3000
+ "running",
3001
+ "done",
3002
+ "failed-step"
3003
+ ]), createVNode($setup["ScriptsPanel"], {
3004
+ rows: $setup.scriptRows,
3005
+ running: $setup.scriptRunning,
3006
+ onRun: $setup.runScript,
3007
+ onRefresh: $setup.scanScripts
3008
+ }, null, 8, [
3009
+ "rows",
3010
+ "running",
3011
+ "onRun",
3012
+ "onRefresh"
3013
+ ])]),
3014
+ _: 1
3015
+ })], 2112)) : $setup.activePanel === "status" ? (openBlock(), createBlock($setup["StatusPanel"], {
2291
3016
  key: 4,
2292
3017
  rows: $setup.healthRows,
2293
3018
  error: $setup.healthError,
@@ -2296,28 +3021,21 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
2296
3021
  "rows",
2297
3022
  "error",
2298
3023
  "onRefresh"
2299
- ])) : $setup.activePanel === "output" ? (openBlock(), createBlock($setup["OutputPanel"], {
3024
+ ])) : $setup.activePanel === "tunnels" ? (openBlock(), createBlock($setup["TunnelsPanel"], {
2300
3025
  key: 5,
2301
- logs: $setup.logs
2302
- }, null, 8, ["logs"])) : (openBlock(), createBlock($setup["Box"], {
3026
+ rows: $setup.tunnelRows,
3027
+ onStart: $setup.startTunnel,
3028
+ onStop: $setup.stopTunnel,
3029
+ onStartAll: $setup.startAllTunnels
3030
+ }, null, 8, [
3031
+ "rows",
3032
+ "onStart",
3033
+ "onStop",
3034
+ "onStartAll"
3035
+ ])) : $setup.activePanel === "output" ? (openBlock(), createBlock($setup["OutputPanel"], {
2303
3036
  key: 6,
2304
- flexDirection: "column",
2305
- flexGrow: 1,
2306
- borderStyle: "round",
2307
- padding: 1
2308
- }, {
2309
- default: withCtx(() => [createVNode($setup["Text"], {
2310
- bold: "",
2311
- color: "cyan"
2312
- }, {
2313
- default: withCtx(() => [createTextVNode(toDisplayString($setup.panelTitle), 1)]),
2314
- _: 1
2315
- }), createVNode($setup["Text"], { dimColor: "" }, {
2316
- default: withCtx(() => [..._cache[6] || (_cache[6] = [createTextVNode("(骨架占位:面板内容随 M2 后续任务实现)", -1)])]),
2317
- _: 1
2318
- })]),
2319
- _: 1
2320
- }))]),
3037
+ logs: $setup.logs
3038
+ }, null, 8, ["logs"])) : createCommentVNode("v-if", true)]),
2321
3039
  _: 1
2322
3040
  }),
2323
3041
  createCommentVNode(" 帮助浮层(? 开关) "),
@@ -2334,7 +3052,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
2334
3052
  bold: "",
2335
3053
  color: "yellow"
2336
3054
  }, {
2337
- default: withCtx(() => [..._cache[7] || (_cache[7] = [createTextVNode("快捷键帮助", -1)])]),
3055
+ default: withCtx(() => [..._cache[6] || (_cache[6] = [createTextVNode("快捷键帮助", -1)])]),
2338
3056
  _: 1
2339
3057
  }),
2340
3058
  (openBlock(true), createElementBlock(Fragment, null, renderList($setup.PANEL_IDS, (id, i) => {
@@ -2344,7 +3062,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
2344
3062
  }, 1024);
2345
3063
  }), 128)),
2346
3064
  createVNode($setup["Text"], null, {
2347
- default: withCtx(() => [..._cache[8] || (_cache[8] = [createTextVNode("? 打开/关闭帮助 │ q 退出", -1)])]),
3065
+ default: withCtx(() => [..._cache[7] || (_cache[7] = [createTextVNode("? 打开/关闭帮助 │ q 退出", -1)])]),
2348
3066
  _: 1
2349
3067
  })
2350
3068
  ]),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dongnanyang/deploy-cli",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Local CLI TUI for SSH tunnels & deploy scripts",
5
5
  "type": "module",
6
6
  "main": "./dist/api.js",