@wkgeo/cli 2.0.3 → 2.1.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 +10 -2
- package/README.md +7 -7
- package/SKILL.md +1038 -1038
- package/lib/api.mjs +351 -351
- package/lib/args.mjs +235 -235
- package/lib/build.mjs +1047 -0
- package/lib/cms.mjs +328 -328
- package/lib/commands/auth.mjs +1280 -1280
- package/lib/commands/data.mjs +694 -694
- package/lib/commands/index.mjs +15 -1
- package/lib/commands/init.mjs +111 -111
- package/lib/commands/orders.mjs +691 -691
- package/lib/commands/site.mjs +82 -0
- package/lib/commands/siteops.mjs +248 -0
- package/lib/commands/sites.mjs +968 -801
- package/lib/commands/spec.mjs +72 -72
- package/lib/commands/template.mjs +1484 -1484
- package/lib/config.mjs +57 -4
- package/lib/errors.mjs +446 -336
- package/lib/manifest-apply.mjs +1650 -1650
- package/lib/manifest-schema.json +480 -480
- package/lib/manifest.mjs +1106 -1106
- package/lib/runtime.mjs +767 -654
- package/lib/site-create.mjs +537 -537
- package/lib/site-credentials.mjs +157 -0
- package/lib/site-meta.mjs +474 -0
- package/lib/site-spec.mjs +302 -302
- package/lib/site-template.mjs +405 -0
- package/lib/template-gen.mjs +1354 -1354
- package/lib/template-publish.mjs +696 -696
- package/lib/templates-sync.mjs +676 -644
- package/lib/workspace-sync.mjs +386 -0
- package/package.json +56 -56
- package/spec/SITE-SPEC.md +198 -198
package/lib/commands/index.mjs
CHANGED
|
@@ -68,6 +68,8 @@ import {
|
|
|
68
68
|
formsListCommand,
|
|
69
69
|
formsEntriesCommand,
|
|
70
70
|
previewCommand,
|
|
71
|
+
siteSyncDiffCommand,
|
|
72
|
+
siteBuildCommand,
|
|
71
73
|
importV2StartCommand,
|
|
72
74
|
importV2StatusCommand,
|
|
73
75
|
} from './siteops.mjs';
|
|
@@ -304,6 +306,18 @@ export const COMMANDS = [
|
|
|
304
306
|
formsListCommand,
|
|
305
307
|
formsEntriesCommand,
|
|
306
308
|
previewCommand,
|
|
309
|
+
/**
|
|
310
|
+
* ★ 2026-11-22(老板「差异检验」第一步):`site sync diff` = 工作区模板通道的**只读**差异
|
|
311
|
+
* (本地 <目录>/template 与上次 pull 的线上基线对 sha256;四类计数 = 待发布 / 待下载 / 未变)。
|
|
312
|
+
* 零网络、零写盘 —— 和 `templates push --dry-run` 是同一口径的两个阶段:先本地看,再实时看。
|
|
313
|
+
*/
|
|
314
|
+
siteSyncDiffCommand,
|
|
315
|
+
/**
|
|
316
|
+
* ★ 2026-11-22(老板「静态页面也在本地生成,最后再传 OSS」):`site build` =
|
|
317
|
+
* 本地生成一份 dist(HTML + site-<hash>.css|js + 模板资产),**只读线上渲染、不发布 / 不上传**。
|
|
318
|
+
* 与 `site sync diff` 同属「工作区」这一层:先在本地看 / 先生成,最后才轮到发布。
|
|
319
|
+
*/
|
|
320
|
+
siteBuildCommand,
|
|
307
321
|
importV2StartCommand,
|
|
308
322
|
importV2StatusCommand,
|
|
309
323
|
/**
|
|
@@ -412,7 +426,7 @@ const GROUP_SUMMARY = {
|
|
|
412
426
|
notify: '我的消息:列表(未读数置顶)/ 标已读(写,默认 dry-run,`--confirm` 才真发)',
|
|
413
427
|
invoices: '我的开票:可开票订单 + 我的开票申请(只读;开票动作留在会员端)',
|
|
414
428
|
plans: '套餐目录:订阅套餐 / 加量包套餐 / 我已买的加量包(只读,三块小表)',
|
|
415
|
-
site: '站点:选站 / 建站 / 公司信息 / 示例内容 / 站级同步(写要 site:write,默认 dry-run)',
|
|
429
|
+
site: '站点:选站 / 建站 / 公司信息 / 示例内容 / 本地生成 dist / 站级同步(写要 site:write,默认 dry-run)',
|
|
416
430
|
lang: '站点语言:列表 / 新增或修改 / 设默认 / 删除 / 启用停用(写要 site:write,默认 dry-run)',
|
|
417
431
|
role: '站点角色:列表 / 新增或修改 / 删除(写要 role:write;不许造带「系统管理」权限的角色)',
|
|
418
432
|
member: '站点成员:列表(手机号掩码)/ 改角色 / 移出本站(只能管站点内角色,不建账号)',
|
package/lib/commands/init.mjs
CHANGED
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `init` 命令:把建站规范的**精简版**写进项目的四个「agent 启动即读」文件。
|
|
3
|
-
*
|
|
4
|
-
* ## 为什么是"写文件",不是"CLI 主动注入"
|
|
5
|
-
* agent 读什么是 **agent 自己的事**:DSH 读 `AGENTS.md`、Claude Code 读 `CLAUDE.md`、
|
|
6
|
-
* Cursor 读 `.cursorrules`、Copilot 读 `.github/copilot-instructions.md`。
|
|
7
|
-
* CLI 无法控制它读什么,能做的只有**把文件放到它该在的位置** —— 就是这条命令。
|
|
8
|
-
*
|
|
9
|
-
* ⚠️ CLI **不猜**调用者是哪个 agent:`process.env` 里没有可靠特征(`CLAUDECODE` / `CURSOR_*` /
|
|
10
|
-
* `DSH_*` 都可能缺失,用户也可能在任意 shell 里跑、或由别的工具当子进程调)。
|
|
11
|
-
* 所以默认**四个都写**,用 `--agents` 让用户自己挑。
|
|
12
|
-
*
|
|
13
|
-
* ## 幂等与"不动用户已有内容"
|
|
14
|
-
* * 写入内容用 `<!-- wkgeo:site-spec:begin -->` … `<!-- wkgeo:site-spec:end -->` 包起来;
|
|
15
|
-
* * 已有我们的标记 ⇒ **原地替换**(改规范后重跑不会重复追加);
|
|
16
|
-
* * 文件有内容但没有标记 ⇒ **只在末尾追加**,用户写的一个字不动;
|
|
17
|
-
* * 算出来一字节不差 ⇒ `unchanged`,不写盘。
|
|
18
|
-
*
|
|
19
|
-
* ## 默认 dry-run
|
|
20
|
-
* 与全 CLI 的写操作一致:不加 `--confirm` 只打计划(零写盘),`--confirm` 才真写。
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import path from 'node:path';
|
|
24
|
-
|
|
25
|
-
import { readSpecMarkdown, planAgentFiles, resolveAgentFiles, writeAgentFiles } from '../site-spec.mjs';
|
|
26
|
-
|
|
27
|
-
/** 人读模式下的动作词(JSON 里仍是 created / appended / replaced / unchanged) */
|
|
28
|
-
const ACTION_LABEL = {
|
|
29
|
-
created: '将新建',
|
|
30
|
-
appended: '已有内容 → 追加到末尾(用户内容不动)',
|
|
31
|
-
replaced: '已有规范段 → 原地替换',
|
|
32
|
-
unchanged: '内容没变 → 跳过',
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const initCommand = {
|
|
36
|
-
name: 'init',
|
|
37
|
-
summary: '把建站规范写进项目的 AGENTS.md / CLAUDE.md / .cursorrules / Copilot 指令(可重复跑)',
|
|
38
|
-
usage: 'wkgeo init [--agents all|none|<名单>] [--confirm] [--json]',
|
|
39
|
-
flags: {
|
|
40
|
-
agents: {
|
|
41
|
-
type: 'string',
|
|
42
|
-
desc: '写哪些约定文件:all(默认)/ none / 逗号分隔(agents,claude,cursor,copilot,也认 AGENTS.md 这类文件名)',
|
|
43
|
-
},
|
|
44
|
-
'dry-run': { type: 'boolean', desc: '只看计划不写盘(不加 --confirm 时本来就是 dry-run)' },
|
|
45
|
-
confirm: { type: 'boolean', desc: '真写盘(不加只打计划)' },
|
|
46
|
-
},
|
|
47
|
-
examples: [
|
|
48
|
-
'wkgeo init # 只看计划(零写盘)',
|
|
49
|
-
'wkgeo init --confirm # 四个约定文件都写 / 追加',
|
|
50
|
-
'wkgeo init --confirm --agents agents,claude # 只写 AGENTS.md 与 CLAUDE.md',
|
|
51
|
-
'wkgeo init --confirm --agents none # 一个都不写(等价于空跑)',
|
|
52
|
-
],
|
|
53
|
-
notes: [
|
|
54
|
-
'写的是建站规范的**精简版**(与 `wkgeo spec --agents` 逐字节相同);全文跑 `wkgeo spec`。',
|
|
55
|
-
'可重复跑:自己那一段用 `<!-- wkgeo:site-spec:begin/end -->` 包着,改规范后重跑会**原地替换**,不会重复追加。',
|
|
56
|
-
'**不覆盖用户内容**:文件已有你自己的内容时只在末尾追加我们这一段(文件里已有我们的段则只替换那一段)。',
|
|
57
|
-
'CLI 不判断你用的是哪个 agent,所以默认四个都写;用 `--agents` 可只写其中几个。',
|
|
58
|
-
'写完后让 agent **重新开一个会话 / 重新读一次**约定文件才会生效(多数 agent 只在会话开始时读)。',
|
|
59
|
-
],
|
|
60
|
-
async run(ctx) {
|
|
61
|
-
const { out, flags } = ctx;
|
|
62
|
-
const dir = process.cwd();
|
|
63
|
-
const info = readSpecMarkdown();
|
|
64
|
-
const files = resolveAgentFiles(flags.agents);
|
|
65
|
-
const plan = planAgentFiles({ dir, markdown: info.markdown, files });
|
|
66
|
-
|
|
67
|
-
/** JSON 里不回整份 content(可能几十 KB),只给动作 + 字节数 + 路径 */
|
|
68
|
-
const rows = plan.map((one) => ({
|
|
69
|
-
path: one.path,
|
|
70
|
-
abs_path: one.absPath,
|
|
71
|
-
label: one.label,
|
|
72
|
-
action: one.action,
|
|
73
|
-
existed: one.existed,
|
|
74
|
-
bytes: Buffer.byteLength(one.content, 'utf8'),
|
|
75
|
-
}));
|
|
76
|
-
|
|
77
|
-
const dryRun = flags.confirm !== true;
|
|
78
|
-
const writeResult = dryRun ? { written: [], skipped: rows.filter((r) => r.action === 'unchanged').map((r) => r.path) } : writeAgentFiles(plan);
|
|
79
|
-
const data = {
|
|
80
|
-
dir,
|
|
81
|
-
source: info.path,
|
|
82
|
-
dry_run: dryRun,
|
|
83
|
-
files: rows,
|
|
84
|
-
written: writeResult.written,
|
|
85
|
-
skipped: writeResult.skipped,
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
if (!out.json) {
|
|
89
|
-
out.head(dryRun ? `建站规范 → ${dir}(dry-run,零写盘)` : `建站规范 → ${dir}`);
|
|
90
|
-
for (const one of rows) {
|
|
91
|
-
const mark = one.action === 'unchanged' ? '·' : '+';
|
|
92
|
-
out.line(` ${mark} ${one.path.padEnd(32)} ${ACTION_LABEL[one.action] || one.action}(${one.bytes} 字节)`);
|
|
93
|
-
}
|
|
94
|
-
out.line('');
|
|
95
|
-
out.info(` 规范来源:${info.path}`);
|
|
96
|
-
out.info(' 全文:wkgeo spec | 只要这一段:wkgeo spec --agents');
|
|
97
|
-
if (files.length === 0) out.warn(' --agents none:没有要写的文件(空跑)。');
|
|
98
|
-
else if (dryRun) out.notice('\n这是 dry-run:加 --confirm 才真写盘。');
|
|
99
|
-
else out.ok(`已写 ${writeResult.written.length} 个文件,跳过 ${writeResult.skipped.length} 个(内容没变)。`);
|
|
100
|
-
out.info(' 提示:多数 agent 只在会话开始时读约定文件,写完请重开会话(或让它重新读一次)。');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
ctx.done(data);
|
|
104
|
-
return data;
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
/** 供单测直接拿目录解析口径(与命令层保持一致:永远用 cwd,不吃 --site 之类) */
|
|
109
|
-
export function resolveInitDir(cwd = process.cwd()) {
|
|
110
|
-
return path.resolve(String(cwd || process.cwd()));
|
|
111
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* `init` 命令:把建站规范的**精简版**写进项目的四个「agent 启动即读」文件。
|
|
3
|
+
*
|
|
4
|
+
* ## 为什么是"写文件",不是"CLI 主动注入"
|
|
5
|
+
* agent 读什么是 **agent 自己的事**:DSH 读 `AGENTS.md`、Claude Code 读 `CLAUDE.md`、
|
|
6
|
+
* Cursor 读 `.cursorrules`、Copilot 读 `.github/copilot-instructions.md`。
|
|
7
|
+
* CLI 无法控制它读什么,能做的只有**把文件放到它该在的位置** —— 就是这条命令。
|
|
8
|
+
*
|
|
9
|
+
* ⚠️ CLI **不猜**调用者是哪个 agent:`process.env` 里没有可靠特征(`CLAUDECODE` / `CURSOR_*` /
|
|
10
|
+
* `DSH_*` 都可能缺失,用户也可能在任意 shell 里跑、或由别的工具当子进程调)。
|
|
11
|
+
* 所以默认**四个都写**,用 `--agents` 让用户自己挑。
|
|
12
|
+
*
|
|
13
|
+
* ## 幂等与"不动用户已有内容"
|
|
14
|
+
* * 写入内容用 `<!-- wkgeo:site-spec:begin -->` … `<!-- wkgeo:site-spec:end -->` 包起来;
|
|
15
|
+
* * 已有我们的标记 ⇒ **原地替换**(改规范后重跑不会重复追加);
|
|
16
|
+
* * 文件有内容但没有标记 ⇒ **只在末尾追加**,用户写的一个字不动;
|
|
17
|
+
* * 算出来一字节不差 ⇒ `unchanged`,不写盘。
|
|
18
|
+
*
|
|
19
|
+
* ## 默认 dry-run
|
|
20
|
+
* 与全 CLI 的写操作一致:不加 `--confirm` 只打计划(零写盘),`--confirm` 才真写。
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import path from 'node:path';
|
|
24
|
+
|
|
25
|
+
import { readSpecMarkdown, planAgentFiles, resolveAgentFiles, writeAgentFiles } from '../site-spec.mjs';
|
|
26
|
+
|
|
27
|
+
/** 人读模式下的动作词(JSON 里仍是 created / appended / replaced / unchanged) */
|
|
28
|
+
const ACTION_LABEL = {
|
|
29
|
+
created: '将新建',
|
|
30
|
+
appended: '已有内容 → 追加到末尾(用户内容不动)',
|
|
31
|
+
replaced: '已有规范段 → 原地替换',
|
|
32
|
+
unchanged: '内容没变 → 跳过',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const initCommand = {
|
|
36
|
+
name: 'init',
|
|
37
|
+
summary: '把建站规范写进项目的 AGENTS.md / CLAUDE.md / .cursorrules / Copilot 指令(可重复跑)',
|
|
38
|
+
usage: 'wkgeo init [--agents all|none|<名单>] [--confirm] [--json]',
|
|
39
|
+
flags: {
|
|
40
|
+
agents: {
|
|
41
|
+
type: 'string',
|
|
42
|
+
desc: '写哪些约定文件:all(默认)/ none / 逗号分隔(agents,claude,cursor,copilot,也认 AGENTS.md 这类文件名)',
|
|
43
|
+
},
|
|
44
|
+
'dry-run': { type: 'boolean', desc: '只看计划不写盘(不加 --confirm 时本来就是 dry-run)' },
|
|
45
|
+
confirm: { type: 'boolean', desc: '真写盘(不加只打计划)' },
|
|
46
|
+
},
|
|
47
|
+
examples: [
|
|
48
|
+
'wkgeo init # 只看计划(零写盘)',
|
|
49
|
+
'wkgeo init --confirm # 四个约定文件都写 / 追加',
|
|
50
|
+
'wkgeo init --confirm --agents agents,claude # 只写 AGENTS.md 与 CLAUDE.md',
|
|
51
|
+
'wkgeo init --confirm --agents none # 一个都不写(等价于空跑)',
|
|
52
|
+
],
|
|
53
|
+
notes: [
|
|
54
|
+
'写的是建站规范的**精简版**(与 `wkgeo spec --agents` 逐字节相同);全文跑 `wkgeo spec`。',
|
|
55
|
+
'可重复跑:自己那一段用 `<!-- wkgeo:site-spec:begin/end -->` 包着,改规范后重跑会**原地替换**,不会重复追加。',
|
|
56
|
+
'**不覆盖用户内容**:文件已有你自己的内容时只在末尾追加我们这一段(文件里已有我们的段则只替换那一段)。',
|
|
57
|
+
'CLI 不判断你用的是哪个 agent,所以默认四个都写;用 `--agents` 可只写其中几个。',
|
|
58
|
+
'写完后让 agent **重新开一个会话 / 重新读一次**约定文件才会生效(多数 agent 只在会话开始时读)。',
|
|
59
|
+
],
|
|
60
|
+
async run(ctx) {
|
|
61
|
+
const { out, flags } = ctx;
|
|
62
|
+
const dir = process.cwd();
|
|
63
|
+
const info = readSpecMarkdown();
|
|
64
|
+
const files = resolveAgentFiles(flags.agents);
|
|
65
|
+
const plan = planAgentFiles({ dir, markdown: info.markdown, files });
|
|
66
|
+
|
|
67
|
+
/** JSON 里不回整份 content(可能几十 KB),只给动作 + 字节数 + 路径 */
|
|
68
|
+
const rows = plan.map((one) => ({
|
|
69
|
+
path: one.path,
|
|
70
|
+
abs_path: one.absPath,
|
|
71
|
+
label: one.label,
|
|
72
|
+
action: one.action,
|
|
73
|
+
existed: one.existed,
|
|
74
|
+
bytes: Buffer.byteLength(one.content, 'utf8'),
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
const dryRun = flags.confirm !== true;
|
|
78
|
+
const writeResult = dryRun ? { written: [], skipped: rows.filter((r) => r.action === 'unchanged').map((r) => r.path) } : writeAgentFiles(plan);
|
|
79
|
+
const data = {
|
|
80
|
+
dir,
|
|
81
|
+
source: info.path,
|
|
82
|
+
dry_run: dryRun,
|
|
83
|
+
files: rows,
|
|
84
|
+
written: writeResult.written,
|
|
85
|
+
skipped: writeResult.skipped,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
if (!out.json) {
|
|
89
|
+
out.head(dryRun ? `建站规范 → ${dir}(dry-run,零写盘)` : `建站规范 → ${dir}`);
|
|
90
|
+
for (const one of rows) {
|
|
91
|
+
const mark = one.action === 'unchanged' ? '·' : '+';
|
|
92
|
+
out.line(` ${mark} ${one.path.padEnd(32)} ${ACTION_LABEL[one.action] || one.action}(${one.bytes} 字节)`);
|
|
93
|
+
}
|
|
94
|
+
out.line('');
|
|
95
|
+
out.info(` 规范来源:${info.path}`);
|
|
96
|
+
out.info(' 全文:wkgeo spec | 只要这一段:wkgeo spec --agents');
|
|
97
|
+
if (files.length === 0) out.warn(' --agents none:没有要写的文件(空跑)。');
|
|
98
|
+
else if (dryRun) out.notice('\n这是 dry-run:加 --confirm 才真写盘。');
|
|
99
|
+
else out.ok(`已写 ${writeResult.written.length} 个文件,跳过 ${writeResult.skipped.length} 个(内容没变)。`);
|
|
100
|
+
out.info(' 提示:多数 agent 只在会话开始时读约定文件,写完请重开会话(或让它重新读一次)。');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
ctx.done(data);
|
|
104
|
+
return data;
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** 供单测直接拿目录解析口径(与命令层保持一致:永远用 cwd,不吃 --site 之类) */
|
|
109
|
+
export function resolveInitDir(cwd = process.cwd()) {
|
|
110
|
+
return path.resolve(String(cwd || process.cwd()));
|
|
111
|
+
}
|