@wkgeo/cli 1.1.0 → 1.1.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 +31 -0
- package/README.md +151 -19
- package/SKILL.md +108 -27
- package/lib/args.mjs +2 -2
- package/lib/asset-role.mjs +68 -0
- package/lib/cms.mjs +2 -2
- package/lib/commands/billing.mjs +56 -10
- package/lib/commands/cms.mjs +49 -13
- package/lib/commands/content.mjs +108 -0
- package/lib/commands/crawl.mjs +219 -0
- package/lib/commands/geo.mjs +1673 -0
- package/lib/commands/index.mjs +640 -541
- package/lib/commands/member.mjs +930 -0
- package/lib/commands/seo.mjs +1386 -0
- package/lib/commands/siteops.mjs +3 -3
- package/lib/commands/sites.mjs +21 -125
- package/lib/commands/template.mjs +1222 -6
- package/lib/config.mjs +16 -13
- package/lib/content-apply.mjs +664 -0
- package/lib/content-check.mjs +887 -0
- package/lib/content-contract.mjs +957 -0
- package/lib/errors.mjs +6 -0
- package/lib/format.mjs +5 -1
- package/lib/manifest-apply.mjs +1499 -0
- package/lib/manifest-schema.json +476 -0
- package/lib/manifest.mjs +1082 -0
- package/lib/oauth-urls.mjs +1 -1
- package/lib/runtime.mjs +5 -1
- package/lib/site-create.mjs +536 -0
- package/lib/template-anim.mjs +1338 -0
- package/lib/template-animation.mjs +232 -0
- package/lib/template-capture.mjs +700 -0
- package/lib/template-gen.mjs +1204 -0
- package/lib/template-pack.mjs +206 -0
- package/lib/template-publish.mjs +733 -0
- package/lib/template-score.mjs +865 -0
- package/lib/template-validate.mjs +368 -0
- package/lib/template-verify.mjs +434 -0
- package/lib/templates-sync.mjs +616 -0
- package/package.json +2 -2
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wkgeo template animation` —— 把模板/网址里的**动画与交互**结构化提取出来(运行时口径,CDP 采样)。
|
|
3
|
+
*
|
|
4
|
+
* ## 与 `template anim` 的区别(两条命令都要留着,别合并)
|
|
5
|
+
* * `template anim`(task-46 前一半,`cli/lib/template-anim.mjs`):**读源码**(正则扫 HTML/CSS/JS),
|
|
6
|
+
* 输出"映射到 `_base` 动效词汇"的清单 `design/animations.json`,给生成/对账用;
|
|
7
|
+
* * `template animation`(本文件):**开 headless Chrome 真跑页面**,从 CSSOM 原文 + DOM 结构采样,
|
|
8
|
+
* 输出 `wkgeo-anim-extract@1` —— keyframes / animations / transitions / scrollTriggers / reducedMotion
|
|
9
|
+
* + 质量三维原始值(layering / easing / rhythm)。源码里"写了但没生效"和被 `!important` 掐死的
|
|
10
|
+
* 规则,只有运行时口径才分得清。
|
|
11
|
+
*
|
|
12
|
+
* ## 为什么 spawn 一个脚本而不是 import
|
|
13
|
+
* `cli/` 是随 npm 包分发的独立目录,不能 `import '../../tools/...'`(装到别人机器上就没有 tools/)。
|
|
14
|
+
* 所以和 `template verify` → `compare.mjs` 一样:**找脚本 → spawn node → 读它写的 JSON**。
|
|
15
|
+
* 找不到脚本时**不假装成功**:exit 1 并写清楚缺什么(`--tool` / `WKGEO_ANIM_EXTRACT` 可以指路)。
|
|
16
|
+
*
|
|
17
|
+
* ## 退出码
|
|
18
|
+
* 工具自己的码原样透传:0 成功 / 1 采集中途失败 / 2 用法错(目录不存在、没有页面、参数不认识)。
|
|
19
|
+
* 命令层把 2 转成 `UsageError`(CLI 的 2),1 转成 `CliError`(CLI 的 1),错误原文不吞。
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import fs from 'node:fs';
|
|
23
|
+
import path from 'node:path';
|
|
24
|
+
import { spawn } from 'node:child_process';
|
|
25
|
+
import { fileURLToPath } from 'node:url';
|
|
26
|
+
|
|
27
|
+
import { CliError, UsageError, EXIT } from './errors.mjs';
|
|
28
|
+
|
|
29
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
30
|
+
|
|
31
|
+
export const EXTRACT_SCRIPT_REL = path.join('tools', 'render-compare', 'animation-extract.mjs');
|
|
32
|
+
export const ANIM_EXTRACT_FORMAT = 'wkgeo-anim-extract@1';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 找提取器脚本:显式 `--tool` > `WKGEO_ANIM_EXTRACT` > cwd 往上 8 层 > 本文件往上 8 层。
|
|
36
|
+
* 显式指定了却不存在 → 返回 null(不偷偷换成别的脚本,否则用户以为跑的是自己指的那个)。
|
|
37
|
+
*/
|
|
38
|
+
export function findExtractScript({ explicit = null, cwd = process.cwd(), env = process.env } = {}) {
|
|
39
|
+
const ok = (p) => {
|
|
40
|
+
try {
|
|
41
|
+
return !!p && fs.statSync(p).isFile();
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
if (explicit) return ok(explicit) ? path.resolve(explicit) : null;
|
|
47
|
+
if (env && env.WKGEO_ANIM_EXTRACT) return ok(env.WKGEO_ANIM_EXTRACT) ? path.resolve(env.WKGEO_ANIM_EXTRACT) : null;
|
|
48
|
+
for (const start of [cwd, HERE]) {
|
|
49
|
+
let dir = path.resolve(start);
|
|
50
|
+
for (let i = 0; i < 8; i++) {
|
|
51
|
+
const cand = path.join(dir, EXTRACT_SCRIPT_REL);
|
|
52
|
+
if (ok(cand)) return cand;
|
|
53
|
+
const parent = path.dirname(dir);
|
|
54
|
+
if (parent === dir) break;
|
|
55
|
+
dir = parent;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const EXTRACT_MISSING_MESSAGE =
|
|
62
|
+
'找不到动画提取器 `tools/render-compare/animation-extract.mjs`。\n' +
|
|
63
|
+
' 它随仓库分发(不在 npm 包里),请在仓库根目录跑,或用 `--tool <path>` 指定;\n' +
|
|
64
|
+
' 也可以设环境变量 `WKGEO_ANIM_EXTRACT` 指向该脚本。';
|
|
65
|
+
|
|
66
|
+
/** 跑一个 node 子进程,收集 stdout/stderr(超时就 kill,返回原因) */
|
|
67
|
+
function runNode(args, { cwd, timeoutMs = 300000 } = {}) {
|
|
68
|
+
return new Promise((resolve) => {
|
|
69
|
+
const child = spawn(process.execPath, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
|
|
70
|
+
let stdout = '';
|
|
71
|
+
let stderr = '';
|
|
72
|
+
let timedOut = false;
|
|
73
|
+
const timer = setTimeout(() => {
|
|
74
|
+
timedOut = true;
|
|
75
|
+
try {
|
|
76
|
+
child.kill();
|
|
77
|
+
} catch {
|
|
78
|
+
/* ignore */
|
|
79
|
+
}
|
|
80
|
+
}, timeoutMs);
|
|
81
|
+
child.stdout.on('data', (d) => (stdout += d.toString('utf8')));
|
|
82
|
+
child.stderr.on('data', (d) => (stderr += d.toString('utf8')));
|
|
83
|
+
child.on('error', (e) => {
|
|
84
|
+
clearTimeout(timer);
|
|
85
|
+
resolve({ code: -1, stdout, stderr: stderr + String(e.message), timedOut });
|
|
86
|
+
});
|
|
87
|
+
child.on('close', (code) => {
|
|
88
|
+
clearTimeout(timer);
|
|
89
|
+
resolve({ code, stdout, stderr, timedOut });
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 采一次动画提取。
|
|
96
|
+
*
|
|
97
|
+
* @param {object} o
|
|
98
|
+
* @param {string} o.dir 模板目录(或 `--url` 时的可选工作目录)
|
|
99
|
+
* @param {string} [o.url] 直接采线上页(只读)
|
|
100
|
+
* @param {string} [o.page] /pages/index.html;给 `--dir` 且不指定时默认首页
|
|
101
|
+
* @param {string[]}[o.pages] 只采这几页
|
|
102
|
+
* @param {string} [o.out] JSON 落盘路径(不传则写临时文件后删)
|
|
103
|
+
* @param {number} [o.virtualTimeBudget] 默认 4000(加载后静置的上限,见提取器头注释)
|
|
104
|
+
* @param {number} [o.seed]
|
|
105
|
+
* @param {string} [o.chrome]
|
|
106
|
+
* @param {string} [o.baseDir]
|
|
107
|
+
* @param {string} [o.toolPath]
|
|
108
|
+
* @returns {Promise<{json:object, outFile:string|null, script:string, elapsedMs:number, stderr:string}>}
|
|
109
|
+
*/
|
|
110
|
+
export async function extractAnimationsForCli({
|
|
111
|
+
dir = null,
|
|
112
|
+
url = null,
|
|
113
|
+
page = null,
|
|
114
|
+
pages = [],
|
|
115
|
+
out = null,
|
|
116
|
+
virtualTimeBudget = 4000,
|
|
117
|
+
seed = 0,
|
|
118
|
+
chrome = null,
|
|
119
|
+
baseDir = null,
|
|
120
|
+
maxPages = 0,
|
|
121
|
+
viewport = null,
|
|
122
|
+
toolPath = null,
|
|
123
|
+
cwd = process.cwd(),
|
|
124
|
+
env = process.env,
|
|
125
|
+
timeoutMs = 300000,
|
|
126
|
+
} = {}) {
|
|
127
|
+
const script = findExtractScript({ explicit: toolPath, cwd, env });
|
|
128
|
+
if (!script) throw new CliError(EXTRACT_MISSING_MESSAGE, { kind: 'usage', exitCode: EXIT.ERROR, hint: '在仓库根目录运行,或 --tool 指定脚本' });
|
|
129
|
+
if (!dir && !url) throw new UsageError('必须给 --dir <模板目录> 或 --url <网址>');
|
|
130
|
+
|
|
131
|
+
const args = [script];
|
|
132
|
+
if (url) args.push('--url', String(url));
|
|
133
|
+
if (dir) args.push('--dir', path.resolve(cwd, String(dir)));
|
|
134
|
+
if (page) args.push('--page', String(page));
|
|
135
|
+
for (const p of pages || []) args.push('--page', String(p));
|
|
136
|
+
if (out) args.push('--out', path.resolve(cwd, String(out)));
|
|
137
|
+
if (chrome) args.push('--chrome', path.resolve(cwd, String(chrome)));
|
|
138
|
+
if (baseDir) args.push('--base-dir', path.resolve(cwd, String(baseDir)));
|
|
139
|
+
if (Number(virtualTimeBudget) > 0) args.push('--virtual-time-budget', String(Math.round(Number(virtualTimeBudget))));
|
|
140
|
+
if (seed !== null && seed !== undefined && seed !== 0) args.push('--seed', String(seed));
|
|
141
|
+
if (Number(maxPages) > 0) args.push('--max-pages', String(Math.round(Number(maxPages))));
|
|
142
|
+
if (viewport && viewport.width > 0 && viewport.height > 0) args.push('--viewport', `${viewport.width}x${viewport.height}`);
|
|
143
|
+
args.push('--json');
|
|
144
|
+
|
|
145
|
+
const startedAt = Date.now();
|
|
146
|
+
const r = await runNode(args, { cwd, timeoutMs });
|
|
147
|
+
const elapsedMs = Date.now() - startedAt;
|
|
148
|
+
|
|
149
|
+
if (r.timedOut) {
|
|
150
|
+
throw new CliError(`动画提取超时(${Math.round(timeoutMs / 1000)}s):${script}`, {
|
|
151
|
+
kind: 'timeout',
|
|
152
|
+
code: 'ETIMEOUT',
|
|
153
|
+
exitCode: EXIT.ERROR,
|
|
154
|
+
hint: '换更小的范围(--page 单页)或调大超时',
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// 工具在 --json 模式下把整份 JSON 打到 stdout;解析失败说明它中途崩了 → 把 stderr 原文带出来
|
|
159
|
+
let json = null;
|
|
160
|
+
const text = String(r.stdout || '').trim();
|
|
161
|
+
if (text) {
|
|
162
|
+
try {
|
|
163
|
+
json = JSON.parse(text);
|
|
164
|
+
} catch {
|
|
165
|
+
json = null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (r.code === 2) {
|
|
170
|
+
const msg = (r.stderr || text || '').trim() || '参数不合法';
|
|
171
|
+
throw new UsageError(msg.replace(/^动画提取失败:/, ''), { hint: '`wkgeo template animation --help` 看用法' });
|
|
172
|
+
}
|
|
173
|
+
if (r.code !== 0) {
|
|
174
|
+
const msg = (r.stderr || '').trim() || text || `提取器退出码 ${r.code}`;
|
|
175
|
+
throw new CliError(`动画提取失败:${msg.replace(/^动画提取失败:/, '')}`, {
|
|
176
|
+
kind: 'extract',
|
|
177
|
+
code: 'EEXTRACT',
|
|
178
|
+
exitCode: EXIT.ERROR,
|
|
179
|
+
raw: { code: r.code, stderr: r.stderr, stdout: text.slice(0, 2000) },
|
|
180
|
+
hint: '看上面的原始错误;目录/页面/Chrome 三者任一不对都会被点名',
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if (!json) {
|
|
184
|
+
throw new CliError(`提取器 exit 0 但没输出可解析的 JSON(${text.length} 字节)`, {
|
|
185
|
+
kind: 'extract',
|
|
186
|
+
code: 'EJSON',
|
|
187
|
+
exitCode: EXIT.ERROR,
|
|
188
|
+
raw: { stdout: text.slice(0, 2000), stderr: r.stderr },
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return { json, outFile: out ? path.resolve(cwd, String(out)) : null, script, elapsedMs, stderr: r.stderr };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** 人读输出(`--text`):一眼看清 5 类计数 + 质量三维原始值(不下结论) */
|
|
195
|
+
export function printExtractSummary(out, json) {
|
|
196
|
+
const s = (json && json.summary) || {};
|
|
197
|
+
const q = (json && json.quality) || {};
|
|
198
|
+
const c = s.counts || {};
|
|
199
|
+
out.head(`动画提取 ${json.dir || json.url || ''}`);
|
|
200
|
+
const chrome = json.chrome && typeof json.chrome === 'object' ? json.chrome.version || json.chrome.product || '' : json.chrome;
|
|
201
|
+
out.line(` 页面 ${s.pages || 0} 个 · ${chrome ? `${String(chrome).replace(/^HeadlessChrome\//, 'Chrome/')}` : 'Chrome ?'}`);
|
|
202
|
+
out.line(
|
|
203
|
+
` 计数:keyframes ${c.keyframes || 0} · animations ${c.animations || 0} · transitions ${c.transitions || 0} · ` +
|
|
204
|
+
`scrollTriggers ${c.scrollTriggers || 0} · reducedMotion ${(c.reducedMotion && c.reducedMotion.pagesCovered) || 0}/${
|
|
205
|
+
(c.reducedMotion && c.reducedMotion.pagesTotal) || 0
|
|
206
|
+
} 页`
|
|
207
|
+
);
|
|
208
|
+
if (s.unique) {
|
|
209
|
+
out.line(
|
|
210
|
+
` 去重(站点级):keyframes ${s.unique.keyframes} · animations ${s.unique.animations} · transitions ${s.unique.transitions} · ` +
|
|
211
|
+
`scrollTriggers ${s.unique.scrollTriggers}`
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
const b = (s.duration && s.duration.buckets) || {};
|
|
215
|
+
out.line(` 时长:<150=${b['<150'] || 0} · 150-300=${b['150-300'] || 0} · 300-600=${b['300-600'] || 0} · >600=${b['>600'] || 0} · unknown=${b.unknown || 0}`);
|
|
216
|
+
const dist = (s.easing && s.easing.distribution) || {};
|
|
217
|
+
out.line(` easing:${Object.entries(dist).map(([k, v]) => `${k}=${v}`).join(' · ') || '(无)'}`);
|
|
218
|
+
for (const l of s.longest5 || []) out.line(` 最长:${l.durationMs}ms ${l.selector} ${l.name || ''}(${l.page})`);
|
|
219
|
+
if (q.layering) {
|
|
220
|
+
out.line(
|
|
221
|
+
` layering 同屏 ${q.layering.animationsSameViewport} 条动画 / ${q.layering.transitionsSameViewport} 个选择器在首屏有 transition / ` +
|
|
222
|
+
`入场层级 ${q.layering.entranceLadder && q.layering.entranceLadder.detected ? '有' : '无'}`
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
if (q.easing) out.line(` easing 自定义占比 ${q.easing.customRatio}%`);
|
|
226
|
+
if (q.rhythm) out.line(` rhythm 循环 ${q.rhythm.loopAnimations} 条`);
|
|
227
|
+
if (q.inputsComplete) out.line(` 体检输入:${q.inputsComplete.ok ? '齐备' : `缺 ${(q.inputsComplete.missing || []).length} 项 → ${(q.inputsComplete.missing || []).join('、')}`}`);
|
|
228
|
+
for (const p of s.perPage || []) {
|
|
229
|
+
const pc = p.counts || {};
|
|
230
|
+
out.line(` · ${p.page} kf ${pc.keyframes || 0} / anim ${pc.animations || 0} / tr ${pc.transitions || 0} / scroll ${pc.scrollTriggers || 0} / rm${p.reducedMotion ? '✓' : '✗'}`);
|
|
231
|
+
}
|
|
232
|
+
}
|