@wkgeo/cli 0.0.0-stage → 1.0.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/CHANGELOG.md +208 -0
- package/LICENSE +21 -0
- package/README.md +1042 -3
- package/SKILL.md +927 -0
- package/lib/ai/client.mjs +161 -0
- package/lib/ai/config.mjs +221 -0
- package/lib/ai/context.mjs +468 -0
- package/lib/ai/log.mjs +53 -0
- package/lib/api.mjs +339 -0
- package/lib/args.mjs +235 -0
- package/lib/cli.mjs +168 -0
- package/lib/cms.mjs +330 -0
- package/lib/commands/ai.mjs +392 -0
- package/lib/commands/apps.mjs +116 -0
- package/lib/commands/auth.mjs +1288 -0
- package/lib/commands/billing.mjs +666 -0
- package/lib/commands/cms.mjs +2533 -0
- package/lib/commands/config-auth.mjs +621 -0
- package/lib/commands/config.mjs +434 -0
- package/lib/commands/dnscred.mjs +428 -0
- package/lib/commands/domainops.mjs +546 -0
- package/lib/commands/domainorder.mjs +439 -0
- package/lib/commands/import.mjs +164 -0
- package/lib/commands/index.mjs +528 -0
- package/lib/commands/logs.mjs +141 -0
- package/lib/commands/orders.mjs +444 -0
- package/lib/commands/overview.mjs +394 -0
- package/lib/commands/plugins.mjs +678 -0
- package/lib/commands/site.mjs +435 -0
- package/lib/commands/siteops.mjs +1012 -0
- package/lib/commands/sites.mjs +905 -0
- package/lib/commands/skill.mjs +119 -0
- package/lib/config.mjs +351 -0
- package/lib/credentials.mjs +160 -0
- package/lib/device-store.mjs +132 -0
- package/lib/device.mjs +464 -0
- package/lib/errors.mjs +299 -0
- package/lib/format.mjs +339 -0
- package/lib/http.mjs +71 -0
- package/lib/index.mjs +44 -0
- package/lib/local-import.mjs +185 -0
- package/lib/login.mjs +1638 -0
- package/lib/oauth-urls.mjs +163 -0
- package/lib/page.mjs +393 -0
- package/lib/pkce.mjs +48 -0
- package/lib/proxy.mjs +454 -0
- package/lib/qr.mjs +31 -0
- package/lib/runtime.mjs +650 -0
- package/lib/site-state.mjs +137 -0
- package/package.json +53 -4
- package/wkgeo.mjs +17 -0
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 插件类命令(B5 / task-91):插件开关 / 配置 / 市场安装卸载升级 / 演示链接。
|
|
3
|
+
*
|
|
4
|
+
* ## 这一层是什么
|
|
5
|
+
* task-91(2026-10-29)把 CMS `actionTable` 里的插件类动作搬进 CLI 自己的云函数
|
|
6
|
+
* `wkgeo-cli-fc`(`src/plugin-core.js`,逐字复制 CMS handler + 本地归属闸)。
|
|
7
|
+
* 因此这里的**动作名 = 服务端动作名**(`pluginList` / `pluginToggle` /
|
|
8
|
+
* `cmsPluginMarketList` / `pluginMarketInstall` …),参数名也照抄 CMS 后端。
|
|
9
|
+
*
|
|
10
|
+
* ## 三条口径(与 B1 内容面 / B3 发布面 / B4 站点面完全一致)
|
|
11
|
+
* 1. **站点必须先定**:`--site` > `WKONGAI_SITE` > `wkgeo site use` 记住的那个;
|
|
12
|
+
* 一个都没有就当场报用法错误(`pluginCall` 统一挡,不多跑一次往返)。
|
|
13
|
+
* 2. **写动作默认 dry-run**:不加 `--confirm` 只打印"将要发什么",一个写请求都不发。
|
|
14
|
+
* 写类 5 条:`toggle` / `settings` / `install` / `uninstall` / `upgrade`。
|
|
15
|
+
* 3. **默认人类可读,`--json` 给原始数据**(信封由 `runtime.done()` 统一包)。
|
|
16
|
+
*
|
|
17
|
+
* ## 权限面
|
|
18
|
+
* * 读(`plugins list` / `access` / `market-list` / `demo`)⇒ `site:read`
|
|
19
|
+
* * 写(`toggle` / `settings` / `install` / `uninstall` / `upgrade`)⇒ `site:write`
|
|
20
|
+
* * **服务端还会校验站点归属**:不是自己名下站一律 403 `not_site_owner`
|
|
21
|
+
* (站不存在 / 已删除回 404,两者不区分、不带站名与人名,不泄露额外信息)
|
|
22
|
+
*
|
|
23
|
+
* ## 别在这里做的事
|
|
24
|
+
* * ❌ 不走 `/cms` 转发面(B5 起这 9 条都改走 `/cli` 自持通道)
|
|
25
|
+
* * ❌ 不在 CLI 侧拼 `site_id`:`pluginCall` 会塞 body.siteId,服务端只用自己判定的值
|
|
26
|
+
* * ❌ 不替用户下载 / 校验演示外链:`plugins demo` 只把**库里登记的** `demo_url`
|
|
27
|
+
* 原样打出来(服务端也不发外呼),能不能打开是浏览器的事
|
|
28
|
+
* * ❌ 不读插件自己的表(`plug_<key>_*`):安装建表 / 配置归一化都在插件网关那一侧
|
|
29
|
+
* (服务端 `callPluginAction` 转发),CLI 不复制一行业务逻辑
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { UsageError } from '../errors.mjs';
|
|
33
|
+
|
|
34
|
+
/* ------------------------------------------------------------------ 公共小工具 */
|
|
35
|
+
|
|
36
|
+
/** 所有插件类命令共用的 `--site`(默认取 `wkgeo site use` 选中的站点) */
|
|
37
|
+
const SITE_FLAG = {
|
|
38
|
+
site: {
|
|
39
|
+
type: 'string',
|
|
40
|
+
desc: '站点 ID(uuid;默认用 `wkgeo site use` 选中的站点,可用 WKONGAI_SITE 覆盖)',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** 写动作的确认闸:不加就 dry-run */
|
|
45
|
+
const CONFIRM_FLAG = {
|
|
46
|
+
confirm: {
|
|
47
|
+
type: 'boolean',
|
|
48
|
+
desc: '真发(不加只打印将要发什么,一个写请求都不发)',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
function siteIdOf(ctx) {
|
|
53
|
+
const site = ctx.cmsSite();
|
|
54
|
+
return (site && site.id) || '';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function siteText(ctx) {
|
|
58
|
+
const site = ctx.cmsSite();
|
|
59
|
+
if (!site || !site.id) return '(未选站)';
|
|
60
|
+
return site.label ? `${site.label}(${site.id})` : String(site.id);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function rowsOf(data) {
|
|
64
|
+
if (Array.isArray(data)) return data;
|
|
65
|
+
if (data && Array.isArray(data.rows)) return data.rows;
|
|
66
|
+
if (data && Array.isArray(data.plugins)) return data.plugins;
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* dry-run:把"将要发什么"打印出来就**结束**(不发请求、退出码 0)。
|
|
72
|
+
*
|
|
73
|
+
* `request` 也进 `--json`:agent 拿 dry-run 结果做二次确认时要能核对
|
|
74
|
+
* "我要发的就是这些",光有人类文案不够机器读。
|
|
75
|
+
*/
|
|
76
|
+
function dryRun(ctx, action, request, lines) {
|
|
77
|
+
const data = {
|
|
78
|
+
dry_run: true,
|
|
79
|
+
action,
|
|
80
|
+
site_id: siteIdOf(ctx),
|
|
81
|
+
request,
|
|
82
|
+
confirm_hint: '确认无误后加 --confirm 真发',
|
|
83
|
+
};
|
|
84
|
+
const { out } = ctx;
|
|
85
|
+
if (!out.json) {
|
|
86
|
+
out.head(`dry-run:${action}(没有发送任何写请求)`);
|
|
87
|
+
out.line(` 站点:${siteText(ctx)}`);
|
|
88
|
+
for (const l of lines || []) out.line(` ${l}`);
|
|
89
|
+
out.line('');
|
|
90
|
+
out.line(' 确认无误后加 --confirm 真发。');
|
|
91
|
+
}
|
|
92
|
+
ctx.done(data);
|
|
93
|
+
return data;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** 服务端动作名(同时用于 dry-run 回执里的 `action`) */
|
|
97
|
+
const ACTION = {
|
|
98
|
+
pluginList: 'pluginList',
|
|
99
|
+
cmsPluginAccessList: 'cmsPluginAccessList',
|
|
100
|
+
pluginToggle: 'pluginToggle',
|
|
101
|
+
pluginSettingsSave: 'pluginSettingsSave',
|
|
102
|
+
cmsPluginMarketList: 'cmsPluginMarketList',
|
|
103
|
+
pluginMarketInstall: 'pluginMarketInstall',
|
|
104
|
+
pluginMarketUninstall: 'pluginMarketUninstall',
|
|
105
|
+
pluginMarketUpgrade: 'pluginMarketUpgrade',
|
|
106
|
+
pluginMarketDemo: 'pluginMarketDemo',
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const PLUGIN_CATEGORY_LABEL = {
|
|
110
|
+
content: '内容',
|
|
111
|
+
member: '会员',
|
|
112
|
+
shop: '商城',
|
|
113
|
+
marketing: '营销',
|
|
114
|
+
tool: '工具',
|
|
115
|
+
api: '接口',
|
|
116
|
+
system: '系统',
|
|
117
|
+
editor: '编辑器',
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/** 取必填的 `--key`(缺了当场报用法错误,别等服务端 400) */
|
|
121
|
+
function requireKey(ctx, what) {
|
|
122
|
+
const key = String(ctx.flags.key || '').trim();
|
|
123
|
+
if (!key) {
|
|
124
|
+
throw new UsageError(`${what}要指定 --key <插件key>`, {
|
|
125
|
+
hint: '插件 key 见 `wkgeo plugins list` 的第一列(也可 `wkgeo plugins market-list`)',
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return key;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* ══════════════════════════════ 本站插件(list / access) ══════════════════════════════ */
|
|
132
|
+
|
|
133
|
+
export const pluginsListCommand = {
|
|
134
|
+
name: 'plugins list',
|
|
135
|
+
summary: '列本站插件(启用状态、分类、互斥提示;只读)',
|
|
136
|
+
usage: 'wkgeo plugins list [--site <站点ID>] [--json]',
|
|
137
|
+
args: [],
|
|
138
|
+
flags: { ...SITE_FLAG },
|
|
139
|
+
examples: ['wkgeo plugins list', 'wkgeo plugins list --json'],
|
|
140
|
+
notes: [
|
|
141
|
+
'需要 `site:read`(只读)。',
|
|
142
|
+
'`editor`(编辑器)分类是**单选互斥**:启用一个会自动停用同分类其它插件,回包里会告诉你停了谁。',
|
|
143
|
+
'只列"适用于 CMS 后台"的插件;`installed=false` 表示本站还没装过(`plugins toggle` 会自动建行)。',
|
|
144
|
+
'`locked_by` 非空 = 该插件被本站启用中的模板依赖,不能关(模板换了才解锁)。',
|
|
145
|
+
],
|
|
146
|
+
async run(ctx) {
|
|
147
|
+
const { out } = ctx;
|
|
148
|
+
const data = (await ctx.pluginCall(ACTION.pluginList)) || {};
|
|
149
|
+
const plugins = rowsOf(data);
|
|
150
|
+
|
|
151
|
+
const enabledEditor = plugins.filter((p) => p.category === 'editor' && p.enabled);
|
|
152
|
+
const payload = {
|
|
153
|
+
site_id: siteIdOf(ctx),
|
|
154
|
+
total: plugins.length,
|
|
155
|
+
enabled: plugins.filter((p) => p.enabled).map((p) => p.key),
|
|
156
|
+
editor_enabled: enabledEditor.map((p) => p.key),
|
|
157
|
+
plugins: plugins.map((p) => ({
|
|
158
|
+
key: p.key,
|
|
159
|
+
name: p.name,
|
|
160
|
+
enabled: p.enabled === true,
|
|
161
|
+
installed: p.installed === true,
|
|
162
|
+
category: p.category || 'tool',
|
|
163
|
+
version: p.version || '',
|
|
164
|
+
capability: p.capability === true,
|
|
165
|
+
entry: p.entry || (p.ui && p.ui.entry) || '',
|
|
166
|
+
has_settings: p.hasSettings === true,
|
|
167
|
+
locked_by: p.lockedBy || null,
|
|
168
|
+
summary: p.summary || '',
|
|
169
|
+
})),
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
if (!out.json) {
|
|
173
|
+
out.head(`插件(站点 ${siteText(ctx)})`);
|
|
174
|
+
out.table(
|
|
175
|
+
[
|
|
176
|
+
{ title: '状态', key: 'state', width: 6 },
|
|
177
|
+
{ title: '插件', key: 'key', width: 26 },
|
|
178
|
+
{ title: '名称', key: 'name', width: 18 },
|
|
179
|
+
{ title: '分类', key: 'category', width: 10 },
|
|
180
|
+
{ title: '装过', key: 'installed', width: 6 },
|
|
181
|
+
],
|
|
182
|
+
payload.plugins.map((p) => ({
|
|
183
|
+
state: p.enabled ? '启用' : '停用',
|
|
184
|
+
key: p.key + (p.locked_by ? '(模板锁)' : ''),
|
|
185
|
+
name: p.name,
|
|
186
|
+
category: PLUGIN_CATEGORY_LABEL[p.category] || p.category,
|
|
187
|
+
installed: p.installed ? '是' : '否',
|
|
188
|
+
})),
|
|
189
|
+
);
|
|
190
|
+
if (enabledEditor.length > 1) {
|
|
191
|
+
out.warn(`editor 分类异常:同时启用了 ${enabledEditor.map((p) => p.key).join('、')}(应当只有一个)`);
|
|
192
|
+
} else if (enabledEditor.length === 1) {
|
|
193
|
+
out.info(`编辑器:${enabledEditor[0].key}(editor 分类单选,换一个会自动停用其它的)`);
|
|
194
|
+
}
|
|
195
|
+
const offEditors = plugins.filter((p) => p.category === 'editor' && !p.enabled).map((p) => p.key);
|
|
196
|
+
if (offEditors.length) out.info(`已停用:${offEditors.join('、')}`);
|
|
197
|
+
out.info('开关:`wkgeo plugins toggle --key <插件> --enable --confirm` / `--disable --confirm`');
|
|
198
|
+
}
|
|
199
|
+
ctx.done(payload);
|
|
200
|
+
return payload;
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export const pluginsAccessCommand = {
|
|
205
|
+
name: 'plugins access',
|
|
206
|
+
summary: '看一个插件的访问范围(按角色 / 按用户放行;只读)',
|
|
207
|
+
usage: 'wkgeo plugins access [--key <插件key>] [--site <站点ID>] [--json]',
|
|
208
|
+
args: [],
|
|
209
|
+
flags: {
|
|
210
|
+
key: { type: 'string', desc: '插件 key(不写 = 本站所有插件的访问行)' },
|
|
211
|
+
...SITE_FLAG,
|
|
212
|
+
},
|
|
213
|
+
examples: [
|
|
214
|
+
'wkgeo plugins access',
|
|
215
|
+
'wkgeo plugins access --key member',
|
|
216
|
+
'wkgeo plugins access --key member --json',
|
|
217
|
+
],
|
|
218
|
+
notes: [
|
|
219
|
+
'需要 `site:read`(只读)。',
|
|
220
|
+
'`available:false` = 本站还没有 `plugin_access` 表(迁移没跑),不是错误 —— 此时按"默认全站可见"理解。',
|
|
221
|
+
'只列可用的行(`revoked_at` 为空等);`total` 是过滤后的条数。',
|
|
222
|
+
],
|
|
223
|
+
async run(ctx) {
|
|
224
|
+
const { out } = ctx;
|
|
225
|
+
const key = String(ctx.flags.key || '').trim();
|
|
226
|
+
const body = key ? { plugin_key: key } : {};
|
|
227
|
+
const res = (await ctx.pluginCall(ACTION.cmsPluginAccessList, body)) || {};
|
|
228
|
+
const rows = rowsOf(res);
|
|
229
|
+
const data = {
|
|
230
|
+
site_id: siteIdOf(ctx),
|
|
231
|
+
plugin_key: res.plugin_key || key || null,
|
|
232
|
+
total: Number(res.total || rows.length),
|
|
233
|
+
available: res.available !== false,
|
|
234
|
+
rows: rows.map((one) => ({
|
|
235
|
+
subject_type: String((one && one.subject_type) || ''),
|
|
236
|
+
subject: String((one && one.subject) || ''),
|
|
237
|
+
allowed: one && one.allowed !== false,
|
|
238
|
+
reason: String((one && one.reason) || ''),
|
|
239
|
+
})),
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
if (!out.json) {
|
|
243
|
+
out.head(`插件访问范围(站点 ${siteText(ctx)}${data.plugin_key ? ` · ${data.plugin_key}` : ''})`);
|
|
244
|
+
if (!data.available) {
|
|
245
|
+
out.info('本站还没有 plugin_access 表:当前按"全站可见"理解(迁移跑完后再看这张清单)');
|
|
246
|
+
} else if (!data.rows.length) {
|
|
247
|
+
out.line(' (没有登记任何按角色 / 按用户的放行行 = 没人被单独限制)');
|
|
248
|
+
} else {
|
|
249
|
+
out.table(
|
|
250
|
+
[
|
|
251
|
+
{ title: '类型', key: 'subject_type', width: 8 },
|
|
252
|
+
{ title: '对象', key: 'subject', width: 28 },
|
|
253
|
+
{ title: '允许', key: 'allowed', width: 6 },
|
|
254
|
+
{ title: '原因', key: 'reason', width: 24 },
|
|
255
|
+
],
|
|
256
|
+
data.rows.map((one) => ({ ...one, allowed: one.allowed ? '是' : '否' })),
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
out.line(` 合计 ${data.total} 行`);
|
|
260
|
+
}
|
|
261
|
+
ctx.done(data);
|
|
262
|
+
return data;
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
/* ══════════════════════════════ 开关(toggle) ══════════════════════════════ */
|
|
267
|
+
|
|
268
|
+
export const pluginsToggleCommand = {
|
|
269
|
+
name: 'plugins toggle',
|
|
270
|
+
summary: '开关一个插件(editor 分类单选:启用一个会自动停用同分类其它;默认 dry-run)',
|
|
271
|
+
usage: 'wkgeo plugins toggle --key <插件key> (--enable|--disable) [--confirm] [--site <站点ID>]',
|
|
272
|
+
args: [],
|
|
273
|
+
flags: {
|
|
274
|
+
key: { type: 'string', required: true, desc: '插件 key(`wkgeo plugins list` 里的那列)' },
|
|
275
|
+
enable: { type: 'boolean', desc: '启用' },
|
|
276
|
+
disable: { type: 'boolean', desc: '停用' },
|
|
277
|
+
...CONFIRM_FLAG,
|
|
278
|
+
...SITE_FLAG,
|
|
279
|
+
},
|
|
280
|
+
examples: [
|
|
281
|
+
'wkgeo plugins toggle --key contact-form --enable # dry-run',
|
|
282
|
+
'wkgeo plugins toggle --key contact-form --enable --confirm # 真开',
|
|
283
|
+
'wkgeo plugins toggle --key member --disable --confirm',
|
|
284
|
+
],
|
|
285
|
+
notes: [
|
|
286
|
+
'需要 `site:write`。**默认 dry-run**,加 `--confirm` 才真发。',
|
|
287
|
+
'只读账号会回 403(人话:你是只读账号,不能改插件)。',
|
|
288
|
+
'关掉会员插件**不会删会员数据**:只是前台接口不再放行,重开数据还在。',
|
|
289
|
+
'`editor` 分类启用时,同站同分类的其它插件会被后端自动关掉,回包 `disabled_keys` 会列出来。',
|
|
290
|
+
'被本站启用中的模板依赖的插件不能关(回 400「该插件被模板《…》依赖,不能关闭」)。',
|
|
291
|
+
],
|
|
292
|
+
async run(ctx) {
|
|
293
|
+
const { out } = ctx;
|
|
294
|
+
if (!ctx.flags.enable && !ctx.flags.disable) {
|
|
295
|
+
throw new UsageError('请给出 --enable 或 --disable(二选一)', {
|
|
296
|
+
hint: 'wkgeo plugins toggle --key <插件> --enable | --disable',
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
if (ctx.flags.enable && ctx.flags.disable) {
|
|
300
|
+
throw new UsageError('--enable 与 --disable 不能同时给');
|
|
301
|
+
}
|
|
302
|
+
const enabled = ctx.flags.enable === true;
|
|
303
|
+
const key = requireKey(ctx, 'plugins toggle');
|
|
304
|
+
const body = { key, enabled };
|
|
305
|
+
|
|
306
|
+
if (!ctx.flags.confirm) {
|
|
307
|
+
return dryRun(ctx, ACTION.pluginToggle, body, [`插件:${key}`, `动作:${enabled ? '启用' : '停用'}`]);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const res = (await ctx.pluginCall(ACTION.pluginToggle, body)) || {};
|
|
311
|
+
const disabledKeys = Array.isArray(res.disabledKeys) ? res.disabledKeys : [];
|
|
312
|
+
const payload = {
|
|
313
|
+
site_id: siteIdOf(ctx),
|
|
314
|
+
key: res.key || key,
|
|
315
|
+
enabled: res.enabled === true,
|
|
316
|
+
category: res.category || '',
|
|
317
|
+
exclusive: res.exclusive === true,
|
|
318
|
+
disabled_keys: disabledKeys,
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
if (!out.json) {
|
|
322
|
+
out.ok(`${payload.key} 已${payload.enabled ? '启用' : '停用'}`);
|
|
323
|
+
if (payload.exclusive) {
|
|
324
|
+
out.info(`(${PLUGIN_CATEGORY_LABEL[payload.category] || payload.category} 分类单选互斥)`);
|
|
325
|
+
}
|
|
326
|
+
if (disabledKeys.length) out.warn(`已停用:${disabledKeys.join('、')}`);
|
|
327
|
+
}
|
|
328
|
+
ctx.done(payload);
|
|
329
|
+
return payload;
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
/* ══════════════════════════════ 配置(settings) ══════════════════════════════ */
|
|
334
|
+
|
|
335
|
+
export const pluginsSettingsCommand = {
|
|
336
|
+
name: 'plugins settings',
|
|
337
|
+
summary: '保存插件配置(把 --settings 的 JSON 交给插件自己的 settings 动作校验后落库;默认 dry-run)',
|
|
338
|
+
usage: 'wkgeo plugins settings --key <插件key> --settings <JSON> [--confirm] [--site <站点ID>]',
|
|
339
|
+
args: [],
|
|
340
|
+
flags: {
|
|
341
|
+
key: { type: 'string', required: true, desc: '插件 key(`wkgeo plugins list` 里 has_settings=是 的那些)' },
|
|
342
|
+
settings: {
|
|
343
|
+
type: 'string',
|
|
344
|
+
required: true,
|
|
345
|
+
desc: '配置项 JSON,键 = manifest.settings 里声明的键:{"siteKey":"…","secret":"…"}',
|
|
346
|
+
},
|
|
347
|
+
...CONFIRM_FLAG,
|
|
348
|
+
...SITE_FLAG,
|
|
349
|
+
},
|
|
350
|
+
examples: [
|
|
351
|
+
'wkgeo plugins settings --key member --settings \'{"loginTitle":"登录"}\' # dry-run',
|
|
352
|
+
'wkgeo plugins settings --key member --settings \'{"loginTitle":"登录"}\' --confirm # 真存',
|
|
353
|
+
],
|
|
354
|
+
notes: [
|
|
355
|
+
'需要 `site:write`。**默认 dry-run**,加 `--confirm` 才真发。',
|
|
356
|
+
'只发**这次给了的完整 settings**:服务端把 `settings` 整体交给插件的 settings 动作,',
|
|
357
|
+
' 插件按自己 manifest 里声明的键归一化(没声明的键会被丢掉);要"改一项留其它"就传全量。',
|
|
358
|
+
'插件没有配置项(manifest 没声明 settings)⇒ 回 400「该插件暂无配置项」。',
|
|
359
|
+
'插件网关不可达时**不会静默成功**:服务端按插件自己的报错回 4xx/5xx,CLI 原样转出。',
|
|
360
|
+
],
|
|
361
|
+
async run(ctx) {
|
|
362
|
+
const { out } = ctx;
|
|
363
|
+
const key = requireKey(ctx, 'plugins settings');
|
|
364
|
+
const raw = String(ctx.flags.settings || '');
|
|
365
|
+
let settings;
|
|
366
|
+
try {
|
|
367
|
+
settings = JSON.parse(raw);
|
|
368
|
+
} catch (e) {
|
|
369
|
+
throw new UsageError(`--settings 不是合法 JSON:${e && e.message ? e.message : e}`);
|
|
370
|
+
}
|
|
371
|
+
if (!settings || typeof settings !== 'object' || Array.isArray(settings)) {
|
|
372
|
+
throw new UsageError('--settings 必须是对象:{"键":"值"}');
|
|
373
|
+
}
|
|
374
|
+
const body = { key, settings };
|
|
375
|
+
const lines = [`插件:${key}`, `配置项:${Object.keys(settings).join(', ') || '(空对象)'}`];
|
|
376
|
+
if (!ctx.flags.confirm) return dryRun(ctx, ACTION.pluginSettingsSave, body, lines);
|
|
377
|
+
|
|
378
|
+
const res = (await ctx.pluginCall(ACTION.pluginSettingsSave, body)) || {};
|
|
379
|
+
const saved = res.settings && typeof res.settings === 'object' ? res.settings : settings;
|
|
380
|
+
const data = {
|
|
381
|
+
site_id: siteIdOf(ctx),
|
|
382
|
+
key: res.key || key,
|
|
383
|
+
settings: saved,
|
|
384
|
+
keys: Object.keys(saved),
|
|
385
|
+
};
|
|
386
|
+
if (!out.json) {
|
|
387
|
+
out.ok(`插件配置已保存:${data.key}(${data.keys.length} 项)`);
|
|
388
|
+
for (const k of data.keys) out.line(` ${k}:${JSON.stringify(saved[k])}`);
|
|
389
|
+
}
|
|
390
|
+
ctx.done(data);
|
|
391
|
+
return data;
|
|
392
|
+
},
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
/* ══════════════════════════════ 插件市场(market-list / install / uninstall / upgrade / demo) ══════════════════════════════ */
|
|
396
|
+
|
|
397
|
+
export const pluginsMarketListCommand = {
|
|
398
|
+
name: 'plugins market-list',
|
|
399
|
+
summary: '列插件市场(可装 / 已装 / 可升级 / 价格;只读)',
|
|
400
|
+
usage:
|
|
401
|
+
'wkgeo plugins market-list [--category <分类>] [--keyword <词>] [--installed-only] [--paid|--free] [--site <站点ID>]',
|
|
402
|
+
args: [],
|
|
403
|
+
flags: {
|
|
404
|
+
category: { type: 'string', desc: '分类:content / member / shop / marketing / tool / api / system / editor' },
|
|
405
|
+
keyword: { type: 'string', desc: '在名称 / 简介 / key 里搜(最多 60 字)' },
|
|
406
|
+
'installed-only': { type: 'boolean', desc: '只列本站已装的' },
|
|
407
|
+
paid: { type: 'boolean', desc: '只列付费的' },
|
|
408
|
+
free: { type: 'boolean', desc: '只列免费的' },
|
|
409
|
+
...SITE_FLAG,
|
|
410
|
+
},
|
|
411
|
+
examples: [
|
|
412
|
+
'wkgeo plugins market-list',
|
|
413
|
+
'wkgeo plugins market-list --category editor',
|
|
414
|
+
'wkgeo plugins market-list --installed-only --json',
|
|
415
|
+
],
|
|
416
|
+
notes: [
|
|
417
|
+
'需要 `site:read`(只读)。',
|
|
418
|
+
'只列"适用于 CMS 后台"的插件(`applies_to` 不含 cms 的市场行不会出现)。',
|
|
419
|
+
'普通用户只看到对你开放的那些(`visible_scope` / 授权行);平台管理员看全量。',
|
|
420
|
+
'`upgradable:true` = 市场版本 > 本站已装版本,可以 `plugins upgrade`。',
|
|
421
|
+
'`--paid` 与 `--free` 互斥。',
|
|
422
|
+
],
|
|
423
|
+
async run(ctx) {
|
|
424
|
+
const { out } = ctx;
|
|
425
|
+
if (ctx.flags.paid && ctx.flags.free) throw new UsageError('--paid 与 --free 不能同时给');
|
|
426
|
+
const body = {};
|
|
427
|
+
const category = String(ctx.flags.category || '').trim();
|
|
428
|
+
if (category) body.category = category;
|
|
429
|
+
const keyword = String(ctx.flags.keyword || '').trim();
|
|
430
|
+
if (keyword) body.keyword = keyword;
|
|
431
|
+
if (ctx.flags.installedOnly) body.installedOnly = true;
|
|
432
|
+
if (ctx.flags.paid) body.paid = true;
|
|
433
|
+
if (ctx.flags.free) body.paid = false;
|
|
434
|
+
|
|
435
|
+
const res = (await ctx.pluginCall(ACTION.cmsPluginMarketList, body)) || {};
|
|
436
|
+
const rows = rowsOf(res);
|
|
437
|
+
const data = {
|
|
438
|
+
site_id: siteIdOf(ctx),
|
|
439
|
+
total: Number(res.total || rows.length),
|
|
440
|
+
installed_count: Number(res.installedCount || 0),
|
|
441
|
+
categories: Array.isArray(res.categories) ? res.categories : [],
|
|
442
|
+
plugins: rows.map((p) => ({
|
|
443
|
+
key: p.key,
|
|
444
|
+
name: p.name,
|
|
445
|
+
category: p.category || 'tool',
|
|
446
|
+
version: p.version || '',
|
|
447
|
+
installed: p.installed === true,
|
|
448
|
+
installed_version: p.installedVersion || '',
|
|
449
|
+
enabled: p.enabled === true,
|
|
450
|
+
upgradable: p.upgradable === true,
|
|
451
|
+
price_cents: Number(p.priceCents || 0),
|
|
452
|
+
downloads: Number(p.downloads || 0),
|
|
453
|
+
demo_url: p.demoUrl || '',
|
|
454
|
+
})),
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
if (!out.json) {
|
|
458
|
+
out.head(`插件市场(站点 ${siteText(ctx)} · 已装 ${data.installed_count} 个 / 命中 ${data.total} 个)`);
|
|
459
|
+
if (!data.plugins.length) {
|
|
460
|
+
out.line(' (没有命中:换个 --category / --keyword 试试,或去掉 --installed-only)');
|
|
461
|
+
} else {
|
|
462
|
+
out.table(
|
|
463
|
+
[
|
|
464
|
+
{ title: '插件', key: 'key', width: 24 },
|
|
465
|
+
{ title: '名称', key: 'name', width: 18 },
|
|
466
|
+
{ title: '分类', key: 'category', width: 10 },
|
|
467
|
+
{ title: '版本', key: 'version', width: 10 },
|
|
468
|
+
{ title: '已装', key: 'installed', width: 8 },
|
|
469
|
+
{ title: '价格', key: 'price', width: 10 },
|
|
470
|
+
],
|
|
471
|
+
data.plugins.map((p) => ({
|
|
472
|
+
key: p.key,
|
|
473
|
+
name: p.name,
|
|
474
|
+
category: PLUGIN_CATEGORY_LABEL[p.category] || p.category,
|
|
475
|
+
version: p.version + (p.upgradable ? ' ↑' : ''),
|
|
476
|
+
installed: p.installed ? (p.enabled ? '启用' : '停用') : '否',
|
|
477
|
+
price: p.price_cents ? `${(p.price_cents / 100).toFixed(2)} 元` : '免费',
|
|
478
|
+
})),
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
const upgradable = data.plugins.filter((p) => p.upgradable).map((p) => p.key);
|
|
482
|
+
if (upgradable.length) out.info(`可升级:${upgradable.join('、')}(\`wkgeo plugins upgrade --key <插件> --confirm\`)`);
|
|
483
|
+
out.info('安装:`wkgeo plugins install --key <插件> --confirm`');
|
|
484
|
+
}
|
|
485
|
+
ctx.done(data);
|
|
486
|
+
return data;
|
|
487
|
+
},
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
export const pluginsInstallCommand = {
|
|
491
|
+
name: 'plugins install',
|
|
492
|
+
summary: '从插件市场装一个插件到本站(跑建表 + install hook;默认 dry-run)',
|
|
493
|
+
usage: 'wkgeo plugins install --key <插件key> [--confirm] [--site <站点ID>]',
|
|
494
|
+
args: [],
|
|
495
|
+
flags: {
|
|
496
|
+
key: { type: 'string', required: true, desc: '插件 key(`wkgeo plugins market-list` 里的那列)' },
|
|
497
|
+
...CONFIRM_FLAG,
|
|
498
|
+
...SITE_FLAG,
|
|
499
|
+
},
|
|
500
|
+
examples: [
|
|
501
|
+
'wkgeo plugins install --key contact-form # dry-run',
|
|
502
|
+
'wkgeo plugins install --key contact-form --confirm # 真装',
|
|
503
|
+
],
|
|
504
|
+
notes: [
|
|
505
|
+
'需要 `site:write`。**默认 dry-run**,加 `--confirm` 才真发。',
|
|
506
|
+
'**幂等**:本站已经装过就直接回 `already_installed:true`,不会重复跑建表 / hook。',
|
|
507
|
+
'服务端按 manifest 建表(`plug_<key>_*`)并调插件自己的 install 动作;',
|
|
508
|
+
' 缺表 / hook 报错会原样失败(`缺少数据表 …`),不会"装了一半算成功"。',
|
|
509
|
+
'安装成功后不自动启用(除非 manifest 写了 `enable_on_install:true`)。',
|
|
510
|
+
],
|
|
511
|
+
async run(ctx) {
|
|
512
|
+
const { out } = ctx;
|
|
513
|
+
const key = requireKey(ctx, 'plugins install');
|
|
514
|
+
const body = { key };
|
|
515
|
+
if (!ctx.flags.confirm) {
|
|
516
|
+
return dryRun(ctx, ACTION.pluginMarketInstall, body, [`插件:${key}`, '效果:建表 + 跑 install hook(幂等)']);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
const res = (await ctx.pluginCall(ACTION.pluginMarketInstall, body)) || {};
|
|
520
|
+
const data = {
|
|
521
|
+
site_id: siteIdOf(ctx),
|
|
522
|
+
key: res.key || key,
|
|
523
|
+
name: res.name || '',
|
|
524
|
+
installed: res.installed !== false,
|
|
525
|
+
already_installed: res.alreadyInstalled === true,
|
|
526
|
+
enabled: res.enabled === true,
|
|
527
|
+
version: res.version || '',
|
|
528
|
+
hook: res.hook || null,
|
|
529
|
+
};
|
|
530
|
+
if (!out.json) {
|
|
531
|
+
if (data.already_installed) out.ok(`${data.key} 本站早就装过了(幂等,没动任何数据)`);
|
|
532
|
+
else out.ok(`${data.key} 已安装${data.version ? `(v${data.version})` : ''}${data.enabled ? ',并已启用' : ''}`);
|
|
533
|
+
if (data.hook && Array.isArray(data.hook.tablesCreated) && data.hook.tablesCreated.length) {
|
|
534
|
+
out.line(` 建表:${data.hook.tablesCreated.join('、')}`);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
ctx.done(data);
|
|
538
|
+
return data;
|
|
539
|
+
},
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
export const pluginsUninstallCommand = {
|
|
543
|
+
name: 'plugins uninstall',
|
|
544
|
+
summary: '从本站卸一个插件(**数据保留**,重装可恢复;默认 dry-run)',
|
|
545
|
+
usage: 'wkgeo plugins uninstall --key <插件key> [--confirm] [--site <站点ID>]',
|
|
546
|
+
args: [],
|
|
547
|
+
flags: {
|
|
548
|
+
key: { type: 'string', required: true, desc: '插件 key' },
|
|
549
|
+
...CONFIRM_FLAG,
|
|
550
|
+
...SITE_FLAG,
|
|
551
|
+
},
|
|
552
|
+
examples: [
|
|
553
|
+
'wkgeo plugins uninstall --key contact-form # dry-run',
|
|
554
|
+
'wkgeo plugins uninstall --key contact-form --confirm # 真卸',
|
|
555
|
+
],
|
|
556
|
+
notes: [
|
|
557
|
+
'需要 `site:write`。**默认 dry-run**,加 `--confirm` 才真发。',
|
|
558
|
+
'**只删 `plugin` 里的那一行**(= 本站的安装记录),插件自己的表与数据**全部保留**:',
|
|
559
|
+
' 重新 `plugins install` 就能接着用,所以这是"停用安装态"而不是"清数据"。',
|
|
560
|
+
'被本站启用中的模板依赖的插件不能卸(回 400「该插件被模板《…》依赖,不能卸载」)。',
|
|
561
|
+
'本站没装过 ⇒ 400「这个站还没装这个插件」。',
|
|
562
|
+
],
|
|
563
|
+
async run(ctx) {
|
|
564
|
+
const { out } = ctx;
|
|
565
|
+
const key = requireKey(ctx, 'plugins uninstall');
|
|
566
|
+
const body = { key };
|
|
567
|
+
if (!ctx.flags.confirm) {
|
|
568
|
+
return dryRun(ctx, ACTION.pluginMarketUninstall, body, [
|
|
569
|
+
`插件:${key}`,
|
|
570
|
+
'效果:删本站安装记录行;**插件数据保留**(重装可恢复)',
|
|
571
|
+
]);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
const res = (await ctx.pluginCall(ACTION.pluginMarketUninstall, body)) || {};
|
|
575
|
+
const data = {
|
|
576
|
+
site_id: siteIdOf(ctx),
|
|
577
|
+
key: res.key || key,
|
|
578
|
+
uninstalled: res.uninstalled !== false,
|
|
579
|
+
data_kept: res.dataKept !== false,
|
|
580
|
+
message: String(res.message || ''),
|
|
581
|
+
};
|
|
582
|
+
if (!out.json) {
|
|
583
|
+
out.ok(`${data.key} 已卸载(数据保留:重装即可恢复)`);
|
|
584
|
+
if (data.message) out.line(` ${data.message}`);
|
|
585
|
+
}
|
|
586
|
+
ctx.done(data);
|
|
587
|
+
return data;
|
|
588
|
+
},
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
export const pluginsUpgradeCommand = {
|
|
592
|
+
name: 'plugins upgrade',
|
|
593
|
+
summary: '把本站已装的插件升到市场版本(只改版本号;默认 dry-run)',
|
|
594
|
+
usage: 'wkgeo plugins upgrade --key <插件key> [--confirm] [--site <站点ID>]',
|
|
595
|
+
args: [],
|
|
596
|
+
flags: {
|
|
597
|
+
key: { type: 'string', required: true, desc: '插件 key' },
|
|
598
|
+
...CONFIRM_FLAG,
|
|
599
|
+
...SITE_FLAG,
|
|
600
|
+
},
|
|
601
|
+
examples: [
|
|
602
|
+
'wkgeo plugins upgrade --key contact-form # dry-run',
|
|
603
|
+
'wkgeo plugins upgrade --key contact-form --confirm # 真升',
|
|
604
|
+
],
|
|
605
|
+
notes: [
|
|
606
|
+
'需要 `site:write`。**默认 dry-run**,加 `--confirm` 才真发。',
|
|
607
|
+
'必须先装再升(404 = 市场没这个插件;400「先安装再升级」= 本站没装)。',
|
|
608
|
+
'已经是市场最新版 ⇒ 400「已经是最新版本」。',
|
|
609
|
+
'**只把 `plugin.version` 改成市场版本**:建表 / 数据迁移不在这条动作里,需要的话先 `uninstall` + `install`。',
|
|
610
|
+
],
|
|
611
|
+
async run(ctx) {
|
|
612
|
+
const { out } = ctx;
|
|
613
|
+
const key = requireKey(ctx, 'plugins upgrade');
|
|
614
|
+
const body = { key };
|
|
615
|
+
if (!ctx.flags.confirm) {
|
|
616
|
+
return dryRun(ctx, ACTION.pluginMarketUpgrade, body, [`插件:${key}`, '效果:版本号跟到市场版本']);
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
const res = (await ctx.pluginCall(ACTION.pluginMarketUpgrade, body)) || {};
|
|
620
|
+
const data = {
|
|
621
|
+
site_id: siteIdOf(ctx),
|
|
622
|
+
key: res.key || key,
|
|
623
|
+
from: res.from || '',
|
|
624
|
+
to: res.to || '',
|
|
625
|
+
upgraded: res.upgraded !== false,
|
|
626
|
+
};
|
|
627
|
+
if (!out.json) out.ok(`${data.key} 已升级:${data.from || '?'} → ${data.to || '?'}`);
|
|
628
|
+
ctx.done(data);
|
|
629
|
+
return data;
|
|
630
|
+
},
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
export const pluginsDemoCommand = {
|
|
634
|
+
name: 'plugins demo',
|
|
635
|
+
summary: '取插件的演示地址(库里登记的 demo_url 原样返回;只读,不下载不校验)',
|
|
636
|
+
usage: 'wkgeo plugins demo --key <插件key> [--site <站点ID>] [--json]',
|
|
637
|
+
args: [],
|
|
638
|
+
flags: {
|
|
639
|
+
key: { type: 'string', required: true, desc: '插件 key(`wkgeo plugins market-list` 里的那列)' },
|
|
640
|
+
...SITE_FLAG,
|
|
641
|
+
},
|
|
642
|
+
examples: ['wkgeo plugins demo --key contact-form', 'wkgeo plugins demo --key contact-form --json'],
|
|
643
|
+
notes: [
|
|
644
|
+
'需要 `site:read`(只读)。',
|
|
645
|
+
'**只是查库**:服务端不发外呼、不下载、不检查链接能不能打开;没有演示地址就回 400「暂无演示」。',
|
|
646
|
+
'演示站是插件作者维护的外链,打开前请自己确认域名可信。',
|
|
647
|
+
],
|
|
648
|
+
async run(ctx) {
|
|
649
|
+
const { out } = ctx;
|
|
650
|
+
const key = requireKey(ctx, 'plugins demo');
|
|
651
|
+
const res = (await ctx.pluginCall(ACTION.pluginMarketDemo, { key })) || {};
|
|
652
|
+
const data = { site_id: siteIdOf(ctx), key: res.key || key, url: String(res.url || '') };
|
|
653
|
+
if (!out.json) {
|
|
654
|
+
out.head(`插件演示:${data.key}`);
|
|
655
|
+
out.line(` ${data.url || '(空)'}`);
|
|
656
|
+
out.line(' ★ 外链由插件作者维护,本命令不校验可达性。');
|
|
657
|
+
}
|
|
658
|
+
ctx.done(data);
|
|
659
|
+
return data;
|
|
660
|
+
},
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* 插件类全部 9 条命令(B5)。注册顺序 = 帮助里的顺序:
|
|
665
|
+
* 先"本站现状"(list / access),再写(toggle / settings),最后市场(market-list / install /
|
|
666
|
+
* uninstall / upgrade / demo)。
|
|
667
|
+
*/
|
|
668
|
+
export const PLUGIN_COMMANDS = [
|
|
669
|
+
pluginsListCommand,
|
|
670
|
+
pluginsAccessCommand,
|
|
671
|
+
pluginsToggleCommand,
|
|
672
|
+
pluginsSettingsCommand,
|
|
673
|
+
pluginsMarketListCommand,
|
|
674
|
+
pluginsInstallCommand,
|
|
675
|
+
pluginsUninstallCommand,
|
|
676
|
+
pluginsUpgradeCommand,
|
|
677
|
+
pluginsDemoCommand,
|
|
678
|
+
];
|