@asiainfo-sdd/multica-cli 0.2.0 → 0.2.1
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/lib/install.js +3 -3
- package/lib/server-config.js +18 -10
- package/package.json +1 -1
package/lib/install.js
CHANGED
|
@@ -151,7 +151,7 @@ function hintRunRebuild() {
|
|
|
151
151
|
log(' 修复方式:稍后执行 npm rebuild @asiainfo-sdd/multica-cli');
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
// 把部署级配置(server_url/app_url)
|
|
154
|
+
// 把部署级配置(server_url/app_url)写入 ~/.multica/config.json(覆盖式)。
|
|
155
155
|
// manifest 失败时传 null,退回 env > 包内置默认值。
|
|
156
156
|
function applyServerConfigSafe(manifest) {
|
|
157
157
|
let result;
|
|
@@ -165,8 +165,8 @@ function applyServerConfigSafe(manifest) {
|
|
|
165
165
|
for (const { key, value } of result.written) {
|
|
166
166
|
log(`✓ 已写入 ${key} = ${value}(${require('./server-config').multicaConfigPath()})`);
|
|
167
167
|
}
|
|
168
|
-
for (const { key,
|
|
169
|
-
log(
|
|
168
|
+
for (const { key, from, to } of result.updated) {
|
|
169
|
+
log(`✓ 已更新 ${key}:${from} → ${to}(环境切换;token 需重新登录生成)`);
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
|
package/lib/server-config.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// 安装时把部署级配置(server_url/app_url)
|
|
3
|
+
// 安装时把部署级配置(server_url/app_url)写入 ~/.multica/config.json,
|
|
4
4
|
// 免去用户手工 multica config set。规则:
|
|
5
5
|
// - 取值优先级: MULTICA_SERVER_URL/MULTICA_APP_URL env > manifest 顶层
|
|
6
6
|
// server_url/app_url(运维可不重发 npm 包直接改) > lib/dist-config.json
|
|
7
|
-
// -
|
|
7
|
+
// - server_url/app_url 两个部署级 URL【覆盖式】更新: 与本次安装源不一致时
|
|
8
|
+
// 直接覆盖并打印 新值 ← 旧值(升级环境后旧地址上的 token 验证/daemon 连接
|
|
9
|
+
// 必然失败,覆盖是唯一正确动作;自定义地址用户可从日志看到旧值并改回)
|
|
10
|
+
// - 其余字段(token/workspace_id/各超时/backends 等)一律不动
|
|
8
11
|
// - 目标文件是 multica CLI 的标准配置(daemon 只认这里的 token),
|
|
9
12
|
// 多 profile 场景(--profile)不在此处理,留给用户手动 config set
|
|
10
13
|
// token 属于个人凭据,始终由用户自行 multica login --token 写入。
|
|
@@ -51,8 +54,9 @@ function resolveDesired(manifest) {
|
|
|
51
54
|
return desired;
|
|
52
55
|
}
|
|
53
56
|
|
|
54
|
-
// 返回 {written: [{key, value}],
|
|
57
|
+
// 返回 {written: [{key, value}], updated: [{key, from, to}]} 供上层打印;
|
|
55
58
|
// 无可写内容或文件损坏时返回 null(不产生任何变更)。
|
|
59
|
+
// written = 原来为空、本次填入;updated = 原有不同值、本次覆盖。
|
|
56
60
|
function applyServerConfig(manifest) {
|
|
57
61
|
const desired = resolveDesired(manifest);
|
|
58
62
|
if (!desired.server_url && !desired.app_url) return null;
|
|
@@ -67,24 +71,28 @@ function applyServerConfig(manifest) {
|
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
const written = [];
|
|
70
|
-
const
|
|
74
|
+
const updated = [];
|
|
75
|
+
let changed = false;
|
|
71
76
|
for (const key of CONFIG_KEYS) {
|
|
72
77
|
if (!desired[key]) continue;
|
|
73
|
-
if (userConfig[key]
|
|
74
|
-
kept.push({ key, existing: userConfig[key] });
|
|
75
|
-
} else if (!userConfig[key]) {
|
|
78
|
+
if (!userConfig[key]) {
|
|
76
79
|
userConfig[key] = desired[key];
|
|
77
80
|
written.push({ key, value: desired[key] });
|
|
81
|
+
changed = true;
|
|
82
|
+
} else if (userConfig[key] !== desired[key]) {
|
|
83
|
+
updated.push({ key, from: userConfig[key], to: desired[key] });
|
|
84
|
+
userConfig[key] = desired[key];
|
|
85
|
+
changed = true;
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
88
|
|
|
81
|
-
if (
|
|
89
|
+
if (!changed) return { written, updated };
|
|
82
90
|
|
|
83
91
|
const file = multicaConfigPath();
|
|
84
92
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
85
|
-
//
|
|
93
|
+
// 保留用户已有其余字段,仅更新部署级键;不写 token。
|
|
86
94
|
fs.writeFileSync(file, JSON.stringify(userConfig, null, 2) + '\n');
|
|
87
|
-
return { written,
|
|
95
|
+
return { written, updated };
|
|
88
96
|
}
|
|
89
97
|
|
|
90
98
|
function logWarn(msg) {
|