@dongnanyang/deploy-cli 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -11
- package/dist/api.js +1 -1
- package/dist/bin.js +2 -6
- package/dist/{cli-DuwAYtpm.js → cli-ku0VmJk4.js} +3 -3
- package/dist/{deploy-DuQKdGV9.js → deploy-DV42j6GT.js} +1 -2
- package/dist/{project-BL00JHAo.js → project-BHmvb9Mf.js} +73 -12
- package/dist/tui/main.js +291 -118
- package/package.json +1 -1
- package/dist/config-xUl8Oa3T.js +0 -66
- package/dist/export-helper-CIEcxb5I.js +0 -8
- package/dist/main.js +0 -1504
package/README.md
CHANGED
|
@@ -14,6 +14,13 @@
|
|
|
14
14
|
- [ssh2](https://github.com/mscdex/ssh2) - SSH 客户端
|
|
15
15
|
- Vite HMR 开发 + tsdown 生产构建
|
|
16
16
|
|
|
17
|
+
## 安装
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm i -g @dongnanyang/deploy-cli
|
|
21
|
+
deploy-cli # 启动交互式 TUI
|
|
22
|
+
```
|
|
23
|
+
|
|
17
24
|
## 快速开始
|
|
18
25
|
|
|
19
26
|
```bash
|
|
@@ -59,15 +66,32 @@ npm start # 运行生产构建
|
|
|
59
66
|
}
|
|
60
67
|
```
|
|
61
68
|
|
|
62
|
-
##
|
|
69
|
+
## TUI 快捷键
|
|
70
|
+
|
|
71
|
+
| 面板 | 键 | 作用 |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| 全局 | `1`-`6` | 切换面板(Projects/Containers/Deploy/Status/Tunnels/Output) |
|
|
74
|
+
| 全局 | `?` | 打开/关闭快捷键帮助 |
|
|
75
|
+
| 全局 | `q` | 退出(停全部隧道) |
|
|
76
|
+
| Projects | `j`/`k` | 上下选择 |
|
|
77
|
+
| Projects | `n` | 新建项目(创建向导) |
|
|
78
|
+
| Projects | `d` | 部署选中项目 |
|
|
79
|
+
| Projects | `r` | 打开脚本浮层(该项目 `deploy/` 目录) |
|
|
80
|
+
| Projects | `f` | 刷新 |
|
|
81
|
+
| Containers | `j`/`k` | 上下选择 |
|
|
82
|
+
| Containers | `l` | 查看容器日志(跟随) |
|
|
83
|
+
| Containers | `r`/`s`/`x` | 重启/停止/删除(确认后执行,删除带 force) |
|
|
84
|
+
| Containers | `f` | 刷新 |
|
|
85
|
+
| Deploy | — | 只读步骤流(Projects 按 `d` 发起) |
|
|
86
|
+
| Status | `f` | 刷新 |
|
|
87
|
+
| Tunnels | `j`/`k` | 上下选择 |
|
|
88
|
+
| Tunnels | `s`/`a` | 启动选中/全部隧道 |
|
|
89
|
+
| Tunnels | `x` | 停止隧道(确认) |
|
|
90
|
+
| Output | `g`/`G` | 到顶/底 |
|
|
91
|
+
| Output | `↑`/`↓` | 逐行滚动 |
|
|
92
|
+
| 脚本浮层 | `Enter`/`p` | 执行(空参/传参,均需 `y` 确认) |
|
|
93
|
+
| 脚本浮层 | `f`/`Esc` | 重扫/返回 |
|
|
94
|
+
| 创建向导 | `Enter`/`c`/`Esc` | 前进/重检 compose/返回 |
|
|
95
|
+
| 确认弹窗 | `y`/`Enter`、`n`/`Esc` | 确认、取消(期间全局键停用) |
|
|
63
96
|
|
|
64
|
-
|
|
65
|
-
|---|---|
|
|
66
|
-
| `j`/`k` | 上下选择 |
|
|
67
|
-
| `s` | 启动隧道 |
|
|
68
|
-
| `x` | 停止隧道 |
|
|
69
|
-
| `a` | 启动全部隧道 |
|
|
70
|
-
| `Enter` | 执行部署脚本 |
|
|
71
|
-
| `Tab` | 切换面板焦点 |
|
|
72
|
-
| `1`/`2`/`3` | 跳转到 Tunnels/Deploy/Output |
|
|
73
|
-
| `q` | 退出 |
|
|
97
|
+
> 快捷键表与实现同源(`src/tui/composables/useKeymap.ts`),完整表见 TUI 内 `?` 帮助。
|
package/dist/api.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as generateCompose, c as loadProject, d as managedRoot, f as removeProject, h as PROJECT_LABEL, i as createManagedProject, m as COMPOSE_SERVICE_LABEL, n as ProjectConfigError, o as hasComposeMarker, p as saveProject, r as addProject, s as listProjects, t as COMPOSE_MARKER, u as managedDir } from "./project-
|
|
1
|
+
import { a as generateCompose, c as loadProject, d as managedRoot, f as removeProject, h as PROJECT_LABEL, i as createManagedProject, m as COMPOSE_SERVICE_LABEL, n as ProjectConfigError, o as hasComposeMarker, p as saveProject, r as addProject, s as listProjects, t as COMPOSE_MARKER, u as managedDir } from "./project-BHmvb9Mf.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
|
@@ -5,21 +5,17 @@ function resolveEntry(argv) {
|
|
|
5
5
|
case void 0:
|
|
6
6
|
case "tui":
|
|
7
7
|
case "--tui-next": return "tui";
|
|
8
|
-
case "--legacy-tui": return "legacy-tui";
|
|
9
8
|
default: return "cli";
|
|
10
9
|
}
|
|
11
10
|
}
|
|
12
|
-
/** 执行入口分发:TUI
|
|
11
|
+
/** 执行入口分发:TUI 挂载;cli 子命令返回退出码写入 process.exitCode */
|
|
13
12
|
async function runEntry(argv = process.argv.slice(2)) {
|
|
14
13
|
switch (resolveEntry(argv)) {
|
|
15
14
|
case "tui":
|
|
16
15
|
await import("./tui/main.js");
|
|
17
16
|
break;
|
|
18
|
-
case "legacy-tui":
|
|
19
|
-
await import("./main.js");
|
|
20
|
-
break;
|
|
21
17
|
case "cli": {
|
|
22
|
-
const cli = await import("./cli-
|
|
18
|
+
const cli = await import("./cli-ku0VmJk4.js");
|
|
23
19
|
process.exitCode = await cli.main(argv);
|
|
24
20
|
break;
|
|
25
21
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { c as createDocker, l as logsArgs, o as checkProjectHealth, r as runDeploy, s as findProjectContainers, t as buildSpec } from "./deploy-DuQKdGV9.js";
|
|
1
|
+
import { E as run, S as createNginx, T as execFailureMessage, _ as loadConfig, b as acmeProbeCommand, c as loadProject, f as removeProject, g as expandPath, r as addProject, s as listProjects, v as saveConfig, w as resolveNginxPaths, x as certbotProbeCommand, y as ACME_BIN } from "./project-BHmvb9Mf.js";
|
|
2
|
+
import { c as createDocker, l as logsArgs, o as checkProjectHealth, r as runDeploy, s as findProjectContainers, t as buildSpec } from "./deploy-DV42j6GT.js";
|
|
4
3
|
import { accessSync, constants, existsSync, readFileSync } from "node:fs";
|
|
5
4
|
import { dirname, join } from "node:path";
|
|
6
5
|
import { fileURLToPath } from "node:url";
|
|
@@ -596,6 +595,7 @@ async function status(args, options = {}) {
|
|
|
596
595
|
const USAGE = `用法:
|
|
597
596
|
deploy-cli 启动交互式 TUI
|
|
598
597
|
deploy-cli tui 启动交互式 TUI
|
|
598
|
+
deploy-cli --tui-next 启动交互式 TUI(预览开关别名,与缺省同义)
|
|
599
599
|
deploy-cli doctor 环境自检
|
|
600
600
|
deploy-cli ps 列出容器(--help 看示例)
|
|
601
601
|
deploy-cli logs 查看容器日志(--help 看示例)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as expandPath } from "./config-xUl8Oa3T.js";
|
|
1
|
+
import { E as run, S as createNginx, T as execFailureMessage, a as generateCompose, g as expandPath, h as PROJECT_LABEL, m as COMPOSE_SERVICE_LABEL, o as hasComposeMarker, t as COMPOSE_MARKER } from "./project-BHmvb9Mf.js";
|
|
3
2
|
import { existsSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
4
3
|
import { dirname, join, resolve } from "node:path";
|
|
5
4
|
import { spawn } from "node:child_process";
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { n as loadConfig, r as saveConfig } from "./config-xUl8Oa3T.js";
|
|
2
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
3
2
|
import { homedir } from "os";
|
|
4
3
|
import { resolve } from "path";
|
|
5
4
|
import { parse, stringify } from "yaml";
|
|
6
|
-
import { existsSync as existsSync$1, lstatSync, readdirSync
|
|
7
|
-
import { join
|
|
5
|
+
import { existsSync as existsSync$1, lstatSync, readdirSync, renameSync, symlinkSync, unlinkSync, writeFileSync as writeFileSync$1 } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
8
7
|
import { execFileSync, spawn } from "node:child_process";
|
|
9
8
|
//#region src/core/exec.ts
|
|
10
9
|
/**
|
|
@@ -319,10 +318,10 @@ function createNginx(runner = run, paths) {
|
|
|
319
318
|
* 写盘段(写 .new/改名/软链)与 nginx -t 同一回滚口径(M2-T2 #8):段内任一 fs 操作失败即整体恢复再抛出。
|
|
320
319
|
*/
|
|
321
320
|
async function writeSite(slug, content) {
|
|
322
|
-
const conf = join
|
|
323
|
-
const tmp = join
|
|
324
|
-
const bak = join
|
|
325
|
-
const link = sitesEnabled ? join
|
|
321
|
+
const conf = join(sitesAvailable, confName(slug));
|
|
322
|
+
const tmp = join(sitesAvailable, tmpName(slug));
|
|
323
|
+
const bak = join(sitesAvailable, bakName(slug));
|
|
324
|
+
const link = sitesEnabled ? join(sitesEnabled, confName(slug)) : void 0;
|
|
326
325
|
const existed = pathExists(conf);
|
|
327
326
|
const linkCreated = link ? !pathExists(link) : false;
|
|
328
327
|
/** 统一回滚:恢复/清除 conf、软链、.new 临时文件(R13:逐项守护,单项失败记 stderr 继续,回滚不抛) */
|
|
@@ -448,10 +447,10 @@ function createNginx(runner = run, paths) {
|
|
|
448
447
|
},
|
|
449
448
|
async removeSite(slug) {
|
|
450
449
|
validateSlug(slug);
|
|
451
|
-
const conf = join
|
|
450
|
+
const conf = join(sitesAvailable, confName(slug));
|
|
452
451
|
if (!pathExists(conf)) throw new Error(`未找到站点配置: ${conf}`);
|
|
453
|
-
const bak = join
|
|
454
|
-
const link = sitesEnabled ? join
|
|
452
|
+
const bak = join(sitesAvailable, bakName(slug));
|
|
453
|
+
const link = sitesEnabled ? join(sitesEnabled, confName(slug)) : void 0;
|
|
455
454
|
const hadLink = link ? pathExists(link) : false;
|
|
456
455
|
/**
|
|
457
456
|
* 与 applySite 同等回滚对等(R2)+ 写盘段同款收口(R13):逐项守护(单项失败记 stderr 继续恢复其余项),
|
|
@@ -497,12 +496,74 @@ function createNginx(runner = run, paths) {
|
|
|
497
496
|
unlinkSync(bak);
|
|
498
497
|
},
|
|
499
498
|
async listSites() {
|
|
500
|
-
return readdirSync
|
|
499
|
+
return readdirSync(sitesAvailable).filter((name) => name.startsWith(CONF_PREFIX) && name.endsWith(CONF_SUFFIX)).map((name) => name.slice(11, -5)).filter((slug) => SLUG_RE.test(slug)).sort();
|
|
501
500
|
},
|
|
502
501
|
requestCert
|
|
503
502
|
};
|
|
504
503
|
}
|
|
505
504
|
//#endregion
|
|
505
|
+
//#region src/core/config.ts
|
|
506
|
+
const CONFIG_DIR = resolve(homedir(), ".deploy-cli");
|
|
507
|
+
const CONFIG_PATH = resolve(CONFIG_DIR, "config.json");
|
|
508
|
+
const DEFAULT_CONFIG = {
|
|
509
|
+
servers: [],
|
|
510
|
+
tunnels: [],
|
|
511
|
+
projects: []
|
|
512
|
+
};
|
|
513
|
+
/** 读取配置,不存在则创建默认配置;projects 缺 deployDir 时补默认值 'deploy'。
|
|
514
|
+
* 首建提示走可注入 log sink(M2-T2 #4),缺省仍打 console.log。 */
|
|
515
|
+
function loadConfig(log = (line) => console.log(line)) {
|
|
516
|
+
if (!existsSync(CONFIG_PATH)) {
|
|
517
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
518
|
+
saveConfig(DEFAULT_CONFIG);
|
|
519
|
+
log(`[config] 已创建默认配置: ${CONFIG_PATH}`);
|
|
520
|
+
return {
|
|
521
|
+
servers: [],
|
|
522
|
+
tunnels: [],
|
|
523
|
+
projects: []
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
const raw = readFileSync(CONFIG_PATH, "utf-8");
|
|
527
|
+
let parsed;
|
|
528
|
+
try {
|
|
529
|
+
parsed = JSON.parse(raw);
|
|
530
|
+
} catch (error) {
|
|
531
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
532
|
+
throw new Error(`配置文件损坏(JSON 解析失败): ${CONFIG_PATH}: ${reason}`);
|
|
533
|
+
}
|
|
534
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error(`配置文件损坏(应为 JSON 对象): ${CONFIG_PATH}`);
|
|
535
|
+
const config = parsed;
|
|
536
|
+
return {
|
|
537
|
+
servers: asArray(config.servers, "servers"),
|
|
538
|
+
tunnels: asArray(config.tunnels, "tunnels"),
|
|
539
|
+
projects: asArray(config.projects, "projects").map((project) => normalizeProject(project))
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
/** 字段缺省视为空数组;非数组抛配置错误(含路径),避免 TypeError 崩溃 */
|
|
543
|
+
function asArray(value, key) {
|
|
544
|
+
if (value === void 0 || value === null) return [];
|
|
545
|
+
if (!Array.isArray(value)) throw new Error(`配置文件损坏(${key} 应为数组): ${CONFIG_PATH}`);
|
|
546
|
+
return value;
|
|
547
|
+
}
|
|
548
|
+
/** 写入配置 */
|
|
549
|
+
function saveConfig(config) {
|
|
550
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
551
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
552
|
+
}
|
|
553
|
+
/** 展开 ~ 路径 */
|
|
554
|
+
function expandPath(p) {
|
|
555
|
+
if (p.startsWith("~/")) return resolve(homedir(), p.slice(2));
|
|
556
|
+
if (p === "~") return homedir();
|
|
557
|
+
return resolve(p);
|
|
558
|
+
}
|
|
559
|
+
/** 读入的项目元素缺 deployDir 时补默认值(配置文件可省略该字段) */
|
|
560
|
+
function normalizeProject(project) {
|
|
561
|
+
return {
|
|
562
|
+
...project,
|
|
563
|
+
deployDir: project.deployDir ?? "deploy"
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
//#endregion
|
|
506
567
|
//#region src/core/types.ts
|
|
507
568
|
/** 容器归属 label 键(M2-T3):generateCompose 写入 compose 服务级 labels,归属判定优先匹配,无 label 回退精确名后过滤 */
|
|
508
569
|
const PROJECT_LABEL = "deploy-cli.project";
|
|
@@ -719,4 +780,4 @@ function createManagedProject(input) {
|
|
|
719
780
|
};
|
|
720
781
|
}
|
|
721
782
|
//#endregion
|
|
722
|
-
export {
|
|
783
|
+
export { isValidSlug as C, run as E, createNginx as S, execFailureMessage as T, loadConfig as _, generateCompose as a, acmeProbeCommand as b, loadProject as c, managedRoot as d, removeProject as f, expandPath as g, PROJECT_LABEL as h, createManagedProject as i, managedComposeExists as l, COMPOSE_SERVICE_LABEL as m, ProjectConfigError as n, hasComposeMarker as o, saveProject as p, addProject as r, listProjects as s, COMPOSE_MARKER as t, managedDir as u, saveConfig as v, resolveNginxPaths as w, certbotProbeCommand as x, ACME_BIN as y };
|