@dongnanyang/deploy-cli 0.9.0 → 0.10.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/api.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as generateCompose, c as loadProject, d as removeProject, f as saveProject, i as createManagedProject, l as managedDir, m as PROJECT_LABEL, n as ProjectConfigError, o as hasComposeMarker, p as COMPOSE_SERVICE_LABEL, r as addProject, s as listProjects, t as COMPOSE_MARKER, u as managedRoot } from "./project-BjXAyWOT.js";
1
+ import { a as generateCompose, c as loadProject, d as removeProject, f as saveProject, i as createManagedProject, l as managedDir, m as PROJECT_LABEL, n as ProjectConfigError, o as hasComposeMarker, p as COMPOSE_SERVICE_LABEL, r as addProject, s as listProjects, t as COMPOSE_MARKER, u as managedRoot } from "./project-BzJoAv1l.js";
2
2
  export { COMPOSE_MARKER, COMPOSE_SERVICE_LABEL, PROJECT_LABEL, ProjectConfigError, addProject, createManagedProject, generateCompose, hasComposeMarker, listProjects, loadProject, managedDir, managedRoot, removeProject, saveProject };
package/dist/bin.js CHANGED
@@ -1,9 +1,31 @@
1
- //#region src/bin.ts
2
- const argv = process.argv.slice(2);
3
- if (argv.length === 0 || argv[0] === "tui") await import("./main.js");
4
- else {
5
- const cli = await import("./cli-DFrwLhsI.js");
6
- process.exitCode = await cli.main(argv);
1
+ //#region src/entry.ts
2
+ /** 入口分发判定(纯函数):argv[0] 决定目标,其余参数原样留给对应入口 */
3
+ function resolveEntry(argv) {
4
+ switch (argv[0]) {
5
+ case void 0:
6
+ case "tui": return "tui";
7
+ case "--tui-next": return "tui-next";
8
+ default: return "cli";
9
+ }
10
+ }
11
+ /** 执行入口分发:TUI 变体各自挂载;cli 子命令返回退出码写入 process.exitCode */
12
+ async function runEntry(argv = process.argv.slice(2)) {
13
+ switch (resolveEntry(argv)) {
14
+ case "tui":
15
+ await import("./main.js");
16
+ break;
17
+ case "tui-next":
18
+ await import("./tui/main.js");
19
+ break;
20
+ case "cli": {
21
+ const cli = await import("./cli-CR04-WjM.js");
22
+ process.exitCode = await cli.main(argv);
23
+ break;
24
+ }
25
+ }
7
26
  }
8
27
  //#endregion
28
+ //#region src/bin.ts
29
+ await runEntry();
30
+ //#endregion
9
31
  export {};
@@ -1,4 +1,4 @@
1
- import { _ as certbotProbeCommand, a as generateCompose, b as execFailureMessage, d as removeProject, g as acmeProbeCommand, h as ACME_BIN, m as PROJECT_LABEL, o as hasComposeMarker, p as COMPOSE_SERVICE_LABEL, r as addProject, s as listProjects, t as COMPOSE_MARKER, v as createNginx, x as run, y as resolveNginxPaths } from "./project-BjXAyWOT.js";
1
+ import { _ as certbotProbeCommand, a as generateCompose, b as execFailureMessage, c as loadProject, d as removeProject, g as acmeProbeCommand, h as ACME_BIN, m as PROJECT_LABEL, o as hasComposeMarker, p as COMPOSE_SERVICE_LABEL, r as addProject, s as listProjects, t as COMPOSE_MARKER, v as createNginx, x as run, y as resolveNginxPaths } from "./project-BzJoAv1l.js";
2
2
  import { n as loadConfig, r as saveConfig, t as expandPath } from "./config-xUl8Oa3T.js";
3
3
  import { accessSync, constants, existsSync, readFileSync, writeFileSync } from "node:fs";
4
4
  import { dirname, join, resolve } from "node:path";
@@ -360,7 +360,7 @@ async function runDeploy(project, opts) {
360
360
  if (!probe.ok) throw new Error(`健康探测失败: ${project.healthUrl}: ${probe.error ?? `HTTP ${probe.status}`}`);
361
361
  }
362
362
  if (project.type !== "static") {
363
- if (!(await findProjectContainers(docker, project.name)).some((c) => c.state === "running")) throw new Error(`无运行中容器: ${project.name}(docker ps 未见 running 状态容器)`);
363
+ if (!(await findProjectContainers(docker, project.name, { services: project.services })).some((c) => c.state === "running")) throw new Error(`无运行中容器: ${project.name}(docker ps 未见 running 状态容器)`);
364
364
  }
365
365
  });
