@wkgeo/cli 1.1.5 → 2.0.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/CHANGELOG.md +8 -0
- package/README.md +6 -43
- package/SKILL.md +4 -34
- package/lib/api.mjs +8 -26
- package/lib/args.mjs +5 -5
- package/lib/cms.mjs +0 -2
- package/lib/commands/auth.mjs +10 -18
- package/lib/commands/cms.mjs +66 -18
- package/lib/commands/index.mjs +15 -82
- package/lib/commands/member.mjs +936 -985
- package/lib/commands/site.mjs +388 -435
- package/lib/commands/siteops.mjs +438 -1013
- package/lib/commands/sites.mjs +4 -4
- package/lib/commands/template.mjs +1 -1
- package/lib/runtime.mjs +4 -4
- package/lib/template-publish.mjs +36 -78
- package/package.json +1 -1
- package/lib/commands/dnscred.mjs +0 -428
- package/lib/commands/domainops.mjs +0 -546
- package/lib/commands/domainorder.mjs +0 -439
package/lib/commands/sites.mjs
CHANGED
|
@@ -144,10 +144,10 @@ function printShortDomain(out, site, { channel = 'platform' } = {}) {
|
|
|
144
144
|
} else if (site.prefix_kv_written === false) {
|
|
145
145
|
out.warn('短域解析未写入(prefix_kv_written=false):现在访问短域会 403/404。');
|
|
146
146
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
147
|
+
* 短域 KV 由服务端在建站时写入,CLI 没有修复能力(2026-11-19 task-1254:域名命令面已全部删除)——
|
|
148
|
+
* 只能在文案里指路,**不要**在 CLI 里假装能修(否则就是"命令回成功、站点还是打不开")。
|
|
149
149
|
*/
|
|
150
|
-
out.info(' →
|
|
150
|
+
out.info(' → 修复要到会员中心 / CMS 后台的「域名」里看开通状态,并联系管理员重写该站短域 KV。');
|
|
151
151
|
} else {
|
|
152
152
|
out.info(' → 短域解析写入结果:服务端未返回(旧版接口)—— 直接打开上面的地址试一下就知道');
|
|
153
153
|
}
|
|
@@ -736,7 +736,7 @@ export const sitesGetCommand = {
|
|
|
736
736
|
out.line(` 创建时间:${formatTime(site.created_at)}${detail.updated_at ? ` · 更新时间:${formatTime(detail.updated_at)}` : ''}`);
|
|
737
737
|
if (detail.last_error) out.warn(`最近一次错误:${detail.last_error}${detail.last_error_at ? `(${formatTime(detail.last_error_at)})` : ''}`);
|
|
738
738
|
if (!site.custom_domain) {
|
|
739
|
-
out.info(' →
|
|
739
|
+
out.info(' → 还没有自有域名:到会员中心 / CMS 后台的「域名」里绑定,并按提示加解析记录。');
|
|
740
740
|
}
|
|
741
741
|
}
|
|
742
742
|
ctx.done(data);
|
|
@@ -1083,7 +1083,7 @@ export const templatePublishCommand = {
|
|
|
1083
1083
|
'wkgeo template publish --dir ./tpl/demo --key t144-probe --confirm # 真写(测试 key)',
|
|
1084
1084
|
],
|
|
1085
1085
|
notes: [
|
|
1086
|
-
'凭据只从 env / 本机 `oss.env`
|
|
1086
|
+
'凭据只从 env / 本机 `oss.env` 读,**永不打印**(只报"已配置 + 来源路径 + 末 4 位");数据库读写走真库 RDS 通道(腾讯 CloudBase 旧网关已退役)。',
|
|
1087
1087
|
'真写前先把**市场行 + OSS 前缀清单**存档到 `.tmp-build/t144/`(`--archive` 可改),写完再存一份,前后可比。',
|
|
1088
1088
|
'OSS 走手写 V1 签名(CLI 零依赖,不引 ali-oss);`prefix`/`max-keys` 这类普通查询参数**不进签名**,进了会 SignatureDoesNotMatch。',
|
|
1089
1089
|
'顺序:上传 → prune(新替旧)→ upsert 市场行(`version` 自增、`sha256` = 发布清单摘要)→ 回读(行 / files 数 / OSS HEAD / 对象直链 / 预览短链)。',
|
package/lib/runtime.mjs
CHANGED
|
@@ -351,10 +351,10 @@ export function createRuntime({
|
|
|
351
351
|
/**
|
|
352
352
|
* ★ 2026-10-28:把**注入的 stdin** 也挂到 ctx 上。
|
|
353
353
|
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
354
|
+
* 为什么需要它:从 stdin(管道)或 TTY 无回显交互读密文(如 `publish targets save`
|
|
355
|
+
* 的密码)时,读取源必须与判定源是同一个对象。命令如果自己用 `process.stdin`,
|
|
356
|
+
* 单测注入的假 stdin 就永远不生效(用例会挂在真 stdin 上),而且 `stdinIsTTY`
|
|
357
|
+
* 与真正的读取源会**对不上**(一个被判成"管道"、另一个却在读终端)。
|
|
358
358
|
*/
|
|
359
359
|
stdin,
|
|
360
360
|
/** 时钟(**恒为函数**;不传 = `Date.now`) */
|
package/lib/template-publish.mjs
CHANGED
|
@@ -112,22 +112,8 @@ export function resolveOssCreds({ cwd = process.cwd(), env = process.env } = {})
|
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
|
|
116
|
-
*
|
|
117
|
-
*/
|
|
118
|
-
export function resolveDbCreds({ cwd = process.cwd(), env = process.env } = {}) {
|
|
119
|
-
const explicit = env.WKGEO_CLOUDBASE_ENV;
|
|
120
|
-
const root = explicit && fs.existsSync(explicit) ? explicit : findUp(cwd, path.join('tencent', 'cloudbase', '.env'));
|
|
121
|
-
const file = explicit && fs.existsSync(explicit) ? path.resolve(explicit) : root ? path.join(root, 'tencent', 'cloudbase', '.env') : null;
|
|
122
|
-
const vars = file ? parseEnvFile(file) : {};
|
|
123
|
-
const pick = (k) => env[k] || vars[k] || '';
|
|
124
|
-
return {
|
|
125
|
-
envId: pick('CLOUDBASE_ENV_ID'),
|
|
126
|
-
apiKey: pick('CLOUDBASE_APIKEY'),
|
|
127
|
-
source: file,
|
|
128
|
-
gateway: pick('CLOUDBASE_GATEWAY'),
|
|
129
|
-
};
|
|
130
|
-
}
|
|
115
|
+
/* 数据库凭据:2026-11-18 task-973 —— 腾讯 CloudBase `exec-pgsql` + `CLOUDBASE_APIKEY` 已退役,
|
|
116
|
+
* 不再解析 / 不再要求;写市场行走真库 RDS 通道(见下面 `dbExec`)。 */
|
|
131
117
|
|
|
132
118
|
/** 只报"有没有配",不报值 */
|
|
133
119
|
export function credsSummary(creds) {
|
|
@@ -139,12 +125,6 @@ export function credsSummary(creds) {
|
|
|
139
125
|
source: creds.oss.source,
|
|
140
126
|
access_key_id_tail: creds.oss.accessKeyId ? creds.oss.accessKeyId.slice(-4) : '',
|
|
141
127
|
},
|
|
142
|
-
db: {
|
|
143
|
-
configured: !!(creds.db.envId && creds.db.apiKey),
|
|
144
|
-
env_id: creds.db.envId,
|
|
145
|
-
source: creds.db.source,
|
|
146
|
-
api_key_tail: creds.db.apiKey ? creds.db.apiKey.slice(-4) : '',
|
|
147
|
-
},
|
|
148
128
|
};
|
|
149
129
|
}
|
|
150
130
|
|
|
@@ -241,65 +221,56 @@ export function ossPublicUrl({ creds, objectKey }) {
|
|
|
241
221
|
return `https://${creds.bucket}.${creds.region}.aliyuncs.com/${objectKey}`;
|
|
242
222
|
}
|
|
243
223
|
|
|
244
|
-
/* ------------------------------------------------------------------
|
|
224
|
+
/* ------------------------------------------------------------------ 数据库(真库 RDS) */
|
|
225
|
+
|
|
226
|
+
/** 懒加载真库通道:`deploy-web/_lib/pg-rds.mjs` 不在 npm 包里 ⇒ 只在真正要读写市场行时才解析。 */
|
|
227
|
+
let rdsModPromise = null;
|
|
228
|
+
function loadRds() {
|
|
229
|
+
if (!rdsModPromise) {
|
|
230
|
+
rdsModPromise = import(new URL('../../deploy-web/_lib/pg-rds.mjs', import.meta.url).href).catch((e) => {
|
|
231
|
+
rdsModPromise = null;
|
|
232
|
+
throw new CliError('数据库通道不可用(真库 RDS 探针仅仓库内可用)', {
|
|
233
|
+
kind: 'db',
|
|
234
|
+
code: 'EDB',
|
|
235
|
+
hint: String((e && e.message) || e).slice(0, 300),
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return rdsModPromise;
|
|
240
|
+
}
|
|
245
241
|
|
|
246
242
|
/**
|
|
247
|
-
* 执行一条 PG
|
|
248
|
-
*
|
|
249
|
-
* body `{sql, parameters, role:'cloudbase_postgres'}`,响应取 `data ?? rows ?? 自身`。
|
|
243
|
+
* 执行一条 PG 语句(2026-11-18 task-973:腾讯 CloudBase `exec-pgsql` 网关已退役,改走真库 RDS)。
|
|
244
|
+
* `rdsExec` 返回行对象数组(与旧网关形状一致);只读语句不给 `write`,写语句显式 `write:true`。
|
|
250
245
|
*/
|
|
251
|
-
export async function dbExec({
|
|
252
|
-
const
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
headers: { 'content-type': 'application/json', authorization: `Bearer ${creds.apiKey}` },
|
|
256
|
-
body: JSON.stringify({ sql, parameters, role: 'cloudbase_postgres' }),
|
|
257
|
-
});
|
|
258
|
-
const text = await res.text();
|
|
259
|
-
let json = null;
|
|
260
|
-
try {
|
|
261
|
-
json = JSON.parse(text);
|
|
262
|
-
} catch {
|
|
263
|
-
json = null;
|
|
264
|
-
}
|
|
265
|
-
if (!res.ok) {
|
|
266
|
-
throw new CliError(`数据库请求失败 ${res.status}`, {
|
|
267
|
-
kind: 'db',
|
|
268
|
-
code: 'EDB',
|
|
269
|
-
hint: (text || '').slice(0, 300),
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
const data = json && (json.data ?? json.rows ?? json.result ?? json);
|
|
273
|
-
const rows = Array.isArray(data) ? data : data && Array.isArray(data.rows) ? data.rows : [];
|
|
274
|
-
return { rows, raw: json };
|
|
246
|
+
export async function dbExec({ sql, parameters = [], write = false } = {}) {
|
|
247
|
+
const mod = await loadRds();
|
|
248
|
+
const rows = await mod.rdsExec(sql, parameters, write ? { write: true } : undefined);
|
|
249
|
+
return { rows, raw: rows };
|
|
275
250
|
}
|
|
276
251
|
|
|
277
252
|
/** 读一行市场模板(不存在返回 null) */
|
|
278
|
-
export async function readMarketRow({
|
|
253
|
+
export async function readMarketRow({ key } = {}) {
|
|
279
254
|
const { rows } = await dbExec({
|
|
280
|
-
creds,
|
|
281
255
|
sql: `select id::text as id, key, name, sort, price_cents, coalesce(version, 0) as version, sha256, jsonb_array_length(files) as files_count, enabled, updated_at::text as updated_at from ${MARKET_TABLE} where key = $1 limit 1`,
|
|
282
256
|
parameters: [key],
|
|
283
|
-
fetchImpl,
|
|
284
257
|
});
|
|
285
258
|
return rows[0] || null;
|
|
286
259
|
}
|
|
287
260
|
|
|
288
261
|
/** 删一行市场模板(清理测试用;调用方负责确认 key) */
|
|
289
|
-
export async function deleteMarketRow({
|
|
262
|
+
export async function deleteMarketRow({ key } = {}) {
|
|
290
263
|
const { rows } = await dbExec({
|
|
291
|
-
creds,
|
|
292
264
|
sql: `delete from ${MARKET_TABLE} where key = $1 returning id::text as id, key`,
|
|
293
265
|
parameters: [key],
|
|
294
|
-
|
|
266
|
+
write: true,
|
|
295
267
|
});
|
|
296
268
|
return rows[0] || null;
|
|
297
269
|
}
|
|
298
270
|
|
|
299
271
|
/** upsert:`files` 就是这个 key 的完整清单(覆盖写),`version` 自增 */
|
|
300
|
-
export async function upsertMarketRow({
|
|
272
|
+
export async function upsertMarketRow({ row } = {}) {
|
|
301
273
|
const { rows } = await dbExec({
|
|
302
|
-
creds,
|
|
303
274
|
sql: `insert into ${MARKET_TABLE}
|
|
304
275
|
(key, name, summary, files, sort, enabled, price_cents, demo, industries, visible_scope, requires_plugins, version, sha256)
|
|
305
276
|
values ($1, $2, $3, $4::jsonb, $5, true, $6, $7::jsonb, $8::jsonb, 'all', '[]'::jsonb, 1, $9)
|
|
@@ -327,7 +298,7 @@ returning id::text as id, key, name, sort, price_cents, coalesce(version, 0) as
|
|
|
327
298
|
JSON.stringify(row.industries || []),
|
|
328
299
|
row.sha256,
|
|
329
300
|
],
|
|
330
|
-
|
|
301
|
+
write: true,
|
|
331
302
|
});
|
|
332
303
|
return rows[0] || null;
|
|
333
304
|
}
|
|
@@ -498,7 +469,7 @@ export async function publishTemplate({
|
|
|
498
469
|
onStep = () => {},
|
|
499
470
|
} = {}) {
|
|
500
471
|
const collected = await collectTemplate({ dir, key });
|
|
501
|
-
const resolved = creds || { oss: resolveOssCreds({ cwd })
|
|
472
|
+
const resolved = creds || { oss: resolveOssCreds({ cwd }) };
|
|
502
473
|
if (!resolved.oss.accessKeyId || !resolved.oss.accessKeySecret) {
|
|
503
474
|
throw new CliError('OSS 凭据缺失(OSS_ACCESS_KEY_ID / OSS_ACCESS_KEY_SECRET)', {
|
|
504
475
|
kind: 'usage',
|
|
@@ -507,21 +478,12 @@ export async function publishTemplate({
|
|
|
507
478
|
hint: '写到 oss.env(仓库根)或设进环境变量;本命令不打印任何密钥',
|
|
508
479
|
});
|
|
509
480
|
}
|
|
510
|
-
if (!resolved.db.envId || !resolved.db.apiKey) {
|
|
511
|
-
throw new CliError('数据库凭据缺失(CLOUDBASE_ENV_ID / CLOUDBASE_APIKEY)', {
|
|
512
|
-
kind: 'usage',
|
|
513
|
-
code: 'ENOCREDS',
|
|
514
|
-
exitCode: 2,
|
|
515
|
-
hint: '写到 tencent/cloudbase/.env 或设进环境变量',
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
481
|
const ossCreds = {
|
|
519
482
|
accessKeyId: resolved.oss.accessKeyId,
|
|
520
483
|
accessKeySecret: resolved.oss.accessKeySecret,
|
|
521
484
|
bucket: resolved.oss.bucket,
|
|
522
485
|
region: resolved.oss.region,
|
|
523
486
|
};
|
|
524
|
-
const dbCreds = { envId: resolved.db.envId, apiKey: resolved.db.apiKey, gateway: resolved.db.gateway };
|
|
525
487
|
const paths = archivePaths(archiveDir, collected.key);
|
|
526
488
|
const steps = [];
|
|
527
489
|
const step = (name, status, detail = null) => {
|
|
@@ -533,7 +495,7 @@ export async function publishTemplate({
|
|
|
533
495
|
|
|
534
496
|
// ① 读目录 + 计划(含现有市场行 / OSS 清单 = "前"存档)
|
|
535
497
|
step('collect', 'ok', { files: collected.files.length, bytes: collected.totalBytes, problems: collected.problems.length });
|
|
536
|
-
const marketBefore = await readMarketRow({
|
|
498
|
+
const marketBefore = await readMarketRow({ key: collected.key });
|
|
537
499
|
const ossBefore = await ossList({ creds: ossCreds, prefix: `templates/${collected.key}/`, fetchImpl });
|
|
538
500
|
step('archive-before', 'ok', { market: !!marketBefore, oss_objects: ossBefore.keys.length });
|
|
539
501
|
const plan = buildPlan({
|
|
@@ -596,7 +558,6 @@ export async function publishTemplate({
|
|
|
596
558
|
|
|
597
559
|
// ④ upsert 市场行(files 顺序 = template.json.files 顺序)
|
|
598
560
|
const row = await upsertMarketRow({
|
|
599
|
-
creds: dbCreds,
|
|
600
561
|
row: {
|
|
601
562
|
key: collected.key,
|
|
602
563
|
name: collected.name,
|
|
@@ -608,12 +569,11 @@ export async function publishTemplate({
|
|
|
608
569
|
industries: collected.industries,
|
|
609
570
|
sha256: collected.digest,
|
|
610
571
|
},
|
|
611
|
-
fetchImpl,
|
|
612
572
|
});
|
|
613
573
|
step('market-upsert', 'ok', row);
|
|
614
574
|
|
|
615
575
|
// ⑤ 回读校验
|
|
616
|
-
const marketAfter = await readMarketRow({
|
|
576
|
+
const marketAfter = await readMarketRow({ key: collected.key });
|
|
617
577
|
const ossAfter = await ossList({ creds: ossCreds, prefix: `templates/${collected.key}/`, fetchImpl });
|
|
618
578
|
const heads = [];
|
|
619
579
|
for (const up of plan.uploads) {
|
|
@@ -699,18 +659,17 @@ export async function cleanupTemplate({ key, creds = null, cwd = process.cwd(),
|
|
|
699
659
|
if (!/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(String(key || ''))) {
|
|
700
660
|
throw new CliError(`非法 key:${key}`, { kind: 'usage', code: 'EBADKEY', exitCode: 2 });
|
|
701
661
|
}
|
|
702
|
-
const resolved = creds || { oss: resolveOssCreds({ cwd })
|
|
662
|
+
const resolved = creds || { oss: resolveOssCreds({ cwd }) };
|
|
703
663
|
const ossCreds = resolved.oss;
|
|
704
|
-
const dbCreds = resolved.db;
|
|
705
664
|
const before = await ossList({ creds: ossCreds, prefix: `templates/${key}/`, fetchImpl });
|
|
706
665
|
const removed = [];
|
|
707
666
|
for (const obj of before.keys) {
|
|
708
667
|
const r = await ossDelete({ creds: ossCreds, objectKey: obj.key, fetchImpl });
|
|
709
668
|
if (r.ok) removed.push(obj.key);
|
|
710
669
|
}
|
|
711
|
-
const row = await deleteMarketRow({
|
|
670
|
+
const row = await deleteMarketRow({ key });
|
|
712
671
|
const after = await ossList({ creds: ossCreds, prefix: `templates/${key}/`, fetchImpl });
|
|
713
|
-
const rowAfter = await readMarketRow({
|
|
672
|
+
const rowAfter = await readMarketRow({ key });
|
|
714
673
|
return { key, removed, row, oss_before: before.keys.length, oss_after: after.keys.length, market_before: !!row, market_after: !!rowAfter };
|
|
715
674
|
}
|
|
716
675
|
|
|
@@ -720,7 +679,6 @@ export default {
|
|
|
720
679
|
buildPlan,
|
|
721
680
|
cleanupTemplate,
|
|
722
681
|
resolveOssCreds,
|
|
723
|
-
resolveDbCreds,
|
|
724
682
|
credsSummary,
|
|
725
683
|
ossPut,
|
|
726
684
|
ossHead,
|