@dongnanyang/deploy-cli 0.13.1 → 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 +149 -55
- 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/dist/config-xUl8Oa3T.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
2
|
-
import { homedir } from "os";
|
|
3
|
-
import { resolve } from "path";
|
|
4
|
-
//#region src/core/config.ts
|
|
5
|
-
const CONFIG_DIR = resolve(homedir(), ".deploy-cli");
|
|
6
|
-
const CONFIG_PATH = resolve(CONFIG_DIR, "config.json");
|
|
7
|
-
const DEFAULT_CONFIG = {
|
|
8
|
-
servers: [],
|
|
9
|
-
tunnels: [],
|
|
10
|
-
projects: []
|
|
11
|
-
};
|
|
12
|
-
/** 读取配置,不存在则创建默认配置;projects 缺 deployDir 时补默认值 'deploy'。
|
|
13
|
-
* 首建提示走可注入 log sink(M2-T2 #4),缺省仍打 console.log。 */
|
|
14
|
-
function loadConfig(log = (line) => console.log(line)) {
|
|
15
|
-
if (!existsSync(CONFIG_PATH)) {
|
|
16
|
-
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
17
|
-
saveConfig(DEFAULT_CONFIG);
|
|
18
|
-
log(`[config] 已创建默认配置: ${CONFIG_PATH}`);
|
|
19
|
-
return {
|
|
20
|
-
servers: [],
|
|
21
|
-
tunnels: [],
|
|
22
|
-
projects: []
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
const raw = readFileSync(CONFIG_PATH, "utf-8");
|
|
26
|
-
let parsed;
|
|
27
|
-
try {
|
|
28
|
-
parsed = JSON.parse(raw);
|
|
29
|
-
} catch (error) {
|
|
30
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
31
|
-
throw new Error(`配置文件损坏(JSON 解析失败): ${CONFIG_PATH}: ${reason}`);
|
|
32
|
-
}
|
|
33
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error(`配置文件损坏(应为 JSON 对象): ${CONFIG_PATH}`);
|
|
34
|
-
const config = parsed;
|
|
35
|
-
return {
|
|
36
|
-
servers: asArray(config.servers, "servers"),
|
|
37
|
-
tunnels: asArray(config.tunnels, "tunnels"),
|
|
38
|
-
projects: asArray(config.projects, "projects").map((project) => normalizeProject(project))
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
/** 字段缺省视为空数组;非数组抛配置错误(含路径),避免 TypeError 崩溃 */
|
|
42
|
-
function asArray(value, key) {
|
|
43
|
-
if (value === void 0 || value === null) return [];
|
|
44
|
-
if (!Array.isArray(value)) throw new Error(`配置文件损坏(${key} 应为数组): ${CONFIG_PATH}`);
|
|
45
|
-
return value;
|
|
46
|
-
}
|
|
47
|
-
/** 写入配置 */
|
|
48
|
-
function saveConfig(config) {
|
|
49
|
-
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
50
|
-
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
51
|
-
}
|
|
52
|
-
/** 展开 ~ 路径 */
|
|
53
|
-
function expandPath(p) {
|
|
54
|
-
if (p.startsWith("~/")) return resolve(homedir(), p.slice(2));
|
|
55
|
-
if (p === "~") return homedir();
|
|
56
|
-
return resolve(p);
|
|
57
|
-
}
|
|
58
|
-
/** 读入的项目元素缺 deployDir 时补默认值(配置文件可省略该字段) */
|
|
59
|
-
function normalizeProject(project) {
|
|
60
|
-
return {
|
|
61
|
-
...project,
|
|
62
|
-
deployDir: project.deployDir ?? "deploy"
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
//#endregion
|
|
66
|
-
export { loadConfig as n, saveConfig as r, expandPath as t };
|