366
366
  if (stopped) return stopped;
@@ -802,6 +802,15 @@ async function project(args, options = {}) {
802
802
  }
803
803
  //#endregion
804
804
  //#region src/cli/commands/ps.ts
805
+ /** R15①:services 真相源=项目 deploy.yaml(spec 6.1);读不到/坏配置降级不过滤(ps 是诊断工具,不因坏配置拒列容器) */
806
+ function declaredServices(project, options) {
807
+ if (options.servicesOf) return options.servicesOf(project);
808
+ try {
809
+ return loadProject(project.path).services;
810
+ } catch {
811
+ return;
812
+ }
813
+ }
805
814
  const USAGE$2 = `用法: deploy-cli ps [--all] [--project <项目名>]
806
815
 
807
816
  选项:
@@ -850,7 +859,10 @@ async function ps(args, options = {}) {
850
859
  error(`未找到项目: ${projectName}(请检查 ~/.deploy-cli/config.json 的 projects 注册表)`);
851
860
  return 1;
852
861
  }
853
- const rows = await findProjectContainers(docker, project.name, { all });
862
+ const rows = await findProjectContainers(docker, project.name, {
863
+ all,
864
+ services: declaredServices(project, options)
865
+ });
854
866
  log("NAME IMAGE STATE PORTS");
855
867
  for (const container of rows) log(`${container.name}\t${container.image}\t${container.state}\t${container.ports}`);
856
868
  return 0;
@@ -0,0 +1,8 @@
1
+ //#region \0/plugin-vue/export-helper
2
+ var export_helper_default = (sfc, props) => {
3
+ const target = sfc.__vccOpts || sfc;
4
+ for (const [key, val] of props) target[key] = val;
5
+ return target;
6
+ };
7
+ //#endregion
8
+ export { export_helper_default as t };
package/dist/main.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { n as loadConfig, r as saveConfig, t as expandPath } from "./config-xUl8Oa3T.js";
2
+ import { t as export_helper_default } from "./export-helper-CIEcxb5I.js";
2
3
  import { readFileSync, readdirSync } from "fs";
3
4
  import { dirname, join, resolve } from "path";
4
5
  import { Box, Text, createApp, useApp, useInput } from "@vue-tui/runtime";
@@ -7,13 +8,6 @@ import { ScrollBox } from "@vue-tui/components";
7
8
  import { createServer } from "net";
8
9
  import { Client } from "ssh2";
9
10
  import { spawn } from "child_process";
10
- //#region \0/plugin-vue/export-helper
11
- var export_helper_default = (sfc, props) => {
12
- const target = sfc.__vccOpts || sfc;
13
- for (const [key, val] of props) target[key] = val;
14
- return target;
15
- };
16
- //#endregion
17
11
  //#region src/components/TunnelPanel.vue
18
12
  const _sfc_main$6 = /*@__PURE__*/ defineComponent({
19
13
  __name: "TunnelPanel",
@@ -562,7 +562,7 @@ function validate(raw) {
562
562
  if (type === "image" && (typeof raw.image !== "string" || raw.image.trim() === "")) throw new ProjectConfigError("image 型缺少必填字段: image", "image");
563
563
  if (type === "static" && (typeof raw.root !== "string" || raw.root.trim() === "")) throw new ProjectConfigError("static 型缺少必填字段: root", "root");
564
564
  if (raw.services !== void 0 && raw.services !== null) {
565
- if (!Array.isArray(raw.services) || raw.services.some((s) => typeof s !== "string" || s.trim() === "")) throw new ProjectConfigError("services 应为字符串数组(参与部署/状态面板的服务名,如 [web])", "services");
565
+ if (!Array.isArray(raw.services) || raw.services.some((s) => typeof s !== "string" || s.trim() === "" || s !== s.trim())) throw new ProjectConfigError("services 应为字符串数组(参与部署/状态面板的服务名,如 [web];服务名不能为空、不得带首尾空白)", "services");
566
566
  }
567
567
  if (raw.nginx !== void 0 && raw.nginx !== null) {
568
568
  const nginx = raw.nginx;
@@ -0,0 +1,359 @@
1
+ import { t as export_helper_default } from "../export-helper-CIEcxb5I.js";
2
+ import { Box, Text, createApp, useApp, useInput } from "@vue-tui/runtime";
3
+ import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createTextVNode, createVNode, defineComponent, openBlock, ref, renderList, toDisplayString, withCtx } from "vue";
4
+ //#region src/tui/components/OutputPanel.vue
5
+ /** 全局日志面板(spec 6.4 Output):只吃 ViewModel(logs 列表),不碰 core */
6
+ const _sfc_main$2 = /*@__PURE__*/ defineComponent({
7
+ __name: "OutputPanel",
8
+ props: { logs: {
9
+ type: Array,
10
+ required: true
11
+ } },
12
+ setup(__props, { expose: __expose }) {
13
+ __expose();
14
+ const __returned__ = {
15
+ props: __props,
16
+ LEVEL_COLOR: {
17
+ info: void 0,
18
+ success: "green",
19
+ warn: "yellow",
20
+ error: "red"
21
+ },
22
+ get Box() {
23
+ return Box;
24
+ },
25
+ get Text() {
26
+ return Text;
27
+ }
28
+ };
29
+ Object.defineProperty(__returned__, "__isScriptSetup", {
30
+ enumerable: false,
31
+ value: true
32
+ });
33
+ return __returned__;
34
+ }
35
+ });
36
+ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
37
+ return openBlock(), createBlock($setup["Box"], {
38
+ flexDirection: "column",
39
+ flexGrow: 1,
40
+ borderStyle: "round",
41
+ borderColor: "cyan",
42
+ padding: 1
43
+ }, {
44
+ default: withCtx(() => [
45
+ createVNode($setup["Text"], {
46
+ bold: "",
47
+ color: "cyan"
48
+ }, {
49
+ default: withCtx(() => [..._cache[0] || (_cache[0] = [createTextVNode("6. Output 输出(全局日志)", -1)])]),
50
+ _: 1
51
+ }),
52
+ $setup.props.logs.length === 0 ? (openBlock(), createBlock($setup["Text"], {
53
+ key: 0,
54
+ dimColor: ""
55
+ }, {
56
+ default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode("(暂无日志)", -1)])]),
57
+ _: 1
58
+ })) : createCommentVNode("v-if", true),
59
+ (openBlock(true), createElementBlock(Fragment, null, renderList($setup.props.logs, (entry, i) => {
60
+ return openBlock(), createBlock($setup["Text"], {
61
+ key: i,
62
+ color: $setup.LEVEL_COLOR[entry.level]
63
+ }, {
64
+ default: withCtx(() => [createTextVNode(toDisplayString(entry.time) + " [" + toDisplayString(entry.level) + "] " + toDisplayString(entry.message), 1)]),
65
+ _: 2
66
+ }, 1032, ["color"]);
67
+ }), 128))
68
+ ]),
69
+ _: 1
70
+ });
71
+ }
72
+ var OutputPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$2, [["render", _sfc_render$2], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/OutputPanel.vue"]]);
73
+ //#endregion
74
+ //#region src/tui/composables/useKeymap.ts
75
+ /** 六面板(spec 6.4):键位 1-6 与数组序一一对应 */
76
+ const PANEL_IDS = [
77
+ "projects",
78
+ "containers",
79
+ "deploy",
80
+ "status",
81
+ "tunnels",
82
+ "output"
83
+ ];
84
+ /** 面板标题(骨架/状态栏共用;中文文案) */
85
+ const PANEL_TITLES = {
86
+ projects: "Projects 项目",
87
+ containers: "Containers 容器",
88
+ deploy: "Deploy 部署",
89
+ status: "Status 状态",
90
+ tunnels: "Tunnels 隧道",
91
+ output: "Output 输出"
92
+ };
93
+ /**
94
+ * 提取单字符键位:text 事件取 text、key 事件取 character/name(同一输入事实只出一个公共事件,不会双发)。
95
+ * 多字符文本(粘贴/连打)不分发,防误触退出。
96
+ */
97
+ function keyChar(event) {
98
+ let raw;
99
+ if (event.type === "text") raw = event.text;
100
+ else if (event.type === "key") raw = event.key.character ?? event.key.name;
101
+ return raw !== void 0 && raw.length === 1 ? raw : void 0;
102
+ }
103
+ /** 键位分发(纯函数,单测锚点):1-6 切面板、q 退出、? 帮助;其余不分发 */
104
+ function dispatchKey(event) {
105
+ const ch = keyChar(event);
106
+ if (ch === void 0) return null;
107
+ if (ch >= "1" && ch <= "6") return {
108
+ kind: "panel",
109
+ panel: PANEL_IDS[Number(ch) - 1]
110
+ };
111
+ if (ch === "q") return { kind: "quit" };
112
+ if (ch === "?") return { kind: "help" };
113
+ return null;
114
+ }
115
+ /** 键位路由接线:useInput 订阅 → dispatchKey → 回调;组件不碰输入流本体 */
116
+ function useKeymap(handlers) {
117
+ useInput((event) => {
118
+ const action = dispatchKey(event);
119
+ if (action === null) return;
120
+ if (action.kind === "panel") handlers.onPanel(action.panel);
121
+ else if (action.kind === "quit") handlers.onQuit();
122
+ else handlers.onHelp();
123
+ });
124
+ }
125
+ //#endregion
126
+ //#region src/tui/components/StatusBar.vue
127
+ const _sfc_main$1 = /*@__PURE__*/ defineComponent({
128
+ __name: "StatusBar",
129
+ props: {
130
+ activePanel: {
131
+ type: null,
132
+ required: true
133
+ },
134
+ helpVisible: {
135
+ type: Boolean,
136
+ required: false
137
+ }
138
+ },
139
+ setup(__props, { expose: __expose }) {
140
+ __expose();
141
+ const __returned__ = {
142
+ props: __props,
143
+ get Box() {
144
+ return Box;
145
+ },
146
+ get Text() {
147
+ return Text;
148
+ },
149
+ get PANEL_TITLES() {
150
+ return PANEL_TITLES;
151
+ }
152
+ };
153
+ Object.defineProperty(__returned__, "__isScriptSetup", {
154
+ enumerable: false,
155
+ value: true
156
+ });
157
+ return __returned__;
158
+ }
159
+ });
160
+ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
161
+ return openBlock(), createBlock($setup["Box"], {
162
+ paddingX: 1,
163
+ flexDirection: "row",
164
+ justifyContent: "space-between",
165
+ flexShrink: 0
166
+ }, {
167
+ default: withCtx(() => [createVNode($setup["Text"], {
168
+ bold: "",
169
+ color: "cyan"
170
+ }, {
171
+ default: withCtx(() => [createTextVNode(toDisplayString($setup.PANEL_TITLES[$setup.props.activePanel]), 1)]),
172
+ _: 1
173
+ }), createVNode($setup["Text"], { dimColor: "" }, {
174
+ default: withCtx(() => [createTextVNode(toDisplayString($setup.props.helpVisible ? "[?] 关闭帮助" : "[?] 帮助") + " │ 1-6 切换面板 · q 退出", 1)]),
175
+ _: 1
176
+ })]),
177
+ _: 1
178
+ });
179
+ }
180
+ var StatusBar_default = /*#__PURE__*/ export_helper_default(_sfc_main$1, [["render", _sfc_render$1], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/components/StatusBar.vue"]]);
181
+ //#endregion
182
+ //#region src/tui/composables/useLogs.ts
183
+ /** 全局日志条目(响应式列表,单例) */
184
+ const entries = ref([]);
185
+ function now() {
186
+ return (/* @__PURE__ */ new Date()).toLocaleTimeString("zh-CN", { hour12: false });
187
+ }
188
+ /**
189
+ * 全局日志 store(单例):core 事件 → 响应式列表,供 OutputPanel 渲染。
190
+ * 同一 App 内多处 useLogs() 拿到同一份列表。
191
+ */
192
+ function useLogs() {
193
+ const log = (level, message) => {
194
+ entries.value.push({
195
+ time: now(),
196
+ level,
197
+ message
198
+ });
199
+ };
200
+ return {
201
+ logs: entries,
202
+ log,
203
+ info: (message) => log("info", message),
204
+ success: (message) => log("success", message),
205
+ warn: (message) => log("warn", message),
206
+ error: (message) => log("error", message),
207
+ pushLine: (line, stream = "stdout") => log(stream === "stderr" ? "error" : "info", line),
208
+ clear: () => {
209
+ entries.value = [];
210
+ }
211
+ };
212
+ }
213
+ //#endregion
214
+ //#region src/tui/App.vue
215
+ const _sfc_main = /*@__PURE__*/ defineComponent({
216
+ __name: "App",
217
+ setup(__props, { expose: __expose }) {
218
+ __expose();
219
+ const { exit } = useApp();
220
+ const { logs } = useLogs();
221
+ const activePanel = ref("projects");
222
+ const helpVisible = ref(false);
223
+ useKeymap({
224
+ onPanel: (panel) => {
225
+ activePanel.value = panel;
226
+ helpVisible.value = false;
227
+ },
228
+ onQuit: () => exit(),
229
+ onHelp: () => {
230
+ helpVisible.value = !helpVisible.value;
231
+ }
232
+ });
233
+ const __returned__ = {
234
+ exit,
235
+ logs,
236
+ activePanel,
237
+ helpVisible,
238
+ panelTitle: computed(() => `${PANEL_IDS.indexOf(activePanel.value) + 1}. ${PANEL_TITLES[activePanel.value]}`),
239
+ get Box() {
240
+ return Box;
241
+ },
242
+ get Text() {
243
+ return Text;
244
+ },
245
+ OutputPanel: OutputPanel_default,
246
+ StatusBar: StatusBar_default,
247
+ get PANEL_IDS() {
248
+ return PANEL_IDS;
249
+ },
250
+ get PANEL_TITLES() {
251
+ return PANEL_TITLES;
252
+ }
253
+ };
254
+ Object.defineProperty(__returned__, "__isScriptSetup", {
255
+ enumerable: false,
256
+ value: true
257
+ });
258
+ return __returned__;
259
+ }
260
+ });
261
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
262
+ return openBlock(), createBlock($setup["Box"], {
263
+ flexDirection: "column",
264
+ flexGrow: 1
265
+ }, {
266
+ default: withCtx(() => [
267
+ createCommentVNode(" 头部:标题 + 六面板键位总览 "),
268
+ createVNode($setup["Box"], {
269
+ paddingX: 1,
270
+ flexDirection: "row",
271
+ justifyContent: "space-between",
272
+ flexShrink: 0
273
+ }, {
274
+ default: withCtx(() => [createVNode($setup["Text"], {
275
+ bold: "",
276
+ color: "cyan"
277
+ }, {
278
+ default: withCtx(() => [..._cache[0] || (_cache[0] = [createTextVNode("Deploy CLI", -1)])]),
279
+ _: 1
280
+ }), createVNode($setup["Text"], { dimColor: "" }, {
281
+ default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode("1 Projects · 2 Containers · 3 Deploy · 4 Status · 5 Tunnels · 6 Output", -1)])]),
282
+ _: 1
283
+ })]),
284
+ _: 1
285
+ }),
286
+ createCommentVNode(" 主面板区:1-5 骨架占位(内容随 M2 后续任务实现),6=全局日志 "),
287
+ createVNode($setup["Box"], {
288
+ flexDirection: "column",
289
+ flexGrow: 1,
290
+ paddingX: 1
291
+ }, {
292
+ default: withCtx(() => [$setup.activePanel === "output" ? (openBlock(), createBlock($setup["OutputPanel"], {
293
+ key: 0,
294
+ logs: $setup.logs
295
+ }, null, 8, ["logs"])) : (openBlock(), createBlock($setup["Box"], {
296
+ key: 1,
297
+ flexDirection: "column",
298
+ flexGrow: 1,
299
+ borderStyle: "round",
300
+ padding: 1
301
+ }, {
302
+ default: withCtx(() => [createVNode($setup["Text"], {
303
+ bold: "",
304
+ color: "cyan"
305
+ }, {
306
+ default: withCtx(() => [createTextVNode(toDisplayString($setup.panelTitle), 1)]),
307
+ _: 1
308
+ }), createVNode($setup["Text"], { dimColor: "" }, {
309
+ default: withCtx(() => [..._cache[2] || (_cache[2] = [createTextVNode("(骨架占位:面板内容随 M2 后续任务实现)", -1)])]),
310
+ _: 1
311
+ })]),
312
+ _: 1
313
+ }))]),
314
+ _: 1
315
+ }),
316
+ createCommentVNode(" 帮助浮层(? 开关) "),
317
+ $setup.helpVisible ? (openBlock(), createBlock($setup["Box"], {
318
+ key: 0,
319
+ flexDirection: "column",
320
+ borderStyle: "round",
321
+ borderColor: "yellow",
322
+ padding: 1,
323
+ marginX: 1
324
+ }, {
325
+ default: withCtx(() => [
326
+ createVNode($setup["Text"], {
327
+ bold: "",
328
+ color: "yellow"
329
+ }, {
330
+ default: withCtx(() => [..._cache[3] || (_cache[3] = [createTextVNode("快捷键帮助", -1)])]),
331
+ _: 1
332
+ }),
333
+ (openBlock(true), createElementBlock(Fragment, null, renderList($setup.PANEL_IDS, (id, i) => {
334
+ return openBlock(), createBlock($setup["Text"], { key: id }, {
335
+ default: withCtx(() => [createTextVNode(toDisplayString(i + 1) + " " + toDisplayString($setup.PANEL_TITLES[id]), 1)]),
336
+ _: 2
337
+ }, 1024);
338
+ }), 128)),
339
+ createVNode($setup["Text"], null, {
340
+ default: withCtx(() => [..._cache[4] || (_cache[4] = [createTextVNode("? 打开/关闭帮助 │ q 退出", -1)])]),
341
+ _: 1
342
+ })
343
+ ]),
344
+ _: 1
345
+ })) : createCommentVNode("v-if", true),
346
+ createCommentVNode(" 底部状态栏 "),
347
+ createVNode($setup["StatusBar"], {
348
+ "active-panel": $setup.activePanel,
349
+ "help-visible": $setup.helpVisible
350
+ }, null, 8, ["active-panel", "help-visible"])
351
+ ]),
352
+ _: 1
353
+ });
354
+ }
355
+ //#endregion
356
+ //#region src/tui/main.ts
357
+ createApp(/* @__PURE__ */ export_helper_default(_sfc_main, [["render", _sfc_render], ["__file", "/Users/yangdongnan/work/deploy-cli/src/tui/App.vue"]])).mount({ exitOnCtrlC: true });
358
+ //#endregion
359
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dongnanyang/deploy-cli",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Local CLI TUI for SSH tunnels & deploy scripts",
5
5
  "type": "module",
6
6
  "main": "./dist/api.js",