@wkgeo/cli 1.1.2 → 1.1.4
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 +40 -0
- package/README.md +66 -4
- package/SKILL.md +35 -2
- package/lib/api.mjs +14 -0
- package/lib/commands/cms.mjs +119 -3
- package/lib/commands/data.mjs +694 -0
- package/lib/commands/domainops.mjs +10 -10
- package/lib/commands/index.mjs +12 -0
- package/lib/commands/member.mjs +3 -1
- package/lib/commands/siteops.mjs +4 -3
- package/lib/commands/sites.mjs +3 -2
- package/lib/commands/template.mjs +2 -2
- package/lib/config.mjs +3 -2
- package/lib/hosts.mjs +37 -0
- package/lib/manifest-apply.mjs +103 -2
- package/lib/manifest-schema.json +4 -0
- package/lib/manifest.mjs +25 -1
- package/lib/site-create.mjs +6 -4
- package/lib/template-anim.mjs +5 -5
- package/lib/template-gen.mjs +56 -13
- package/lib/template-pack.mjs +2 -2
- package/lib/template-publish.mjs +7 -2
- package/lib/template-validate.mjs +15 -9
- package/lib/template-verify.mjs +1 -1
- package/package.json +1 -1
package/lib/template-gen.mjs
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* from-dir 是同一套流程换成本地静态目录:读本地 HTML、把被引用的本地资源收进 `assets/`、
|
|
13
13
|
* 反过来从 `<nav>` / `<title>` / 卡片标题推出 v2 `template.json`(栏目 / 菜单 / 字段 / 演示数据)。
|
|
14
14
|
*
|
|
15
|
-
* ## 产出(v2 口径,见 templates/
|
|
15
|
+
* ## 产出(v2 口径,见 templates/base/README.md §3 §4)
|
|
16
16
|
* ```
|
|
17
17
|
* <out>/
|
|
18
18
|
* template.json _format=wkgeo-template@2 / key / site / menus / columns / requires / data
|
|
@@ -31,6 +31,7 @@ import crypto from 'node:crypto';
|
|
|
31
31
|
import { fileURLToPath } from 'node:url';
|
|
32
32
|
|
|
33
33
|
import { CliError, UsageError } from './errors.mjs';
|
|
34
|
+
import { PLATFORM_WEB_ORIGIN } from './hosts.mjs';
|
|
34
35
|
import { VIEWPORTS, captureDesign, inspectDesign, resolveChrome } from './template-capture.mjs';
|
|
35
36
|
|
|
36
37
|
export const TEMPLATE_FORMAT = 'wkgeo-template@2';
|
|
@@ -158,7 +159,7 @@ export function normalizeSiteUrl(input) {
|
|
|
158
159
|
return u;
|
|
159
160
|
}
|
|
160
161
|
|
|
161
|
-
const UA =
|
|
162
|
+
const UA = `wkgeo-cli-template/1.0 (+${PLATFORM_WEB_ORIGIN})`;
|
|
162
163
|
|
|
163
164
|
async function fetchBuffer(url, { fetchImpl, timeoutMs = 30000, referer = null } = {}) {
|
|
164
165
|
const f = fetchImpl || globalThis.fetch;
|
|
@@ -205,28 +206,37 @@ function wrapFetchError(url, err, timeoutMs) {
|
|
|
205
206
|
return new CliError(`抓取失败:${url}\n 原因:${msg}\n ${hint}`, { kind: 'fetch', code: 'EFETCH', cause: err });
|
|
206
207
|
}
|
|
207
208
|
|
|
208
|
-
// ----------------------------------------------------------------
|
|
209
|
+
// ---------------------------------------------------------------- 定位基础库
|
|
209
210
|
|
|
210
211
|
/**
|
|
211
|
-
*
|
|
212
|
+
* 找基础库宿主目录(只读引用):显式参数 > 环境变量 > 从 cwd 往上找 > 从本文件往上找。
|
|
213
|
+
*
|
|
214
|
+
* 2026-11-09 起基础库并入**模板 `templates/base/assets/`**(老板:"`_base` 不应该有,
|
|
215
|
+
* 他就是 base 的 assets 里的 js css")。老结构 `templates/_base/` 已删除,但这里仍保留
|
|
216
|
+
* 一档回落,避免有人从旧分支/旧分发目录里跑命令时直接崩。
|
|
212
217
|
* 找不到就返回 null(validate 会降级为"只查 assets/base 存在")。
|
|
213
218
|
*/
|
|
214
219
|
export function resolveBaseDir(explicit, { cwd = process.cwd(), env = process.env } = {}) {
|
|
215
|
-
const ok = (dir) => dir && fs.existsSync(path.join(dir, 'assets', 'base.css'));
|
|
220
|
+
const ok = (dir) => dir && fs.existsSync(path.join(dir, 'assets', 'base.css')) && fs.existsSync(path.join(dir, 'components.json'));
|
|
221
|
+
const candidates = ['templates/base', path.join('templates', '_base')];
|
|
216
222
|
if (ok(explicit)) return path.resolve(explicit);
|
|
217
223
|
if (ok(env.WKGEO_BASE_TEMPLATE)) return path.resolve(env.WKGEO_BASE_TEMPLATE);
|
|
218
224
|
let dir = path.resolve(cwd);
|
|
219
225
|
for (let i = 0; i < 8; i++) {
|
|
220
|
-
const
|
|
221
|
-
|
|
226
|
+
for (const rel of candidates) {
|
|
227
|
+
const cand = path.join(dir, rel);
|
|
228
|
+
if (ok(cand)) return cand;
|
|
229
|
+
}
|
|
222
230
|
const parent = path.dirname(dir);
|
|
223
231
|
if (parent === dir) break;
|
|
224
232
|
dir = parent;
|
|
225
233
|
}
|
|
226
234
|
dir = HERE;
|
|
227
235
|
for (let i = 0; i < 8; i++) {
|
|
228
|
-
const
|
|
229
|
-
|
|
236
|
+
for (const rel of candidates) {
|
|
237
|
+
const cand = path.join(dir, rel);
|
|
238
|
+
if (ok(cand)) return cand;
|
|
239
|
+
}
|
|
230
240
|
const parent = path.dirname(dir);
|
|
231
241
|
if (parent === dir) break;
|
|
232
242
|
dir = parent;
|
|
@@ -234,14 +244,47 @@ export function resolveBaseDir(explicit, { cwd = process.cwd(), env = process.en
|
|
|
234
244
|
return null;
|
|
235
245
|
}
|
|
236
246
|
|
|
237
|
-
/**
|
|
247
|
+
/**
|
|
248
|
+
* 基础库里**属于库**的文件(相对 `<基础库目录>/assets/` 的路径)。
|
|
249
|
+
* `style.css` / `page.css` 是 `templates/base/` **自己的皮肤**,与库文件同住在 assets/ 下,
|
|
250
|
+
* 同步到别的模板时必须排除(它们不是"所有模板都该有"的东西)。
|
|
251
|
+
*/
|
|
252
|
+
const BASE_LIB_SKIN_FILES = new Set(['style.css', 'page.css']);
|
|
253
|
+
|
|
254
|
+
/** 递归列出基础库 assets 下要同步的文件(相对路径,posix 风格) */
|
|
255
|
+
export function listBaseAssetFiles(baseDir) {
|
|
256
|
+
const root = path.join(baseDir, 'assets');
|
|
257
|
+
const out = [];
|
|
258
|
+
const walk = (rel) => {
|
|
259
|
+
for (const ent of fs.readdirSync(path.join(root, rel), { withFileTypes: true })) {
|
|
260
|
+
const childRel = rel ? `${rel}/${ent.name}` : ent.name;
|
|
261
|
+
if (ent.isDirectory()) {
|
|
262
|
+
walk(childRel);
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if (!rel && BASE_LIB_SKIN_FILES.has(ent.name)) continue;
|
|
266
|
+
out.push(childRel);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
walk('');
|
|
270
|
+
return out.sort();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** `assets/base/` = 基础库 `templates/base/assets/` 的逐字节副本(不含宿主模板的皮肤文件) */
|
|
238
274
|
export async function syncBaseAssets(outDir, baseDir) {
|
|
239
275
|
const dest = path.join(outDir, 'assets', 'base');
|
|
240
|
-
if (!baseDir)
|
|
276
|
+
if (!baseDir) {
|
|
277
|
+
return { copied: false, reason: '没找到基础库(templates/base/assets 或老的 templates/_base)——跳过 assets/base 同步' };
|
|
278
|
+
}
|
|
241
279
|
await fsp.mkdir(path.dirname(dest), { recursive: true });
|
|
242
280
|
await fsp.rm(dest, { recursive: true, force: true });
|
|
243
|
-
|
|
244
|
-
|
|
281
|
+
const list = listBaseAssetFiles(baseDir);
|
|
282
|
+
for (const rel of list) {
|
|
283
|
+
const to = path.join(dest, ...rel.split('/'));
|
|
284
|
+
await fsp.mkdir(path.dirname(to), { recursive: true });
|
|
285
|
+
await fsp.copyFile(path.join(baseDir, 'assets', ...rel.split('/')), to);
|
|
286
|
+
}
|
|
287
|
+
return { copied: true, from: path.join(baseDir, 'assets'), to: dest, files: list.length };
|
|
245
288
|
}
|
|
246
289
|
|
|
247
290
|
const PLACEHOLDER_SVG =
|
package/lib/template-pack.mjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* UTF-8 文件名标志位 0x0800、中央目录齐全),解压工具(PowerShell Expand-Archive / 7-Zip)都认。
|
|
8
8
|
*
|
|
9
9
|
* ## 打包前
|
|
10
|
-
* 1. 把 `templates/
|
|
10
|
+
* 1. 把 `templates/base/assets/**` **逐字节**同步进 `<模板>/assets/base/`(§3 基础库同步规则);
|
|
11
11
|
* 2. 跑 9 关校验(`template-validate.mjs`),**不合格不出包**(exit 1)。
|
|
12
12
|
*
|
|
13
13
|
* 包内结构:`template.json`、`pages/`、`partials/`、`assets/`(含 `assets/base/`)、`design/`。
|
|
@@ -161,7 +161,7 @@ export async function packTemplate({ dir, out = null, base = null, cwd = process
|
|
|
161
161
|
// 1) 基础库逐字节同步
|
|
162
162
|
const baseDir = resolveBaseDir(base, { cwd });
|
|
163
163
|
const baseSync = await syncBaseAssets(root, baseDir);
|
|
164
|
-
if (!baseSync.copied) say(`!
|
|
164
|
+
if (!baseSync.copied) say(`! 没找到基础库(templates/base/assets):${baseSync.reason}`);
|
|
165
165
|
|
|
166
166
|
// 2) 9 关校验(不合格不出包)
|
|
167
167
|
say('跑 9 关校验…');
|
package/lib/template-publish.mjs
CHANGED
|
@@ -26,6 +26,7 @@ import path from 'node:path';
|
|
|
26
26
|
import crypto from 'node:crypto';
|
|
27
27
|
|
|
28
28
|
import { CliError } from './errors.mjs';
|
|
29
|
+
import { PLATFORM_WEB_ORIGIN } from './hosts.mjs';
|
|
29
30
|
|
|
30
31
|
/** 市场表(发布上游:模板市场) */
|
|
31
32
|
export const MARKET_TABLE = 'public.cms_template_market';
|
|
@@ -43,7 +44,11 @@ const MIME = {
|
|
|
43
44
|
'.js': 'application/javascript; charset=utf-8',
|
|
44
45
|
};
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
/**
|
|
48
|
+
* 模板母版落点桶(可用 `OSS_BUCKET` 覆盖)。
|
|
49
|
+
* 2026-11-11(t180 切桶):`wkgeocom` → `wkgeo-cn`(旧桶只读保留,删桶前必须切走)。
|
|
50
|
+
*/
|
|
51
|
+
const DEFAULT_BUCKET = 'wkgeo-cn';
|
|
47
52
|
const DEFAULT_REGION = 'oss-cn-shanghai';
|
|
48
53
|
|
|
49
54
|
const mimeOf = (rel) => MIME[path.extname(rel).toLowerCase()] || 'application/octet-stream';
|
|
@@ -637,7 +642,7 @@ export async function publishTemplate({
|
|
|
637
642
|
}
|
|
638
643
|
let previewCheck = null;
|
|
639
644
|
if (preview) {
|
|
640
|
-
const url =
|
|
645
|
+
const url = `${PLATFORM_WEB_ORIGIN}/cms/template/preview?key=${encodeURIComponent(collected.key)}&device=desktop`;
|
|
641
646
|
try {
|
|
642
647
|
const res = await fetchImpl(url, { method: 'GET', redirect: 'follow' });
|
|
643
648
|
const body = Buffer.from(await res.arrayBuffer());
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 模板校验(9 关)——`wkgeo template validate` 与 `pack` 共用同一套门禁。
|
|
3
3
|
*
|
|
4
|
-
* 口径来源:`templates/
|
|
4
|
+
* 口径来源:`templates/base/README.md` §1(12 种字段类型 / 8 个字段键)、§3(目录约定)、
|
|
5
5
|
* §4(v2 字段表)、§5(禁止事项)。**这里不另创规则**,每条门禁都能指回 README 的哪一节。
|
|
6
6
|
*
|
|
7
7
|
* 9 关:
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* 4. menus menus.top 非空,项字段与 menu_type/link_type 枚举合法(§1)
|
|
12
12
|
* 5. columns ≥1 个栏目;12 个栏键齐全;fields 8 键齐全且 type ∈ 12 种;items 与 fields 对齐(§1 §4)
|
|
13
13
|
* 6. pages pages/index.html 存在;columns[].page 都有对应文件;每页有 <title>(§3)
|
|
14
|
-
* 7. base assets/base/
|
|
14
|
+
* 7. base assets/base/ 存在,且能找到基础库(`templates/base/assets/`)时逐字节一致(§3)
|
|
15
15
|
* 8. links 页面引用的本地 CSS/JS/图片都在;资源类标签不得走外网(§5.2)
|
|
16
16
|
* 9. design design/desktop-1440.png 与 mobile-375.png 尺寸正确(t0/t1500 帧可选但建议有)
|
|
17
17
|
*/
|
|
@@ -23,7 +23,7 @@ import path from 'node:path';
|
|
|
23
23
|
import { CliError, EXIT } from './errors.mjs';
|
|
24
24
|
import { readPngSize } from './template-capture.mjs';
|
|
25
25
|
import { VIEWPORTS } from './template-capture.mjs';
|
|
26
|
-
import { TEMPLATE_FORMAT, resolveBaseDir } from './template-gen.mjs';
|
|
26
|
+
import { TEMPLATE_FORMAT, resolveBaseDir, listBaseAssetFiles } from './template-gen.mjs';
|
|
27
27
|
|
|
28
28
|
export const FIELD_TYPES = ['text', 'textarea', 'richtext', 'image', 'gallery', 'date', 'number', 'select', 'link', 'phone', 'email', 'boolean'];
|
|
29
29
|
export const FIELD_KEYS = ['key', 'label', 'type', 'required', 'options', 'group', 'sort', 'hint'];
|
|
@@ -47,12 +47,13 @@ async function walkFiles(root, out = [], skip = new Set(['node_modules', '.git']
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/** 逐字节比较两个目录(相对路径集合 + 每个文件内容) */
|
|
50
|
-
export async function compareTrees(a, b) {
|
|
50
|
+
export async function compareTrees(a, b, opts = {}) {
|
|
51
|
+
const only = opts.only instanceof Set ? opts.only : Array.isArray(opts.only) ? new Set(opts.only) : null;
|
|
51
52
|
const fa = await walkFiles(a);
|
|
52
53
|
const fb = await walkFiles(b);
|
|
53
54
|
const rel = (root, list) => new Map(list.map((f) => [path.relative(root, f).replace(/\\/g, '/'), f]));
|
|
54
|
-
const ma = rel(a, fa);
|
|
55
|
-
const mb = rel(b, fb);
|
|
55
|
+
const ma = new Map([...rel(a, fa)].filter(([k]) => !only || only.has(k)));
|
|
56
|
+
const mb = new Map([...rel(b, fb)].filter(([k]) => !only || only.has(k)));
|
|
56
57
|
const missing = [...ma.keys()].filter((k) => !mb.has(k));
|
|
57
58
|
const extra = [...mb.keys()].filter((k) => !ma.has(k));
|
|
58
59
|
const different = [];
|
|
@@ -270,11 +271,16 @@ export async function validateTemplate({ dir, base = null, cwd = process.cwd(),
|
|
|
270
271
|
const dest = path.join(root, 'assets', 'base');
|
|
271
272
|
const baseDir = resolveBaseDir(base, { cwd });
|
|
272
273
|
if (!fs.existsSync(dest)) {
|
|
273
|
-
errors.push('缺少 assets/base/(应从 templates/
|
|
274
|
+
errors.push('缺少 assets/base/(应从 templates/base/assets 逐字节复制)');
|
|
274
275
|
} else if (!fs.existsSync(path.join(dest, 'base.css'))) {
|
|
275
276
|
errors.push('assets/base/ 里没有 base.css');
|
|
276
277
|
} else if (baseDir) {
|
|
277
|
-
|
|
278
|
+
/**
|
|
279
|
+
* 只比**库文件**:2026-11-09 起基础库住在 `templates/base/assets/`,同目录里还躺着
|
|
280
|
+
* base 模板自己的皮肤 `style.css`(不是库文件、别的模板不该有),所以按
|
|
281
|
+
* `listBaseAssetFiles()` 给的清单逐字节比,不整目录比。
|
|
282
|
+
*/
|
|
283
|
+
const cmp = await compareTrees(path.join(baseDir, 'assets'), dest, { only: listBaseAssetFiles(baseDir) });
|
|
278
284
|
if (!cmp.ok) {
|
|
279
285
|
const bits = [];
|
|
280
286
|
if (cmp.missing.length) bits.push(`缺 ${cmp.missing.length} 个(${cmp.missing.slice(0, 3).join(', ')})`);
|
|
@@ -283,7 +289,7 @@ export async function validateTemplate({ dir, base = null, cwd = process.cwd(),
|
|
|
283
289
|
errors.push(`assets/base/ 与 ${baseDir}/assets 不是逐字节副本:${bits.join(';')}`);
|
|
284
290
|
}
|
|
285
291
|
} else {
|
|
286
|
-
warnings.push('
|
|
292
|
+
warnings.push('没找到基础库(templates/base/assets),只校验了 assets/base 的存在性');
|
|
287
293
|
}
|
|
288
294
|
add('base', 'assets/base 基础库副本', errors, warnings);
|
|
289
295
|
}
|
package/lib/template-verify.mjs
CHANGED
|
@@ -229,7 +229,7 @@ export async function verifyTemplate({
|
|
|
229
229
|
|
|
230
230
|
const chrome = resolveChrome(chromeExe);
|
|
231
231
|
const baseDir = resolveBaseDir(null, {});
|
|
232
|
-
if (!baseDir) say('
|
|
232
|
+
if (!baseDir) say('提示:没找到基础库 templates/base/assets(不影响比对)');
|
|
233
233
|
|
|
234
234
|
const out =
|
|
235
235
|
outDir ||
|