@dongnanyang/deploy-cli 0.0.0-stage → 0.2.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/main.js ADDED
@@ -0,0 +1,1571 @@
1
+ import { Box, Text, createApp, useApp, useInput } from "@vue-tui/runtime";
2
+ import { Fragment, createBlock, createCommentVNode, createElementBlock, createTextVNode, createVNode, defineComponent, nextTick, onMounted, onUnmounted, openBlock, ref, renderList, shallowRef, toDisplayString, watch, withCtx } from "vue";
3
+ import { ScrollBox } from "@vue-tui/components";
4
+ import { createServer } from "net";
5
+ import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "fs";
6
+ import { Client } from "ssh2";
7
+ import { dirname, join, resolve } from "path";
8
+ import { homedir } from "os";
9
+ 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
+ //#region src/components/TunnelPanel.vue
18
+ const _sfc_main$6 = /*@__PURE__*/ defineComponent({
19
+ __name: "TunnelPanel",
20
+ props: {
21
+ tunnels: {
22
+ type: Array,
23
+ required: true
24
+ },
25
+ isActive: {
26
+ type: Boolean,
27
+ required: true
28
+ }
29
+ },
30
+ emits: [
31
+ "start",
32
+ "stop",
33
+ "startAll"
34
+ ],
35
+ setup(__props, { expose: __expose, emit: __emit }) {
36
+ __expose();
37
+ const props = __props;
38
+ const emit = __emit;
39
+ const selected = ref(0);
40
+ watch(() => props.tunnels.length, (len) => {
41
+ if (selected.value >= len) selected.value = Math.max(0, len - 1);
42
+ });
43
+ useInput((event) => {
44
+ if (!props.isActive) return;
45
+ if (event.type !== "key") return;
46
+ const name = event.key.name;
47
+ if (name === "j" || name === "down") selected.value = Math.min(selected.value + 1, props.tunnels.length - 1);
48
+ else if (name === "k" || name === "up") selected.value = Math.max(selected.value - 1, 0);
49
+ else if (name === "s") {
50
+ const t = props.tunnels[selected.value];
51
+ if (t) emit("start", t.name);
52
+ } else if (name === "x") {
53
+ const t = props.tunnels[selected.value];
54
+ if (t) emit("stop", t.name);
55
+ } else if (name === "a") emit("startAll");
56
+ }, { isActive: () => props.isActive });
57
+ const __returned__ = {
58
+ props,
59
+ emit,
60
+ selected,
61
+ get Box() {
62
+ return Box;
63
+ },
64
+ get Text() {
65
+ return Text;
66
+ }
67
+ };
68
+ Object.defineProperty(__returned__, "__isScriptSetup", {
69
+ enumerable: false,
70
+ value: true
71
+ });
72
+ return __returned__;
73
+ }
74
+ });
75
+ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
76
+ return openBlock(), createBlock($setup["Box"], {
77
+ flexDirection: "column",
78
+ borderStyle: "single",
79
+ borderColor: $props.isActive ? "cyan" : "gray",
80
+ padding: 1,
81
+ flexGrow: 1,
82
+ flexShrink: 0
83
+ }, {
84
+ default: withCtx(() => [
85
+ createVNode($setup["Text"], {
86
+ bold: "",
87
+ color: "cyan"
88
+ }, {
89
+ default: withCtx(() => [..._cache[0] || (_cache[0] = [createTextVNode("Tunnels", -1)])]),
90
+ _: 1
91
+ }),
92
+ $props.tunnels.length === 0 ? (openBlock(), createBlock($setup["Box"], {
93
+ key: 0,
94
+ flexDirection: "column"
95
+ }, {
96
+ default: withCtx(() => [createVNode($setup["Text"], { dimColor: "" }, {
97
+ default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode("暂无隧道配置", -1)])]),
98
+ _: 1
99
+ }), createVNode($setup["Text"], { dimColor: "" }, {
100
+ default: withCtx(() => [..._cache[2] || (_cache[2] = [createTextVNode("编辑 ~/.deploy-cli/config.json 添加", -1)])]),
101
+ _: 1
102
+ })]),
103
+ _: 1
104
+ })) : (openBlock(), createBlock($setup["Box"], {
105
+ key: 1,
106
+ flexDirection: "column",
107
+ marginTop: 1
108
+ }, {
109
+ default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList($props.tunnels, (t, i) => {
110
+ return openBlock(), createBlock($setup["Box"], {
111
+ key: t.name,
112
+ flexDirection: "row",
113
+ gap: 1,
114
+ flexShrink: 0
115
+ }, {
116
+ default: withCtx(() => [
117
+ createVNode($setup["Text"], { color: t.status === "running" ? "green" : t.status === "error" ? "red" : "gray" }, {
118
+ default: withCtx(() => [createTextVNode(toDisplayString(t.status === "running" ? "●" : t.status === "error" ? "✗" : "○"), 1)]),
119
+ _: 2
120
+ }, 1032, ["color"]),
121
+ createVNode($setup["Text"], {
122
+ bold: i === $setup.selected,
123
+ color: i === $setup.selected ? "cyan" : "default"
124
+ }, {
125
+ default: withCtx(() => [createTextVNode(toDisplayString(t.name), 1)]),
126
+ _: 2
127
+ }, 1032, ["bold", "color"]),
128
+ createVNode($setup["Text"], { dimColor: "" }, {
129
+ default: withCtx(() => [createTextVNode(":" + toDisplayString(t.localPort) + " -> " + toDisplayString(t.remoteHost) + ":" + toDisplayString(t.remotePort), 1)]),
130
+ _: 2
131
+ }, 1024),
132
+ t.autoStart ? (openBlock(), createBlock($setup["Text"], {
133
+ key: 0,
134
+ dimColor: ""
135
+ }, {
136
+ default: withCtx(() => [..._cache[3] || (_cache[3] = [createTextVNode("(auto)", -1)])]),
137
+ _: 1
138
+ })) : createCommentVNode("v-if", true)
139
+ ]),
140
+ _: 2
141
+ }, 1024);
142
+ }), 128))]),
143
+ _: 1
144
+ })),
145
+ createVNode($setup["Box"], {
146
+ flexDirection: "row",
147
+ marginTop: 1,
148
+ gap: 2,
149
+ flexShrink: 0
150
+ }, {
151
+ default: withCtx(() => [createVNode($setup["Text"], { dimColor: "" }, {
152
+ default: withCtx(() => [..._cache[4] || (_cache[4] = [createTextVNode("[s]tart [x]stop [a]ll", -1)])]),
153
+ _: 1
154
+ })]),
155
+ _: 1
156
+ })
157
+ ]),
158
+ _: 1
159
+ }, 8, ["borderColor"]);
160
+ }
161
+ var TunnelPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$6, [["render", _sfc_render$6], ["__file", "/Users/yangdongnan/work/deploy-cli/src/components/TunnelPanel.vue"]]);
162
+ //#endregion
163
+ //#region src/components/DeployPanel.vue
164
+ const _sfc_main$5 = /*@__PURE__*/ defineComponent({
165
+ __name: "DeployPanel",
166
+ props: {
167
+ scripts: {
168
+ type: Array,
169
+ required: true
170
+ },
171
+ isActive: {
172
+ type: Boolean,
173
+ required: true
174
+ },
175
+ running: {
176
+ type: [String, null],
177
+ required: true
178
+ }
179
+ },
180
+ emits: ["run", "runWithParams"],
181
+ setup(__props, { expose: __expose, emit: __emit }) {
182
+ __expose();
183
+ const props = __props;
184
+ const emit = __emit;
185
+ const selected = ref(0);
186
+ watch(() => props.scripts.length, (len) => {
187
+ if (selected.value >= len) selected.value = Math.max(0, len - 1);
188
+ });
189
+ useInput((event) => {
190
+ if (!props.isActive) return;
191
+ if (event.type !== "key") return;
192
+ const name = event.key.name;
193
+ if (name === "j" || name === "down") selected.value = Math.min(selected.value + 1, props.scripts.length - 1);
194
+ else if (name === "k" || name === "up") selected.value = Math.max(selected.value - 1, 0);
195
+ else if (name === "enter") {
196
+ const s = props.scripts[selected.value];
197
+ if (s) emit("run", s, []);
198
+ } else if (name === "p") {
199
+ const s = props.scripts[selected.value];
200
+ if (s) emit("runWithParams", s);
201
+ }
202
+ }, { isActive: () => props.isActive });
203
+ const __returned__ = {
204
+ props,
205
+ emit,
206
+ selected,
207
+ get Box() {
208
+ return Box;
209
+ },
210
+ get Text() {
211
+ return Text;
212
+ }
213
+ };
214
+ Object.defineProperty(__returned__, "__isScriptSetup", {
215
+ enumerable: false,
216
+ value: true
217
+ });
218
+ return __returned__;
219
+ }
220
+ });
221
+ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
222
+ return openBlock(), createBlock($setup["Box"], {
223
+ flexDirection: "column",
224
+ borderStyle: "single",
225
+ borderColor: $props.isActive ? "cyan" : "gray",
226
+ padding: 1,
227
+ flexGrow: 1,
228
+ flexShrink: 0
229
+ }, {
230
+ default: withCtx(() => [
231
+ createVNode($setup["Text"], {
232
+ bold: "",
233
+ color: "cyan"
234
+ }, {
235
+ default: withCtx(() => [..._cache[0] || (_cache[0] = [createTextVNode("Deploy", -1)])]),
236
+ _: 1
237
+ }),
238
+ $props.scripts.length === 0 ? (openBlock(), createBlock($setup["Box"], {
239
+ key: 0,
240
+ flexDirection: "column"
241
+ }, {
242
+ default: withCtx(() => [createVNode($setup["Text"], { dimColor: "" }, {
243
+ default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode("暂无部署脚本", -1)])]),
244
+ _: 1
245
+ }), createVNode($setup["Text"], { dimColor: "" }, {
246
+ default: withCtx(() => [..._cache[2] || (_cache[2] = [createTextVNode("按 [n] 添加项目", -1)])]),
247
+ _: 1
248
+ })]),
249
+ _: 1
250
+ })) : (openBlock(), createBlock($setup["Box"], {
251
+ key: 1,
252
+ flexDirection: "column",
253
+ marginTop: 1
254
+ }, {
255
+ default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList($props.scripts, (s, i) => {
256
+ return openBlock(), createBlock($setup["Box"], {
257
+ key: `${s.project}/${s.name}`,
258
+ flexDirection: "row",
259
+ gap: 1,
260
+ flexShrink: 0
261
+ }, {
262
+ default: withCtx(() => [
263
+ createVNode($setup["Text"], { color: i === $setup.selected ? "cyan" : "gray" }, {
264
+ default: withCtx(() => [createTextVNode(toDisplayString(i === $setup.selected ? "▸" : " "), 1)]),
265
+ _: 2
266
+ }, 1032, ["color"]),
267
+ createVNode($setup["Text"], { bold: i === $setup.selected }, {
268
+ default: withCtx(() => [createTextVNode(toDisplayString(s.project) + "/" + toDisplayString(s.name), 1)]),
269
+ _: 2
270
+ }, 1032, ["bold"]),
271
+ $props.running === `${s.project}/${s.name}` ? (openBlock(), createBlock($setup["Text"], {
272
+ key: 0,
273
+ color: "yellow"
274
+ }, {
275
+ default: withCtx(() => [..._cache[3] || (_cache[3] = [createTextVNode("running...", -1)])]),
276
+ _: 1
277
+ })) : s.lastResult === "success" ? (openBlock(), createBlock($setup["Text"], {
278
+ key: 1,
279
+ color: "green",
280
+ dimColor: ""
281
+ }, {
282
+ default: withCtx(() => [..._cache[4] || (_cache[4] = [createTextVNode("✓", -1)])]),
283
+ _: 1
284
+ })) : s.lastResult === "fail" ? (openBlock(), createBlock($setup["Text"], {
285
+ key: 2,
286
+ color: "red",
287
+ dimColor: ""
288
+ }, {
289
+ default: withCtx(() => [..._cache[5] || (_cache[5] = [createTextVNode("✗", -1)])]),
290
+ _: 1
291
+ })) : createCommentVNode("v-if", true)
292
+ ]),
293
+ _: 2
294
+ }, 1024);
295
+ }), 128))]),
296
+ _: 1
297
+ })),
298
+ createVNode($setup["Box"], {
299
+ flexDirection: "row",
300
+ marginTop: 1,
301
+ gap: 2,
302
+ flexShrink: 0
303
+ }, {
304
+ default: withCtx(() => [createVNode($setup["Text"], { dimColor: "" }, {
305
+ default: withCtx(() => [..._cache[6] || (_cache[6] = [createTextVNode("[Enter] run [p]arams", -1)])]),
306
+ _: 1
307
+ })]),
308
+ _: 1
309
+ })
310
+ ]),
311
+ _: 1
312
+ }, 8, ["borderColor"]);
313
+ }
314
+ var DeployPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$5, [["render", _sfc_render$5], ["__file", "/Users/yangdongnan/work/deploy-cli/src/components/DeployPanel.vue"]]);
315
+ //#endregion
316
+ //#region src/components/OutputPanel.vue
317
+ const _sfc_main$4 = /*@__PURE__*/ defineComponent({
318
+ __name: "OutputPanel",
319
+ props: {
320
+ logs: {
321
+ type: Array,
322
+ required: true
323
+ },
324
+ isActive: {
325
+ type: Boolean,
326
+ required: true
327
+ }
328
+ },
329
+ setup(__props, { expose: __expose }) {
330
+ __expose();
331
+ const props = __props;
332
+ const scrollRef = shallowRef(null);
333
+ watch(() => props.logs.length, async () => {
334
+ await nextTick();
335
+ scrollRef.value?.scrollToBottom();
336
+ });
337
+ useInput((event) => {
338
+ if (!props.isActive) return;
339
+ if (event.type !== "key") return;
340
+ const name = event.key.name;
341
+ if (name === "up") scrollRef.value?.scrollByLines(-1);
342
+ else if (name === "down") scrollRef.value?.scrollByLines(1);
343
+ else if (name === "g") scrollRef.value?.scrollToTop();
344
+ else if (name === "G") scrollRef.value?.scrollToBottom();
345
+ }, { isActive: () => props.isActive });
346
+ function levelColor(level) {
347
+ return level === "success" ? "green" : level === "error" ? "red" : level === "warn" ? "yellow" : "default";
348
+ }
349
+ function levelIcon(level) {
350
+ return level === "success" ? "✓" : level === "error" ? "✗" : level === "warn" ? "⚠" : " ";
351
+ }
352
+ const __returned__ = {
353
+ props,
354
+ scrollRef,
355
+ levelColor,
356
+ levelIcon,
357
+ get Box() {
358
+ return Box;
359
+ },
360
+ get Text() {
361
+ return Text;
362
+ },
363
+ get ScrollBox() {
364
+ return ScrollBox;
365
+ }
366
+ };
367
+ Object.defineProperty(__returned__, "__isScriptSetup", {
368
+ enumerable: false,
369
+ value: true
370
+ });
371
+ return __returned__;
372
+ }
373
+ });
374
+ function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
375
+ return openBlock(), createBlock($setup["Box"], {
376
+ flexDirection: "column",
377
+ borderStyle: "single",
378
+ borderColor: $props.isActive ? "cyan" : "gray",
379
+ padding: 0,
380
+ flexGrow: 2,
381
+ overflow: "hidden"
382
+ }, {
383
+ default: withCtx(() => [createVNode($setup["Box"], { paddingX: 1 }, {
384
+ default: withCtx(() => [createVNode($setup["Text"], {
385
+ bold: "",
386
+ color: "cyan"
387
+ }, {
388
+ default: withCtx(() => [..._cache[0] || (_cache[0] = [createTextVNode("Output", -1)])]),
389
+ _: 1
390
+ })]),
391
+ _: 1
392
+ }), createVNode($setup["ScrollBox"], {
393
+ ref: "scrollRef",
394
+ flexGrow: 1
395
+ }, {
396
+ default: withCtx(() => [createVNode($setup["Box"], {
397
+ flexDirection: "column",
398
+ paddingX: 1
399
+ }, {
400
+ default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList($props.logs, (log, i) => {
401
+ return openBlock(), createBlock($setup["Box"], {
402
+ key: i,
403
+ flexDirection: "row",
404
+ gap: 1
405
+ }, {
406
+ default: withCtx(() => [
407
+ createVNode($setup["Text"], { dimColor: "" }, {
408
+ default: withCtx(() => [createTextVNode(toDisplayString(log.time), 1)]),
409
+ _: 2
410
+ }, 1024),
411
+ createVNode($setup["Text"], { color: $setup.levelColor(log.level) }, {
412
+ default: withCtx(() => [createTextVNode(toDisplayString($setup.levelIcon(log.level)), 1)]),
413
+ _: 2
414
+ }, 1032, ["color"]),
415
+ createVNode($setup["Text"], {
416
+ color: $setup.levelColor(log.level),
417
+ dimColor: log.level === "info"
418
+ }, {
419
+ default: withCtx(() => [createTextVNode(toDisplayString(log.message), 1)]),
420
+ _: 2
421
+ }, 1032, ["color", "dimColor"])
422
+ ]),
423
+ _: 2
424
+ }, 1024);
425
+ }), 128))]),
426
+ _: 1
427
+ })]),
428
+ _: 1
429
+ }, 512)]),
430
+ _: 1
431
+ }, 8, ["borderColor"]);
432
+ }
433
+ var OutputPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$4, [["render", _sfc_render$4], ["__file", "/Users/yangdongnan/work/deploy-cli/src/components/OutputPanel.vue"]]);
434
+ //#endregion
435
+ //#region src/components/StatusBar.vue
436
+ const _sfc_main$3 = /*@__PURE__*/ defineComponent({
437
+ __name: "StatusBar",
438
+ props: {
439
+ tunnelCount: {
440
+ type: Number,
441
+ required: true
442
+ },
443
+ focus: {
444
+ type: String,
445
+ required: true
446
+ },
447
+ runningDeploy: {
448
+ type: [String, null],
449
+ required: true
450
+ }
451
+ },
452
+ setup(__props, { expose: __expose }) {
453
+ __expose();
454
+ const __returned__ = {
455
+ get Box() {
456
+ return Box;
457
+ },
458
+ get Text() {
459
+ return Text;
460
+ }
461
+ };
462
+ Object.defineProperty(__returned__, "__isScriptSetup", {
463
+ enumerable: false,
464
+ value: true
465
+ });
466
+ return __returned__;
467
+ }
468
+ });
469
+ function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
470
+ return openBlock(), createBlock($setup["Box"], {
471
+ flexDirection: "row",
472
+ paddingX: 1,
473
+ flexShrink: 0
474
+ }, {
475
+ default: withCtx(() => [
476
+ createVNode($setup["Text"], { color: $props.tunnelCount > 0 ? "green" : "gray" }, {
477
+ default: withCtx(() => [createTextVNode(toDisplayString($props.tunnelCount) + " tunnels running ", 1)]),
478
+ _: 1
479
+ }, 8, ["color"]),
480
+ createVNode($setup["Text"], { dimColor: "" }, {
481
+ default: withCtx(() => [..._cache[0] || (_cache[0] = [createTextVNode(" │ ", -1)])]),
482
+ _: 1
483
+ }),
484
+ createVNode($setup["Text"], { dimColor: "" }, {
485
+ default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode("focus: ", -1)])]),
486
+ _: 1
487
+ }),
488
+ createVNode($setup["Text"], { bold: "" }, {
489
+ default: withCtx(() => [createTextVNode(toDisplayString($props.focus), 1)]),
490
+ _: 1
491
+ }),
492
+ $props.runningDeploy ? (openBlock(), createBlock($setup["Text"], {
493
+ key: 0,
494
+ dimColor: ""
495
+ }, {
496
+ default: withCtx(() => [..._cache[2] || (_cache[2] = [createTextVNode(" │ ", -1)])]),
497
+ _: 1
498
+ })) : createCommentVNode("v-if", true),
499
+ $props.runningDeploy ? (openBlock(), createBlock($setup["Text"], {
500
+ key: 1,
501
+ color: "yellow"
502
+ }, {
503
+ default: withCtx(() => [createTextVNode(toDisplayString($props.runningDeploy), 1)]),
504
+ _: 1
505
+ })) : createCommentVNode("v-if", true),
506
+ createVNode($setup["Text"], { dimColor: "" }, {
507
+ default: withCtx(() => [..._cache[3] || (_cache[3] = [createTextVNode(" │ [Tab] switch [n]ew [r]escan [q] quit", -1)])]),
508
+ _: 1
509
+ })
510
+ ]),
511
+ _: 1
512
+ });
513
+ }
514
+ var StatusBar_default = /*#__PURE__*/ export_helper_default(_sfc_main$3, [["render", _sfc_render$3], ["__file", "/Users/yangdongnan/work/deploy-cli/src/components/StatusBar.vue"]]);
515
+ //#endregion
516
+ //#region src/components/InputModal.vue
517
+ const _sfc_main$2 = /*@__PURE__*/ defineComponent({
518
+ __name: "InputModal",
519
+ props: {
520
+ title: {
521
+ type: String,
522
+ required: true
523
+ },
524
+ fields: {
525
+ type: Array,
526
+ required: true
527
+ },
528
+ visible: {
529
+ type: Boolean,
530
+ required: true
531
+ }
532
+ },
533
+ emits: ["submit", "cancel"],
534
+ setup(__props, { expose: __expose, emit: __emit }) {
535
+ __expose();
536
+ const props = __props;
537
+ const emit = __emit;
538
+ const values = ref({});
539
+ const fieldIdx = ref(0);
540
+ watch(() => props.visible, (v) => {
541
+ if (v) {
542
+ values.value = {};
543
+ for (const f of props.fields) values.value[f.key] = f.default || "";
544
+ fieldIdx.value = 0;
545
+ }
546
+ });
547
+ useInput((event) => {
548
+ if (!props.visible) return;
549
+ if (event.type !== "key") return;
550
+ const name = event.key.name;
551
+ if (name === "escape") {
552
+ emit("cancel");
553
+ return;
554
+ }
555
+ if (name === "enter") {
556
+ emit("submit", { ...values.value });
557
+ return;
558
+ }
559
+ if (name === "tab") {
560
+ fieldIdx.value = (fieldIdx.value + 1) % props.fields.length;
561
+ return;
562
+ }
563
+ if (name === "backspace") {
564
+ const key = props.fields[fieldIdx.value].key;
565
+ values.value[key] = values.value[key].slice(0, -1);
566
+ return;
567
+ }
568
+ if (event.key.character) {
569
+ const key = props.fields[fieldIdx.value].key;
570
+ values.value[key] += event.key.character;
571
+ }
572
+ }, { isActive: () => props.visible });
573
+ const __returned__ = {
574
+ props,
575
+ emit,
576
+ values,
577
+ fieldIdx,
578
+ get Box() {
579
+ return Box;
580
+ },
581
+ get Text() {
582
+ return Text;
583
+ }
584
+ };
585
+ Object.defineProperty(__returned__, "__isScriptSetup", {
586
+ enumerable: false,
587
+ value: true
588
+ });
589
+ return __returned__;
590
+ }
591
+ });
592
+ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
593
+ return $props.visible ? (openBlock(), createBlock($setup["Box"], {
594
+ key: 0,
595
+ flexDirection: "column",
596
+ borderStyle: "round",
597
+ borderColor: "cyan",
598
+ padding: 1,
599
+ width: 60,
600
+ position: "absolute",
601
+ top: 2,
602
+ left: 2
603
+ }, {
604
+ default: withCtx(() => [
605
+ createVNode($setup["Text"], {
606
+ bold: "",
607
+ color: "cyan"
608
+ }, {
609
+ default: withCtx(() => [createTextVNode(toDisplayString($props.title), 1)]),
610
+ _: 1
611
+ }),
612
+ createVNode($setup["Box"], {
613
+ flexDirection: "column",
614
+ marginTop: 1,
615
+ gap: 1
616
+ }, {
617
+ default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList($props.fields, (f, i) => {
618
+ return openBlock(), createBlock($setup["Box"], {
619
+ key: f.key,
620
+ flexDirection: "row",
621
+ gap: 1
622
+ }, {
623
+ default: withCtx(() => [
624
+ createVNode($setup["Text"], {
625
+ color: i === $setup.fieldIdx ? "cyan" : "gray",
626
+ bold: i === $setup.fieldIdx
627
+ }, {
628
+ default: withCtx(() => [createTextVNode(toDisplayString(i === $setup.fieldIdx ? "▸" : " "), 1)]),
629
+ _: 2
630
+ }, 1032, ["color", "bold"]),
631
+ createVNode($setup["Text"], { dimColor: "" }, {
632
+ default: withCtx(() => [createTextVNode(toDisplayString(f.label) + ":", 1)]),
633
+ _: 2
634
+ }, 1024),
635
+ createVNode($setup["Text"], { bold: i === $setup.fieldIdx }, {
636
+ default: withCtx(() => [createTextVNode(toDisplayString($setup.values[f.key] || "") + " ", 1), i === $setup.fieldIdx ? (openBlock(), createBlock($setup["Text"], {
637
+ key: 0,
638
+ color: "cyan"
639
+ }, {
640
+ default: withCtx(() => [..._cache[0] || (_cache[0] = [createTextVNode("_", -1)])]),
641
+ _: 1
642
+ })) : createCommentVNode("v-if", true)]),
643
+ _: 2
644
+ }, 1032, ["bold"])
645
+ ]),
646
+ _: 2
647
+ }, 1024);
648
+ }), 128))]),
649
+ _: 1
650
+ }),
651
+ createVNode($setup["Box"], {
652
+ flexDirection: "row",
653
+ marginTop: 1,
654
+ gap: 2
655
+ }, {
656
+ default: withCtx(() => [createVNode($setup["Text"], { dimColor: "" }, {
657
+ default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode("[Enter] 确认 [Esc] 取消 [Tab] 切换字段", -1)])]),
658
+ _: 1
659
+ })]),
660
+ _: 1
661
+ })
662
+ ]),
663
+ _: 1
664
+ })) : createCommentVNode("v-if", true);
665
+ }
666
+ var InputModal_default = /*#__PURE__*/ export_helper_default(_sfc_main$2, [["render", _sfc_render$2], ["__file", "/Users/yangdongnan/work/deploy-cli/src/components/InputModal.vue"]]);
667
+ //#endregion
668
+ //#region src/components/ConfigPanel.vue
669
+ const _sfc_main$1 = /*@__PURE__*/ defineComponent({
670
+ __name: "ConfigPanel",
671
+ props: {
672
+ config: {
673
+ type: Object,
674
+ required: true
675
+ },
676
+ isActive: {
677
+ type: Boolean,
678
+ required: true
679
+ },
680
+ visible: {
681
+ type: Boolean,
682
+ required: true
683
+ }
684
+ },
685
+ emits: ["configChanged"],
686
+ setup(__props, { expose: __expose, emit: __emit }) {
687
+ __expose();
688
+ const props = __props;
689
+ const emit = __emit;
690
+ const modalType = ref(null);
691
+ useInput((event) => {
692
+ if (!props.visible || modalType.value !== null) return;
693
+ if (event.type !== "key") return;
694
+ const name = event.key.name;
695
+ if (name === "1") modalType.value = "server";
696
+ else if (name === "2") modalType.value = "tunnel";
697
+ else if (name === "3") modalType.value = "project";
698
+ else if (name === "escape") emit("configChanged");
699
+ });
700
+ function handleSubmit(values) {
701
+ const type = modalType.value;
702
+ modalType.value = null;
703
+ if (type === "server") {
704
+ const server = {
705
+ name: values.name,
706
+ host: values.host,
707
+ port: parseInt(values.port) || 22,
708
+ username: values.username || "root",
709
+ privateKey: values.privateKey || void 0,
710
+ password: values.password || void 0
711
+ };
712
+ props.config.servers.push(server);
713
+ } else if (type === "tunnel") {
714
+ const tunnel = {
715
+ name: values.name,
716
+ server: values.server,
717
+ localPort: parseInt(values.localPort) || 3306,
718
+ remoteHost: values.remoteHost || "127.0.0.1",
719
+ remotePort: parseInt(values.remotePort) || 3306,
720
+ autoStart: values.autoStart === "y" || values.autoStart === "true"
721
+ };
722
+ props.config.tunnels.push(tunnel);
723
+ } else if (type === "project") {
724
+ const project = {
725
+ name: values.name,
726
+ path: values.path,
727
+ deployDir: values.deployDir || "deploy",
728
+ server: values.server || void 0
729
+ };
730
+ props.config.projects.push(project);
731
+ }
732
+ emit("configChanged");
733
+ }
734
+ function handleCancel() {
735
+ modalType.value = null;
736
+ }
737
+ const __returned__ = {
738
+ props,
739
+ emit,
740
+ modalType,
741
+ handleSubmit,
742
+ handleCancel,
743
+ serverFields: [
744
+ {
745
+ key: "name",
746
+ label: "名称 ",
747
+ placeholder: "prod-web"
748
+ },
749
+ {
750
+ key: "host",
751
+ label: "主机 ",
752
+ placeholder: "example.com"
753
+ },
754
+ {
755
+ key: "port",
756
+ label: "端口 ",
757
+ default: "22"
758
+ },
759
+ {
760
+ key: "username",
761
+ label: "用户 ",
762
+ default: "root"
763
+ },
764
+ {
765
+ key: "privateKey",
766
+ label: "私钥路径 ",
767
+ placeholder: "~/.ssh/id_rsa"
768
+ }
769
+ ],
770
+ tunnelFields: [
771
+ {
772
+ key: "name",
773
+ label: "名称 ",
774
+ placeholder: "MySQL"
775
+ },
776
+ {
777
+ key: "server",
778
+ label: "服务器名 ",
779
+ placeholder: "prod-web"
780
+ },
781
+ {
782
+ key: "localPort",
783
+ label: "本地端口 ",
784
+ placeholder: "3306"
785
+ },
786
+ {
787
+ key: "remoteHost",
788
+ label: "远程主机 ",
789
+ default: "127.0.0.1"
790
+ },
791
+ {
792
+ key: "remotePort",
793
+ label: "远程端口 ",
794
+ placeholder: "3306"
795
+ },
796
+ {
797
+ key: "autoStart",
798
+ label: "自动启动 ",
799
+ default: "n"
800
+ }
801
+ ],
802
+ projectFields: [
803
+ {
804
+ key: "name",
805
+ label: "项目名 ",
806
+ placeholder: "my-app"
807
+ },
808
+ {
809
+ key: "path",
810
+ label: "本地路径 ",
811
+ placeholder: "~/work/my-app"
812
+ },
813
+ {
814
+ key: "deployDir",
815
+ label: "脚本目录 ",
816
+ default: "deploy"
817
+ },
818
+ {
819
+ key: "server",
820
+ label: "服务器名 ",
821
+ placeholder: "prod-web"
822
+ }
823
+ ],
824
+ get Box() {
825
+ return Box;
826
+ },
827
+ get Text() {
828
+ return Text;
829
+ },
830
+ InputModal: InputModal_default
831
+ };
832
+ Object.defineProperty(__returned__, "__isScriptSetup", {
833
+ enumerable: false,
834
+ value: true
835
+ });
836
+ return __returned__;
837
+ }
838
+ });
839
+ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
840
+ return openBlock(), createElementBlock(Fragment, null, [
841
+ createCommentVNode(" 配置面板 "),
842
+ $props.visible && $setup.modalType === null ? (openBlock(), createBlock($setup["Box"], {
843
+ key: 0,
844
+ flexDirection: "column",
845
+ borderStyle: "round",
846
+ borderColor: "yellow",
847
+ padding: 1,
848
+ width: 50,
849
+ position: "absolute",
850
+ top: 3,
851
+ left: 3
852
+ }, {
853
+ default: withCtx(() => [
854
+ createVNode($setup["Text"], {
855
+ bold: "",
856
+ color: "yellow"
857
+ }, {
858
+ default: withCtx(() => [..._cache[0] || (_cache[0] = [createTextVNode("配置管理", -1)])]),
859
+ _: 1
860
+ }),
861
+ createVNode($setup["Box"], {
862
+ flexDirection: "column",
863
+ marginTop: 1,
864
+ gap: 1
865
+ }, {
866
+ default: withCtx(() => [
867
+ createVNode($setup["Text"], { color: "cyan" }, {
868
+ default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode("[1] 添加服务器", -1)])]),
869
+ _: 1
870
+ }),
871
+ createVNode($setup["Text"], { color: "cyan" }, {
872
+ default: withCtx(() => [..._cache[2] || (_cache[2] = [createTextVNode("[2] 添加隧道", -1)])]),
873
+ _: 1
874
+ }),
875
+ createVNode($setup["Text"], { color: "cyan" }, {
876
+ default: withCtx(() => [..._cache[3] || (_cache[3] = [createTextVNode("[3] 添加项目", -1)])]),
877
+ _: 1
878
+ })
879
+ ]),
880
+ _: 1
881
+ }),
882
+ createVNode($setup["Box"], {
883
+ flexDirection: "column",
884
+ marginTop: 1
885
+ }, {
886
+ default: withCtx(() => [createVNode($setup["Text"], { dimColor: "" }, {
887
+ default: withCtx(() => [createTextVNode("当前: " + toDisplayString($props.config.servers.length) + " 服务器, " + toDisplayString($props.config.tunnels.length) + " 隧道, " + toDisplayString($props.config.projects.length) + " 项目", 1)]),
888
+ _: 1
889
+ })]),
890
+ _: 1
891
+ }),
892
+ createVNode($setup["Box"], {
893
+ flexDirection: "row",
894
+ marginTop: 1
895
+ }, {
896
+ default: withCtx(() => [createVNode($setup["Text"], { dimColor: "" }, {
897
+ default: withCtx(() => [..._cache[4] || (_cache[4] = [createTextVNode("[Esc] 保存并关闭", -1)])]),
898
+ _: 1
899
+ })]),
900
+ _: 1
901
+ })
902
+ ]),
903
+ _: 1
904
+ })) : createCommentVNode("v-if", true),
905
+ createCommentVNode(" 添加服务器弹窗 "),
906
+ createVNode($setup["InputModal"], {
907
+ title: "添加服务器",
908
+ fields: $setup.serverFields,
909
+ visible: $setup.modalType === "server",
910
+ onSubmit: $setup.handleSubmit,
911
+ onCancel: $setup.handleCancel
912
+ }, null, 8, ["visible"]),
913
+ createCommentVNode(" 添加隧道弹窗 "),
914
+ createVNode($setup["InputModal"], {
915
+ title: "添加隧道",
916
+ fields: $setup.tunnelFields,
917
+ visible: $setup.modalType === "tunnel",
918
+ onSubmit: $setup.handleSubmit,
919
+ onCancel: $setup.handleCancel
920
+ }, null, 8, ["visible"]),
921
+ createCommentVNode(" 添加项目弹窗 "),
922
+ createVNode($setup["InputModal"], {
923
+ title: "添加项目",
924
+ fields: $setup.projectFields,
925
+ visible: $setup.modalType === "project",
926
+ onSubmit: $setup.handleSubmit,
927
+ onCancel: $setup.handleCancel
928
+ }, null, 8, ["visible"])
929
+ ], 64);
930
+ }
931
+ var ConfigPanel_default = /*#__PURE__*/ export_helper_default(_sfc_main$1, [["render", _sfc_render$1], ["__file", "/Users/yangdongnan/work/deploy-cli/src/components/ConfigPanel.vue"]]);
932
+ //#endregion
933
+ //#region src/core/config.ts
934
+ const CONFIG_DIR = resolve(homedir(), ".deploy-cli");
935
+ const CONFIG_PATH = resolve(CONFIG_DIR, "config.json");
936
+ const DEFAULT_CONFIG = {
937
+ servers: [],
938
+ tunnels: [],
939
+ projects: []
940
+ };
941
+ /** 读取配置,不存在则创建默认配置;projects 缺 deployDir 时补默认值 'deploy' */
942
+ function loadConfig() {
943
+ if (!existsSync(CONFIG_PATH)) {
944
+ mkdirSync(CONFIG_DIR, { recursive: true });
945
+ saveConfig(DEFAULT_CONFIG);
946
+ console.log(`[config] 已创建默认配置: ${CONFIG_PATH}`);
947
+ return {
948
+ servers: [],
949
+ tunnels: [],
950
+ projects: []
951
+ };
952
+ }
953
+ const raw = readFileSync(CONFIG_PATH, "utf-8");
954
+ let parsed;
955
+ try {
956
+ parsed = JSON.parse(raw);
957
+ } catch (error) {
958
+ const reason = error instanceof Error ? error.message : String(error);
959
+ throw new Error(`配置文件损坏(JSON 解析失败): ${CONFIG_PATH}: ${reason}`);
960
+ }
961
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error(`配置文件损坏(应为 JSON 对象): ${CONFIG_PATH}`);
962
+ const config = parsed;
963
+ return {
964
+ servers: asArray(config.servers, "servers"),
965
+ tunnels: asArray(config.tunnels, "tunnels"),
966
+ projects: asArray(config.projects, "projects").map((project) => normalizeProject(project))
967
+ };
968
+ }
969
+ /** 字段缺省视为空数组;非数组抛配置错误(含路径),避免 TypeError 崩溃 */
970
+ function asArray(value, key) {
971
+ if (value === void 0 || value === null) return [];
972
+ if (!Array.isArray(value)) throw new Error(`配置文件损坏(${key} 应为数组): ${CONFIG_PATH}`);
973
+ return value;
974
+ }
975
+ /** 写入配置 */
976
+ function saveConfig(config) {
977
+ mkdirSync(CONFIG_DIR, { recursive: true });
978
+ writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2) + "\n", "utf-8");
979
+ }
980
+ /** 展开 ~ 路径 */
981
+ function expandPath(p) {
982
+ if (p.startsWith("~/")) return resolve(homedir(), p.slice(2));
983
+ if (p === "~") return homedir();
984
+ return resolve(p);
985
+ }
986
+ /** 读入的项目元素缺 deployDir 时补默认值(配置文件可省略该字段) */
987
+ function normalizeProject(project) {
988
+ return {
989
+ ...project,
990
+ deployDir: project.deployDir ?? "deploy"
991
+ };
992
+ }
993
+ //#endregion
994
+ //#region src/lib/tunnel.ts
995
+ const activeTunnels = /* @__PURE__ */ new Map();
996
+ /** 读取私钥文件内容 */
997
+ function readPrivateKey(keyPath) {
998
+ const expanded = expandPath(keyPath);
999
+ return readFileSync(expanded, "utf-8");
1000
+ }
1001
+ /** 建立 SSH 连接 */
1002
+ function createSSHConn(server) {
1003
+ return new Promise((resolve, reject) => {
1004
+ const conn = new Client();
1005
+ const config = {
1006
+ host: server.host,
1007
+ port: server.port,
1008
+ username: server.username,
1009
+ readyTimeout: 1e4
1010
+ };
1011
+ if (server.privateKey) config.privateKey = readPrivateKey(server.privateKey);
1012
+ else if (server.password) config.password = server.password;
1013
+ const timer = setTimeout(() => reject(/* @__PURE__ */ new Error("SSH 连接超时")), 12e3);
1014
+ conn.on("ready", () => {
1015
+ clearTimeout(timer);
1016
+ resolve(conn);
1017
+ });
1018
+ conn.on("error", (err) => {
1019
+ clearTimeout(timer);
1020
+ reject(err);
1021
+ });
1022
+ conn.connect(config);
1023
+ });
1024
+ }
1025
+ /** 启动隧道 */
1026
+ async function startTunnel(tunnel, server, onLog) {
1027
+ if (activeTunnels.has(tunnel.name)) throw new Error(`隧道 "${tunnel.name}" 已在运行`);
1028
+ onLog("info", `正在连接 ${server.host}...`);
1029
+ const conn = await createSSHConn(server);
1030
+ onLog("info", `SSH 已连接 ${server.username}@${server.host}`);
1031
+ const netServer = createServer((socket) => {
1032
+ conn.forwardOut(socket.remoteAddress || "127.0.0.1", socket.remotePort || 0, tunnel.remoteHost, tunnel.remotePort, (err, stream) => {
1033
+ if (err) {
1034
+ socket.destroy();
1035
+ return;
1036
+ }
1037
+ socket.pipe(stream);
1038
+ stream.pipe(socket);
1039
+ socket.on("error", () => stream.end());
1040
+ socket.on("close", () => stream.end());
1041
+ stream.on("error", () => socket.destroy());
1042
+ stream.on("close", () => socket.destroy());
1043
+ });
1044
+ });
1045
+ await new Promise((resolve, reject) => {
1046
+ netServer.on("error", reject);
1047
+ netServer.listen(tunnel.localPort, "127.0.0.1", resolve);
1048
+ });
1049
+ conn.on("close", () => {
1050
+ if (activeTunnels.has(tunnel.name)) {
1051
+ stopTunnel(tunnel.name);
1052
+ onLog("warn", `隧道 "${tunnel.name}" SSH 连接断开`);
1053
+ }
1054
+ });
1055
+ conn.on("error", () => {
1056
+ if (activeTunnels.has(tunnel.name)) {
1057
+ stopTunnel(tunnel.name);
1058
+ onLog("error", `隧道 "${tunnel.name}" SSH 错误`);
1059
+ }
1060
+ });
1061
+ activeTunnels.set(tunnel.name, {
1062
+ server: netServer,
1063
+ conn
1064
+ });
1065
+ onLog("success", `隧道 "${tunnel.name}" 已启动: localhost:${tunnel.localPort} -> ${tunnel.remoteHost}:${tunnel.remotePort}`);
1066
+ }
1067
+ /** 停止隧道 */
1068
+ function stopTunnel(name) {
1069
+ const active = activeTunnels.get(name);
1070
+ if (!active) return;
1071
+ active.server.close();
1072
+ active.conn.end();
1073
+ activeTunnels.delete(name);
1074
+ }
1075
+ /** 查询隧道运行状态 */
1076
+ function getTunnelStatus(name) {
1077
+ return activeTunnels.has(name) ? "running" : "stopped";
1078
+ }
1079
+ /** 停止所有隧道 */
1080
+ function stopAllTunnels() {
1081
+ for (const name of activeTunnels.keys()) stopTunnel(name);
1082
+ }
1083
+ /** 从配置生成隧道状态列表 */
1084
+ function buildTunnelStates(config) {
1085
+ return config.tunnels.map((t) => ({
1086
+ name: t.name,
1087
+ server: t.server,
1088
+ localPort: t.localPort,
1089
+ remoteHost: t.remoteHost,
1090
+ remotePort: t.remotePort,
1091
+ autoStart: t.autoStart,
1092
+ status: getTunnelStatus(t.name)
1093
+ }));
1094
+ }
1095
+ //#endregion
1096
+ //#region src/composables/useTunnels.ts
1097
+ function useTunnels(config, logs) {
1098
+ const tunnels = ref(buildTunnelStates(config));
1099
+ const starting = ref(/* @__PURE__ */ new Set());
1100
+ function log(level, message) {
1101
+ logs.value.push({
1102
+ time: (/* @__PURE__ */ new Date()).toLocaleTimeString("zh-CN", { hour12: false }),
1103
+ level,
1104
+ message
1105
+ });
1106
+ }
1107
+ async function start(name) {
1108
+ const tunnel = config.tunnels.find((t) => t.name === name);
1109
+ if (!tunnel) return;
1110
+ const server = config.servers.find((s) => s.name === tunnel.server);
1111
+ if (!server) {
1112
+ log("error", `找不到服务器: ${tunnel.server}`);
1113
+ return;
1114
+ }
1115
+ starting.value.add(name);
1116
+ const state = tunnels.value.find((t) => t.name === name);
1117
+ if (state) state.status = "running";
1118
+ try {
1119
+ await startTunnel(tunnel, server, log);
1120
+ const s = tunnels.value.find((t) => t.name === name);
1121
+ if (s) {
1122
+ s.status = "running";
1123
+ s.message = void 0;
1124
+ }
1125
+ } catch (e) {
1126
+ const s = tunnels.value.find((t) => t.name === name);
1127
+ if (s) {
1128
+ s.status = "error";
1129
+ s.message = e.message;
1130
+ }
1131
+ log("error", `隧道 "${name}" 启动失败: ${e.message}`);
1132
+ } finally {
1133
+ starting.value.delete(name);
1134
+ }
1135
+ }
1136
+ function stop(name) {
1137
+ stopTunnel(name);
1138
+ const s = tunnels.value.find((t) => t.name === name);
1139
+ if (s) s.status = "stopped";
1140
+ log("info", `隧道 "${name}" 已停止`);
1141
+ }
1142
+ async function startAll() {
1143
+ for (const t of config.tunnels) {
1144
+ if (getTunnelRunning(t.name)) continue;
1145
+ await start(t.name);
1146
+ }
1147
+ }
1148
+ function getTunnelRunning(name) {
1149
+ return tunnels.value.find((t) => t.name === name)?.status === "running";
1150
+ }
1151
+ function cleanup() {
1152
+ stopAllTunnels();
1153
+ }
1154
+ async function autoStart() {
1155
+ for (const t of config.tunnels) if (t.autoStart) await start(t.name);
1156
+ }
1157
+ return {
1158
+ tunnels,
1159
+ starting,
1160
+ start,
1161
+ stop,
1162
+ startAll,
1163
+ autoStart,
1164
+ cleanup
1165
+ };
1166
+ }
1167
+ //#endregion
1168
+ //#region src/lib/deploy-runner.ts
1169
+ /** 扫描项目的部署脚本 */
1170
+ function discoverScripts(project) {
1171
+ const projectPath = expandPath(project.path);
1172
+ const deployPath = resolve(projectPath, project.deployDir);
1173
+ let files;
1174
+ try {
1175
+ files = readdirSync(deployPath);
1176
+ } catch {
1177
+ return [];
1178
+ }
1179
+ return files.filter((f) => f.endsWith(".sh")).map((f) => ({
1180
+ project: project.name,
1181
+ name: f,
1182
+ path: join(deployPath, f)
1183
+ })).sort((a, b) => a.name.localeCompare(b.name));
1184
+ }
1185
+ /** 执行部署脚本 */
1186
+ function runDeployScript(script, args, onOutput, onExit) {
1187
+ const cwd = dirname(script.path);
1188
+ const child = spawn("bash", [script.name, ...args], {
1189
+ cwd,
1190
+ stdio: [
1191
+ "pipe",
1192
+ "pipe",
1193
+ "pipe"
1194
+ ],
1195
+ env: { ...process.env }
1196
+ });
1197
+ const handleStream = (stream) => {
1198
+ let buffer = "";
1199
+ stream.on("data", (chunk) => {
1200
+ buffer += chunk.toString();
1201
+ const lines = buffer.split("\n");
1202
+ buffer = lines.pop() || "";
1203
+ for (const line of lines) if (line.trim()) onOutput(line);
1204
+ });
1205
+ stream.on("end", () => {
1206
+ if (buffer.trim()) onOutput(buffer);
1207
+ });
1208
+ };
1209
+ handleStream(child.stdout);
1210
+ handleStream(child.stderr);
1211
+ child.on("exit", onExit);
1212
+ }
1213
+ /** 记录脚本执行结果 */
1214
+ function saveScriptResult(script, success) {
1215
+ script.lastRun = (/* @__PURE__ */ new Date()).toISOString();
1216
+ script.lastResult = success ? "success" : "fail";
1217
+ }
1218
+ //#endregion
1219
+ //#region src/composables/useDeploy.ts
1220
+ function useDeploy(config, logs) {
1221
+ const scripts = ref([]);
1222
+ const running = ref(null);
1223
+ function log(level, message) {
1224
+ logs.value.push({
1225
+ time: (/* @__PURE__ */ new Date()).toLocaleTimeString("zh-CN", { hour12: false }),
1226
+ level,
1227
+ message
1228
+ });
1229
+ }
1230
+ function scan() {
1231
+ const all = [];
1232
+ for (const project of config.projects) {
1233
+ const found = discoverScripts(project);
1234
+ all.push(...found);
1235
+ }
1236
+ scripts.value = all;
1237
+ log("info", `扫描完成: ${config.projects.length} 个项目, ${all.length} 个脚本`);
1238
+ }
1239
+ function run(script, args = []) {
1240
+ const key = `${script.project}/${script.name}`;
1241
+ if (running.value) {
1242
+ log("warn", `已有脚本在运行: ${running.value}`);
1243
+ return;
1244
+ }
1245
+ running.value = key;
1246
+ log("info", `▸ ${key}${args.length ? " " + args.join(" ") : ""}`);
1247
+ runDeployScript(script, args, (line) => {
1248
+ logs.value.push({
1249
+ time: (/* @__PURE__ */ new Date()).toLocaleTimeString("zh-CN", { hour12: false }),
1250
+ level: "info",
1251
+ message: ` ${line}`
1252
+ });
1253
+ }, (code) => {
1254
+ const success = code === 0;
1255
+ saveScriptResult(script, success);
1256
+ log(success ? "success" : "error", `${success ? "✓" : "✗"} ${key} ${success ? "完成" : `失败 (exit ${code})`}`);
1257
+ running.value = null;
1258
+ });
1259
+ }
1260
+ return {
1261
+ scripts,
1262
+ running,
1263
+ scan,
1264
+ run
1265
+ };
1266
+ }
1267
+ //#endregion
1268
+ //#region src/App.vue
1269
+ const _sfc_main = /*@__PURE__*/ defineComponent({
1270
+ __name: "App",
1271
+ setup(__props, { expose: __expose }) {
1272
+ __expose();
1273
+ const { exit } = useApp();
1274
+ const config = loadConfig();
1275
+ const logs = ref([]);
1276
+ const { tunnels, start, stop, startAll, autoStart, cleanup } = useTunnels(config, logs);
1277
+ const { scripts, running, scan, run } = useDeploy(config, logs);
1278
+ const activePanel = ref("tunnels");
1279
+ const showConfig = ref(false);
1280
+ const paramModal = ref(null);
1281
+ const paramInput = ref("");
1282
+ function log(level, message) {
1283
+ logs.value.push({
1284
+ time: (/* @__PURE__ */ new Date()).toLocaleTimeString("zh-CN", { hour12: false }),
1285
+ level,
1286
+ message
1287
+ });
1288
+ }
1289
+ useInput((event) => {
1290
+ if (event.type !== "key") return;
1291
+ const name = event.key.name;
1292
+ if (showConfig.value) {
1293
+ if (name === "escape") {
1294
+ showConfig.value = false;
1295
+ saveConfig(config);
1296
+ log("info", "配置已保存");
1297
+ scan();
1298
+ }
1299
+ return;
1300
+ }
1301
+ if (paramModal.value) {
1302
+ if (name === "escape") {
1303
+ paramModal.value = null;
1304
+ return;
1305
+ }
1306
+ if (name === "enter") {
1307
+ const script = paramModal.value.script;
1308
+ const args = paramInput.value.trim().split(/\s+/).filter(Boolean);
1309
+ paramModal.value = null;
1310
+ paramInput.value = "";
1311
+ run(script, args);
1312
+ return;
1313
+ }
1314
+ if (name === "backspace") {
1315
+ paramInput.value = paramInput.value.slice(0, -1);
1316
+ return;
1317
+ }
1318
+ if (event.key.character) paramInput.value += event.key.character;
1319
+ return;
1320
+ }
1321
+ if (name === "tab") {
1322
+ const panels = [
1323
+ "tunnels",
1324
+ "deploy",
1325
+ "output"
1326
+ ];
1327
+ const idx = panels.indexOf(activePanel.value);
1328
+ activePanel.value = panels[(idx + 1) % panels.length];
1329
+ return;
1330
+ }
1331
+ if (name === "1") {
1332
+ activePanel.value = "tunnels";
1333
+ return;
1334
+ }
1335
+ if (name === "2") {
1336
+ activePanel.value = "deploy";
1337
+ return;
1338
+ }
1339
+ if (name === "3") {
1340
+ activePanel.value = "output";
1341
+ return;
1342
+ }
1343
+ if (name === "n") {
1344
+ showConfig.value = true;
1345
+ return;
1346
+ }
1347
+ if (name === "r") {
1348
+ scan();
1349
+ log("info", "已重新扫描");
1350
+ return;
1351
+ }
1352
+ if (name === "q" || name === "escape") {
1353
+ cleanup();
1354
+ exit();
1355
+ return;
1356
+ }
1357
+ });
1358
+ onMounted(async () => {
1359
+ log("info", "Deploy CLI 已启动");
1360
+ log("info", `配置: ${config.servers.length} 服务器, ${config.tunnels.length} 隧道, ${config.projects.length} 项目`);
1361
+ log("info", "按 [n] 添加配置, [r] 重新扫描, [p] 传参执行");
1362
+ scan();
1363
+ await autoStart();
1364
+ });
1365
+ onUnmounted(() => {
1366
+ cleanup();
1367
+ });
1368
+ function handleRun(script, _args) {
1369
+ run(script, []);
1370
+ }
1371
+ function handleRunWithParams(script) {
1372
+ paramModal.value = { script };
1373
+ paramInput.value = "";
1374
+ }
1375
+ function handleConfigChanged() {
1376
+ saveConfig(config);
1377
+ log("info", "配置已更新");
1378
+ scan();
1379
+ }
1380
+ const __returned__ = {
1381
+ exit,
1382
+ config,
1383
+ logs,
1384
+ tunnels,
1385
+ start,
1386
+ stop,
1387
+ startAll,
1388
+ autoStart,
1389
+ cleanup,
1390
+ scripts,
1391
+ running,
1392
+ scan,
1393
+ run,
1394
+ activePanel,
1395
+ showConfig,
1396
+ paramModal,
1397
+ paramInput,
1398
+ log,
1399
+ handleRun,
1400
+ handleRunWithParams,
1401
+ handleConfigChanged,
1402
+ get Box() {
1403
+ return Box;
1404
+ },
1405
+ get Text() {
1406
+ return Text;
1407
+ },
1408
+ TunnelPanel: TunnelPanel_default,
1409
+ DeployPanel: DeployPanel_default,
1410
+ OutputPanel: OutputPanel_default,
1411
+ StatusBar: StatusBar_default,
1412
+ ConfigPanel: ConfigPanel_default
1413
+ };
1414
+ Object.defineProperty(__returned__, "__isScriptSetup", {
1415
+ enumerable: false,
1416
+ value: true
1417
+ });
1418
+ return __returned__;
1419
+ }
1420
+ });
1421
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
1422
+ return openBlock(), createBlock($setup["Box"], {
1423
+ flexDirection: "column",
1424
+ flexGrow: 1
1425
+ }, {
1426
+ default: withCtx(() => [
1427
+ createCommentVNode(" 标题栏 "),
1428
+ createVNode($setup["Box"], {
1429
+ paddingX: 1,
1430
+ flexDirection: "row",
1431
+ justifyContent: "space-between",
1432
+ flexShrink: 0
1433
+ }, {
1434
+ default: withCtx(() => [createVNode($setup["Text"], {
1435
+ bold: "",
1436
+ color: "cyan"
1437
+ }, {
1438
+ default: withCtx(() => [..._cache[0] || (_cache[0] = [createTextVNode("Deploy CLI", -1)])]),
1439
+ _: 1
1440
+ }), createVNode($setup["Text"], { dimColor: "" }, {
1441
+ default: withCtx(() => [createTextVNode(toDisplayString($setup.config.servers.length) + " servers · " + toDisplayString($setup.config.projects.length) + " projects · [n]ew [r]escan", 1)]),
1442
+ _: 1
1443
+ })]),
1444
+ _: 1
1445
+ }),
1446
+ createCommentVNode(" 主区域:左面板 + 右输出 "),
1447
+ createVNode($setup["Box"], {
1448
+ flexDirection: "row",
1449
+ flexGrow: 1,
1450
+ gap: 1
1451
+ }, {
1452
+ default: withCtx(() => [
1453
+ createCommentVNode(" 左列:隧道 + 部署 "),
1454
+ createVNode($setup["Box"], {
1455
+ flexDirection: "column",
1456
+ flexGrow: 1,
1457
+ gap: 1
1458
+ }, {
1459
+ default: withCtx(() => [createVNode($setup["TunnelPanel"], {
1460
+ tunnels: $setup.tunnels,
1461
+ "is-active": $setup.activePanel === "tunnels" && !$setup.showConfig && !$setup.paramModal,
1462
+ onStart: $setup.start,
1463
+ onStop: $setup.stop,
1464
+ onStartAll: $setup.startAll
1465
+ }, null, 8, [
1466
+ "tunnels",
1467
+ "is-active",
1468
+ "onStart",
1469
+ "onStop",
1470
+ "onStartAll"
1471
+ ]), createVNode($setup["DeployPanel"], {
1472
+ scripts: $setup.scripts,
1473
+ "is-active": $setup.activePanel === "deploy" && !$setup.showConfig && !$setup.paramModal,
1474
+ running: $setup.running,
1475
+ onRun: $setup.handleRun,
1476
+ onRunWithParams: $setup.handleRunWithParams
1477
+ }, null, 8, [
1478
+ "scripts",
1479
+ "is-active",
1480
+ "running"
1481
+ ])]),
1482
+ _: 1
1483
+ }),
1484
+ createCommentVNode(" 右列:日志输出 "),
1485
+ createVNode($setup["OutputPanel"], {
1486
+ logs: $setup.logs,
1487
+ "is-active": $setup.activePanel === "output" && !$setup.showConfig && !$setup.paramModal
1488
+ }, null, 8, ["logs", "is-active"])
1489
+ ]),
1490
+ _: 1
1491
+ }),
1492
+ createCommentVNode(" 底部状态栏 "),
1493
+ createVNode($setup["StatusBar"], {
1494
+ "tunnel-count": $setup.tunnels.filter((t) => t.status === "running").length,
1495
+ focus: $setup.activePanel,
1496
+ "running-deploy": $setup.running
1497
+ }, null, 8, [
1498
+ "tunnel-count",
1499
+ "focus",
1500
+ "running-deploy"
1501
+ ]),
1502
+ createCommentVNode(" 配置面板 "),
1503
+ createVNode($setup["ConfigPanel"], {
1504
+ config: $setup.config,
1505
+ "is-active": $setup.showConfig,
1506
+ visible: $setup.showConfig,
1507
+ onConfigChanged: $setup.handleConfigChanged
1508
+ }, null, 8, [
1509
+ "config",
1510
+ "is-active",
1511
+ "visible"
1512
+ ]),
1513
+ createCommentVNode(" 传参弹窗 "),
1514
+ $setup.paramModal ? (openBlock(), createBlock($setup["Box"], {
1515
+ key: 0,
1516
+ flexDirection: "column",
1517
+ borderStyle: "round",
1518
+ borderColor: "cyan",
1519
+ padding: 1,
1520
+ width: 60,
1521
+ position: "absolute",
1522
+ top: 3,
1523
+ left: 3
1524
+ }, {
1525
+ default: withCtx(() => [
1526
+ createVNode($setup["Text"], {
1527
+ bold: "",
1528
+ color: "cyan"
1529
+ }, {
1530
+ default: withCtx(() => [createTextVNode("执行: " + toDisplayString($setup.paramModal.script.project) + "/" + toDisplayString($setup.paramModal.script.name), 1)]),
1531
+ _: 1
1532
+ }),
1533
+ createVNode($setup["Box"], {
1534
+ flexDirection: "row",
1535
+ marginTop: 1,
1536
+ gap: 1
1537
+ }, {
1538
+ default: withCtx(() => [createVNode($setup["Text"], { dimColor: "" }, {
1539
+ default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode("参数:", -1)])]),
1540
+ _: 1
1541
+ }), createVNode($setup["Text"], {
1542
+ bold: "",
1543
+ color: "cyan"
1544
+ }, {
1545
+ default: withCtx(() => [createTextVNode(toDisplayString($setup.paramInput) + "_", 1)]),
1546
+ _: 1
1547
+ })]),
1548
+ _: 1
1549
+ }),
1550
+ createVNode($setup["Box"], {
1551
+ flexDirection: "row",
1552
+ marginTop: 1
1553
+ }, {
1554
+ default: withCtx(() => [createVNode($setup["Text"], { dimColor: "" }, {
1555
+ default: withCtx(() => [..._cache[2] || (_cache[2] = [createTextVNode("[Enter] 执行 [Esc] 取消", -1)])]),
1556
+ _: 1
1557
+ })]),
1558
+ _: 1
1559
+ })
1560
+ ]),
1561
+ _: 1
1562
+ })) : createCommentVNode("v-if", true)
1563
+ ]),
1564
+ _: 1
1565
+ });
1566
+ }
1567
+ //#endregion
1568
+ //#region src/main.ts
1569
+ createApp(/* @__PURE__ */ export_helper_default(_sfc_main, [["render", _sfc_render], ["__file", "/Users/yangdongnan/work/deploy-cli/src/App.vue"]])).mount({ exitOnCtrlC: true });
1570
+ //#endregion
1571
+ export {};