@wkgeo/cli 1.1.3 → 1.1.5
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 +35 -0
- package/README.md +64 -3
- package/SKILL.md +35 -2
- package/lib/api.mjs +28 -1
- package/lib/commands/cms.mjs +2 -2
- package/lib/commands/data.mjs +694 -0
- package/lib/commands/domainops.mjs +11 -11
- package/lib/commands/index.mjs +13 -1
- package/lib/commands/member.mjs +104 -49
- package/lib/commands/orders.mjs +27 -1
- package/lib/commands/siteops.mjs +1 -1
- package/lib/commands/sites.mjs +0 -1
- package/lib/commands/template.mjs +10 -0
- package/lib/errors.mjs +31 -0
- package/lib/manifest-apply.mjs +103 -2
- package/lib/manifest-schema.json +4 -0
- package/lib/manifest.mjs +23 -0
- package/lib/site-create.mjs +1 -2
- package/lib/template-publish.mjs +5 -1
- package/lib/templates-sync.mjs +51 -23
- package/package.json +1 -1
package/lib/manifest-apply.mjs
CHANGED
|
@@ -53,6 +53,8 @@ import {
|
|
|
53
53
|
const PUBLISH_POLL_MS = 2000;
|
|
54
54
|
/** 素材列表翻页上限(每页 100 × N 桶) */
|
|
55
55
|
const ASSET_PAGE_CAP = 5;
|
|
56
|
+
/** 首页栏目 slug(与后台 `isHomeCategorySlug` 同一口径:首页永远进导航) */
|
|
57
|
+
const HOME_SLUGS = new Set(['home', 'index']);
|
|
56
58
|
|
|
57
59
|
/** task-95:建站模式(与三条云上链路同一口径:默认 optimize) */
|
|
58
60
|
const BUILD_MODES = ['optimize', 'origin_copy'];
|
|
@@ -636,8 +638,70 @@ function createApplyEngine({ ctx, site, manifest, itemErrors, warnings, dryRun }
|
|
|
636
638
|
}
|
|
637
639
|
|
|
638
640
|
/* ── 栏目 ─────────────────────────────────────────────────── */
|
|
641
|
+
|
|
642
|
+
/** 本次清单 `menus[]` 声明的导航 path(懒算一次;`menus[]` 是导航唯一真相) */
|
|
643
|
+
let navPathsMemo = null;
|
|
644
|
+
function navPaths() {
|
|
645
|
+
if (!navPathsMemo) {
|
|
646
|
+
navPathsMemo = new Set();
|
|
647
|
+
for (const one of flattenMenus(manifest.menus)) {
|
|
648
|
+
const p = normalizePath(one.path);
|
|
649
|
+
if (p) navPathsMemo.add(p);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
return navPathsMemo;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* 这个栏目该不该进前台导航(老板 2026-11-13 口径:「首页板块一律用隐藏栏目承载」)。
|
|
657
|
+
*
|
|
658
|
+
* @returns {true|false|undefined} `undefined` = 本次**不动**导航字段(老清单:没写 `inMenu`、
|
|
659
|
+
* 也没声明 `menus[]` ⇒ 服务端默认 true,行为与改造前完全一致)。
|
|
660
|
+
*
|
|
661
|
+
* 判定顺序(`menus[]` 是导航唯一真相,`categories[].inMenu` 只是补充):
|
|
662
|
+
* 1. 在 `menus[]` 里 ⇒ `true`(老的显式导航行为不变);同时又写 `inMenu:false` ⇒ 按导航为准并告警;
|
|
663
|
+
* 2. 不在 `menus[]` 里、显式 `inMenu:false` ⇒ `false`(首页板块 / 隐藏栏目);
|
|
664
|
+
* 3. 不在 `menus[]` 里、显式 `inMenu:true` ⇒ `true`(清单没声明导航时也能手动进导航);
|
|
665
|
+
* 4. 没写 `inMenu`、但清单**声明了**导航 ⇒ `false`(没被导航引用就不进导航);
|
|
666
|
+
* 5. 没写 `inMenu`、清单也没有 `menus[]` ⇒ `undefined`(老行为,不碰)。
|
|
667
|
+
*/
|
|
668
|
+
function navStateOf(cat, catPath) {
|
|
669
|
+
const nav = navPaths();
|
|
670
|
+
const p = normalizePath(catPath);
|
|
671
|
+
const inNav = nav.size > 0 && Boolean(p) && nav.has(p);
|
|
672
|
+
if (inNav) {
|
|
673
|
+
if (cat.inMenu === false) {
|
|
674
|
+
warnings.push({
|
|
675
|
+
path: `categories.${cat.slug}.inMenu`,
|
|
676
|
+
message: '写了 inMenu:false,但它出现在 menus[] 里 —— 按导航为准(进导航);要隐藏就从 menus[] 里去掉',
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
return true;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* 首页永远进导航:`menus[].path` 的契约是 `/xxx/`,**写不出 `/`**
|
|
683
|
+
* (JSON Schema `^/[a-z0-9]...` + 校验都拦),所以「不在 menus[] 里」对首页没有意义。
|
|
684
|
+
* 判据与后台一致:slug = `home` / `index`(服务端 `isHomeCategorySlug`)或 path 为 `/`。
|
|
685
|
+
*/
|
|
686
|
+
if (nav.size > 0 && (p === '/' || HOME_SLUGS.has(String(cat.slug || '').toLowerCase()))) return true;
|
|
687
|
+
if (cat.inMenu === false) return false;
|
|
688
|
+
if (cat.inMenu === true) return true;
|
|
689
|
+
return nav.size > 0 ? false : undefined;
|
|
690
|
+
}
|
|
691
|
+
|
|
639
692
|
async function stageCategories() {
|
|
640
693
|
const entries = [];
|
|
694
|
+
/**
|
|
695
|
+
* 映射判据(`site-mapping-contract.mjs`):manifest 的 `type` 落成哪个 `kind` 由它一处说了算。
|
|
696
|
+
* 加载不到(npm 包里没有 `aliyun/` 目录)⇒ `null`,退回 `cat.kind`,行为与改造前一致。
|
|
697
|
+
*
|
|
698
|
+
* ⚠️ 原来这里只有 `const mapped = contract ? … : null`,**`contract` 从没赋值过** ⇒ 只要有
|
|
699
|
+
* `categories[]` 就抛 `ReferenceError: contract is not defined`(`content apply` 一直是坏的;
|
|
700
|
+
* 之前没有用例覆盖「apply 带栏目」,所以没被发现)。这一行是补上的加载点。
|
|
701
|
+
*/
|
|
702
|
+
const contract = await loadSiteMappingContract();
|
|
703
|
+
/** 本次按口径落成隐藏的栏目(集中一条告警,免得刷屏) */
|
|
704
|
+
const hidden = [];
|
|
641
705
|
for (const cat of sortCategoriesForApply(manifest.categories)) {
|
|
642
706
|
const item = `category:${cat.slug}`;
|
|
643
707
|
if (blocked.has(item)) continue;
|
|
@@ -690,6 +754,9 @@ function createApplyEngine({ ctx, site, manifest, itemErrors, warnings, dryRun }
|
|
|
690
754
|
const kind = mapped ? mapped.kind : cat.kind;
|
|
691
755
|
/** 模板绑定先过契约(计划期就定下来:不合法 ⇒ 空串 + 一条 ⚠,创建 / 更新两条分支共用) */
|
|
692
756
|
const templateFile = await resolveManifestTemplateFile(cat, kind);
|
|
757
|
+
/** 导航归属:true / false / undefined(undefined = 本次不动,老行为) */
|
|
758
|
+
const inMenu = navStateOf(cat, wantPath);
|
|
759
|
+
if (inMenu === false) hidden.push(cat.name);
|
|
693
760
|
|
|
694
761
|
if (!existing) {
|
|
695
762
|
const entry = {
|
|
@@ -698,7 +765,7 @@ function createApplyEngine({ ctx, site, manifest, itemErrors, warnings, dryRun }
|
|
|
698
765
|
planned: 'create',
|
|
699
766
|
action: 'create',
|
|
700
767
|
label,
|
|
701
|
-
detail: `新建栏目(${kind})${templateFile ? ` 模板 ${templateFile}` : ''}`,
|
|
768
|
+
detail: `新建栏目(${kind}${inMenu === false ? ',不进导航' : ''})${templateFile ? ` 模板 ${templateFile}` : ''}`,
|
|
702
769
|
};
|
|
703
770
|
entry.run = async (row) => {
|
|
704
771
|
const payload = { name: cat.name, slug: cat.slug, kind, sort: cat.sort };
|
|
@@ -710,6 +777,11 @@ function createApplyEngine({ ctx, site, manifest, itemErrors, warnings, dryRun }
|
|
|
710
777
|
if (cat.description) payload.description = cat.description;
|
|
711
778
|
if (cat.seoDescription) payload.seo_description = cat.seoDescription;
|
|
712
779
|
if (cat.seoKeywords) payload.seo_keywords = cat.seoKeywords;
|
|
780
|
+
/**
|
|
781
|
+
* 关键:**建的时候就带上导航归属**。以前这里没有 `in_menu`,服务端默认 true,
|
|
782
|
+
* 于是「首页·XXX」建完就挂在导航里,只能事后手动 `categories update --no-in-menu` 补。
|
|
783
|
+
*/
|
|
784
|
+
if (inMenu !== undefined) payload.in_menu = inMenu;
|
|
713
785
|
const saved = await call('categorySave', payload);
|
|
714
786
|
let id = String((saved && (saved.id || saved.categoryId)) || '');
|
|
715
787
|
if (!id) {
|
|
@@ -743,6 +815,8 @@ function createApplyEngine({ ctx, site, manifest, itemErrors, warnings, dryRun }
|
|
|
743
815
|
description: cat.description,
|
|
744
816
|
seoDescription: cat.seoDescription,
|
|
745
817
|
seoKeywords: cat.seoKeywords,
|
|
818
|
+
/** 已有栏目也按同一口径纠正导航归属(以前只摘「不在清单里」的,清单内的永远留在导航) */
|
|
819
|
+
inMenu,
|
|
746
820
|
});
|
|
747
821
|
state.catIdBySlug.set(cat.slug, {
|
|
748
822
|
id: String(existing.id),
|
|
@@ -762,6 +836,14 @@ function createApplyEngine({ ctx, site, manifest, itemErrors, warnings, dryRun }
|
|
|
762
836
|
};
|
|
763
837
|
entries.push(entry);
|
|
764
838
|
}
|
|
839
|
+
if (hidden.length) {
|
|
840
|
+
warnings.push({
|
|
841
|
+
path: 'categories',
|
|
842
|
+
message:
|
|
843
|
+
`${hidden.length} 个栏目不在 menus[] 里,按口径落成隐藏栏目(in_menu=false):${hidden.join('、')}` +
|
|
844
|
+
' —— 要进导航就把它们写进 menus[]',
|
|
845
|
+
});
|
|
846
|
+
}
|
|
765
847
|
return entries;
|
|
766
848
|
}
|
|
767
849
|
|
|
@@ -991,6 +1073,13 @@ function createApplyEngine({ ctx, site, manifest, itemErrors, warnings, dryRun }
|
|
|
991
1073
|
async function stageMenus() {
|
|
992
1074
|
const entries = [];
|
|
993
1075
|
const flat = flattenMenus(manifest.menus);
|
|
1076
|
+
/**
|
|
1077
|
+
* 清单没写 `menus[]` ⇒ **本次不动导航**(老清单行为不变)。
|
|
1078
|
+
*
|
|
1079
|
+
* 注意这里**不再**兜底「把清单里的栏目摘出导航」:清单内的导航归属在 `stageCategories`
|
|
1080
|
+
* 里按 `menus[]` 一次定好(见 `navStateOf`:没被引用 ⇒ 建的时候就是 `in_menu=false`)。
|
|
1081
|
+
* 如果在这里再摘一遍,没有 `menus[]` 的老清单会连整站导航一起被摘空(以前正是这么绕开的)。
|
|
1082
|
+
*/
|
|
994
1083
|
if (!flat.length) return entries;
|
|
995
1084
|
if (!dryRun) {
|
|
996
1085
|
/* 栏目阶段可能刚建出一批:落库后以服务端为准重建 path 索引(服务端算 path,本地不猜) */
|
|
@@ -1045,9 +1134,16 @@ function createApplyEngine({ ctx, site, manifest, itemErrors, warnings, dryRun }
|
|
|
1045
1134
|
for (const row of state.cats) {
|
|
1046
1135
|
if (row.builtin === true) continue;
|
|
1047
1136
|
if (row.in_menu !== true) continue;
|
|
1048
|
-
|
|
1137
|
+
/**
|
|
1138
|
+
* 清单里的栏目:导航归属已由 `stageCategories` 按 `menus[]` 决定(建/改时带 `in_menu`),
|
|
1139
|
+
* 这里再摘一次只会多出一条重复条目。只跳过**清单里**的,清单外的照样按老逻辑摘。
|
|
1140
|
+
* 认 ID 不认 path(服务端 path 可能与 manifest 写法不同)。
|
|
1141
|
+
*/
|
|
1142
|
+
if (manifestCatIds.has(String(row.id))) continue;
|
|
1049
1143
|
const p = normalizePath(row.path);
|
|
1050
1144
|
if (!p || whitelist.has(p)) continue;
|
|
1145
|
+
/* 首页(`/`)不在 menus[] 里是因为契约写不出 `/`,不是"没被引用"—— 永远留在导航 */
|
|
1146
|
+
if (p === '/') continue;
|
|
1051
1147
|
const item = `menu:${p}`;
|
|
1052
1148
|
const entry = {
|
|
1053
1149
|
kind: 'menu',
|
|
@@ -1217,6 +1313,11 @@ function diffCategory(row, want) {
|
|
|
1217
1313
|
payload.sort = want.sort;
|
|
1218
1314
|
changes.push(`sort:${row.sort} → ${want.sort}`);
|
|
1219
1315
|
}
|
|
1316
|
+
/* 导航归属:`undefined` = 本次不动(老清单);只比布尔值,避免把服务端默认值当成「有变」 */
|
|
1317
|
+
if (typeof want.inMenu === 'boolean' && Boolean(row.in_menu) !== want.inMenu) {
|
|
1318
|
+
payload.in_menu = want.inMenu;
|
|
1319
|
+
changes.push(`导航:${row.in_menu ? '显示' : '隐藏'} → ${want.inMenu ? '显示' : '隐藏'}`);
|
|
1320
|
+
}
|
|
1220
1321
|
if (want.templateFile && normTemplate(row.template_path) !== normTemplate(want.templateFile)) {
|
|
1221
1322
|
payload.template_path = want.templateFile;
|
|
1222
1323
|
changes.push(`模板:${row.template_path || '(空)'} → ${want.templateFile}`);
|
package/lib/manifest-schema.json
CHANGED
|
@@ -181,6 +181,10 @@
|
|
|
181
181
|
"type": "number",
|
|
182
182
|
"description": "同级排序,默认按声明顺序 ×10"
|
|
183
183
|
},
|
|
184
|
+
"inMenu": {
|
|
185
|
+
"type": "boolean",
|
|
186
|
+
"description": "是否显示在前台导航(也认 in_menu)。不写 = 按 menus[] 反推:清单声明了导航但没引用它 ⇒ 隐藏(in_menu=false);首页独立板块(首页·XXX)就该这样隐藏"
|
|
187
|
+
},
|
|
184
188
|
"templateFile": {
|
|
185
189
|
"type": "string",
|
|
186
190
|
"pattern": "\\.html$",
|
package/lib/manifest.mjs
CHANGED
|
@@ -433,6 +433,22 @@ export function validateManifest(doc, opts = {}) {
|
|
|
433
433
|
if (declaredPath && !PATH_RE.test(declaredPath)) {
|
|
434
434
|
fail(`${at}.path`, `path 形如 "/product/"(前后都有斜杠),收到 "${declaredPath}"`);
|
|
435
435
|
}
|
|
436
|
+
/**
|
|
437
|
+
* 导航归属(老板 2026-11-13 口径:「首页板块一律用隐藏栏目承载」)。
|
|
438
|
+
*
|
|
439
|
+
* 契约写法 `inMenu`(也认服务端字段名 `in_menu`);**不写**时由 `menus[]` 反推:
|
|
440
|
+
* 清单声明了导航但没引用这个栏目 ⇒ 落 `in_menu=false`(见 manifest-apply.mjs 的 `navStateOf`)。
|
|
441
|
+
* 这里只做取值解析与类型校验,反推逻辑放在落地层(需要本次清单的 menus[] 全景)。
|
|
442
|
+
*/
|
|
443
|
+
const inMenuRaw = raw.inMenu !== undefined ? raw.inMenu : raw.in_menu;
|
|
444
|
+
let inMenu;
|
|
445
|
+
if (inMenuRaw !== undefined && inMenuRaw !== null) {
|
|
446
|
+
if (typeof inMenuRaw !== 'boolean') {
|
|
447
|
+
fail(`${at}.inMenu`, `inMenu 必须是 true / false,收到 "${oneLine(String(inMenuRaw), 20)}"`);
|
|
448
|
+
} else {
|
|
449
|
+
inMenu = inMenuRaw;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
436
452
|
|
|
437
453
|
/* fields:栏目自己的自定义字段 */
|
|
438
454
|
const fields = [];
|
|
@@ -488,6 +504,7 @@ export function validateManifest(doc, opts = {}) {
|
|
|
488
504
|
seoKeywords,
|
|
489
505
|
description: text(raw.description),
|
|
490
506
|
fields,
|
|
507
|
+
inMenu,
|
|
491
508
|
declaredPath: declaredPath ? normalizePath(declaredPath) : '',
|
|
492
509
|
path: '',
|
|
493
510
|
level: 0,
|
|
@@ -942,6 +959,12 @@ export function manifestJsonSchema() {
|
|
|
942
959
|
},
|
|
943
960
|
parent: str({ description: '父栏目 slug 或 path;子栏目继承父的类型' }),
|
|
944
961
|
sort: { type: 'number', description: '同级排序,默认按声明顺序 ×10' },
|
|
962
|
+
inMenu: {
|
|
963
|
+
type: 'boolean',
|
|
964
|
+
description:
|
|
965
|
+
'是否显示在前台导航(也认 in_menu)。不写 = 按 menus[] 反推:清单声明了导航但没引用它 ⇒ 隐藏(in_menu=false);' +
|
|
966
|
+
'首页独立板块(首页·XXX)就该这样隐藏',
|
|
967
|
+
},
|
|
945
968
|
templateFile: str({ pattern: '\\.html$', description: '本站已有的模板文件(如 list.html),必须是 .html' }),
|
|
946
969
|
description: str({ description: '栏目简介,落 description' }),
|
|
947
970
|
seoDescription: str({ maxLength: LIMITS.seoDescriptionChars, description: '回退读 seo.description' }),
|
package/lib/site-create.mjs
CHANGED
|
@@ -112,7 +112,6 @@ function siteBrief(row) {
|
|
|
112
112
|
name: one.name || '',
|
|
113
113
|
status: one.status || null,
|
|
114
114
|
owner_user_id: one.owner_user_id || one.owner_id || null,
|
|
115
|
-
pool_id: one.pool_id || null,
|
|
116
115
|
prefix_host: prefixHost || null,
|
|
117
116
|
prefix_url: one.prefix_url || (prefixHost ? `https://${prefixHost}/` : null),
|
|
118
117
|
};
|
|
@@ -419,7 +418,7 @@ export async function runSiteCreate(ctx, flags) {
|
|
|
419
418
|
hint: '用 `wkgeo sites list` 确认是否已经建出来了;刚建出来但没有 id 属服务端异常。',
|
|
420
419
|
});
|
|
421
420
|
}
|
|
422
|
-
record('create_site', { site_id: site.id, prefix_host: site.prefix_host,
|
|
421
|
+
record('create_site', { site_id: site.id, prefix_host: site.prefix_host, region });
|
|
423
422
|
if (!json) {
|
|
424
423
|
out.ok(`站点已创建:${site.name || name}`);
|
|
425
424
|
say(`站点 ID:${site.id}`);
|
package/lib/template-publish.mjs
CHANGED
|
@@ -44,7 +44,11 @@ const MIME = {
|
|
|
44
44
|
'.js': 'application/javascript; charset=utf-8',
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
/**
|
|
48
|
+
* 模板母版落点桶(可用 `OSS_BUCKET` 覆盖)。
|
|
49
|
+
* 2026-11-11(t180 切桶):`wkgeocom` → `wkgeo-cn`(旧桶只读保留,删桶前必须切走)。
|
|
50
|
+
*/
|
|
51
|
+
const DEFAULT_BUCKET = 'wkgeo-cn';
|
|
48
52
|
const DEFAULT_REGION = 'oss-cn-shanghai';
|
|
49
53
|
|
|
50
54
|
const mimeOf = (rel) => MIME[path.extname(rel).toLowerCase()] || 'application/octet-stream';
|
package/lib/templates-sync.mjs
CHANGED
|
@@ -42,6 +42,35 @@ export const MANIFEST_VERSION = 1;
|
|
|
42
42
|
/** 服务端 `templateMaxBytes = 400 * 1024`(**按字符**算);二进制按字节同口径兜住 */
|
|
43
43
|
export const MAX_FILE_CHARS = 400 * 1024;
|
|
44
44
|
export const MAX_FILE_BYTES = 400 * 1024;
|
|
45
|
+
/**
|
|
46
|
+
* 超限文件 = **不该进站点模板副本的大体积演示资产**(three.min.js / 大图等)。
|
|
47
|
+
*
|
|
48
|
+
* ⚠️ 2026-11-14 task-107:以前拉 / 推遇到超限文件**整包直接失败**,结果是
|
|
49
|
+
* 「库里本来就有的大文件把整站的拉/推全堵死」——base 站 `assets/vendor/three-0.147.0/three.min.js`
|
|
50
|
+
* (607784 字符)与闵航站 `home.jpg`(538619 字节)就是这样堵住的,其余几十个小文件一个都推不上去。
|
|
51
|
+
* 现在改成:**跳过这一个文件 + 告警**,其余文件照常拉 / 推;上限本身**不调大**(避免整站模板过大)。
|
|
52
|
+
*/
|
|
53
|
+
export function oversizeOf(filePath, buf) {
|
|
54
|
+
const rel = String(filePath || '');
|
|
55
|
+
const text = Buffer.isBuffer(buf) ? buf : Buffer.from(String(buf === undefined || buf === null ? '' : buf), 'utf8');
|
|
56
|
+
if (isBinaryPath(rel)) {
|
|
57
|
+
if (text.length > MAX_FILE_BYTES) return { reason: 'binary-bytes', measured: text.length, limit: MAX_FILE_BYTES };
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const chars = text.toString('utf8').length;
|
|
61
|
+
if (chars > MAX_FILE_CHARS) return { reason: 'text-chars', measured: chars, limit: MAX_FILE_CHARS };
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 超限告警文案(拉 / 推共用;不打印正文) */
|
|
66
|
+
export function oversizeWarning(rel, one) {
|
|
67
|
+
const unit = one.reason === 'binary-bytes' ? '字节' : '字符';
|
|
68
|
+
return (
|
|
69
|
+
`跳过超限文件 ${rel}(${one.measured} ${unit},上限 ${one.limit}):大体积演示资产不进站点模板副本,` +
|
|
70
|
+
'其余文件照常同步;要放它请走素材库 / 母版引用'
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
45
74
|
/** 路径上限:对齐 `template-files.js` 的 `TEMPLATE_FILE_MAX_PATH_CHARS` / 每段 64 字符 */
|
|
46
75
|
export const MAX_PATH_CHARS = 200;
|
|
47
76
|
export const MAX_SEGMENT_CHARS = 64;
|
|
@@ -285,24 +314,17 @@ export async function pullTemplate({
|
|
|
285
314
|
|
|
286
315
|
const at = now().toISOString();
|
|
287
316
|
const files = [];
|
|
317
|
+
const skipped = [];
|
|
288
318
|
let binaryCount = 0;
|
|
289
319
|
let totalBytes = 0;
|
|
290
320
|
for (const raw of remoteFiles) {
|
|
291
321
|
const rel = assertSafePath(raw.path);
|
|
292
322
|
const buf = entryBytes({ ...raw, path: rel });
|
|
293
323
|
const binary = isBinaryPath(rel);
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
hint: '把这张图/字体压缩后再放回来;模板里的大文件建议走素材库(assets upload)',
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
} else if (buf.toString('utf8').length > MAX_FILE_CHARS) {
|
|
302
|
-
throw new CliError(`第 ${files.length + 1} 个模板文件太长:${rel}(${buf.toString('utf8').length} 字符,上限 ${MAX_FILE_CHARS})`, {
|
|
303
|
-
kind: 'file_too_large',
|
|
304
|
-
hint: '拆成多个 partials 文件(服务端 templateFileSave 也按 40 万字符挡)',
|
|
305
|
-
});
|
|
324
|
+
const oversize = oversizeOf(rel, buf);
|
|
325
|
+
if (oversize) {
|
|
326
|
+
skipped.push({ path: rel, bytes: buf.length, measured: oversize.measured, reason: oversize.reason });
|
|
327
|
+
continue;
|
|
306
328
|
}
|
|
307
329
|
const target = resolveInside(root, rel);
|
|
308
330
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
@@ -341,6 +363,8 @@ export async function pullTemplate({
|
|
|
341
363
|
bytes: totalBytes,
|
|
342
364
|
contentHash: manifest.contentHash,
|
|
343
365
|
files,
|
|
366
|
+
skipped,
|
|
367
|
+
warnings: skipped.map((one) => oversizeWarning(one.path, { reason: one.reason, measured: one.measured, limit: one.reason === 'binary-bytes' ? MAX_FILE_BYTES : MAX_FILE_CHARS })),
|
|
344
368
|
};
|
|
345
369
|
}
|
|
346
370
|
|
|
@@ -401,20 +425,17 @@ function scanLocal(dir) {
|
|
|
401
425
|
};
|
|
402
426
|
walk(root);
|
|
403
427
|
const files = [];
|
|
428
|
+
const skipped = [];
|
|
404
429
|
for (const abs of absPaths) {
|
|
405
430
|
const rel = path.relative(root, abs).split(path.sep).join('/');
|
|
406
431
|
if (rel === MANIFEST_FILE) continue;
|
|
407
432
|
const safe = assertSafePath(rel);
|
|
408
433
|
const buf = fs.readFileSync(abs);
|
|
409
434
|
const binary = isBinaryPath(safe);
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
} else if (buf.toString('utf8').length > MAX_FILE_CHARS) {
|
|
415
|
-
throw new CliError(`本地模板文件太长:${safe}(${buf.toString('utf8').length} 字符,上限 ${MAX_FILE_CHARS})`, {
|
|
416
|
-
kind: 'file_too_large',
|
|
417
|
-
});
|
|
435
|
+
const oversize = oversizeOf(safe, buf);
|
|
436
|
+
if (oversize) {
|
|
437
|
+
skipped.push({ path: safe, bytes: buf.length, measured: oversize.measured, reason: oversize.reason });
|
|
438
|
+
continue;
|
|
418
439
|
}
|
|
419
440
|
files.push({
|
|
420
441
|
path: safe,
|
|
@@ -426,7 +447,7 @@ function scanLocal(dir) {
|
|
|
426
447
|
text: binary ? null : buf.toString('utf8'),
|
|
427
448
|
});
|
|
428
449
|
}
|
|
429
|
-
return files.sort((a, b) => a.path.localeCompare(b.path));
|
|
450
|
+
return { files: files.sort((a, b) => a.path.localeCompare(b.path)), skipped };
|
|
430
451
|
}
|
|
431
452
|
|
|
432
453
|
/** 远端当前文件(按 manifest 里那套模板取;不传 id = 当前启用那套) */
|
|
@@ -482,7 +503,9 @@ export async function planPush({ dir = '', api = null, prune = false, cwd = proc
|
|
|
482
503
|
|
|
483
504
|
const { manifest, file: manifestPath } = readManifest(root);
|
|
484
505
|
assertSameSite(manifest, api);
|
|
485
|
-
const
|
|
506
|
+
const scanned = scanLocal(root);
|
|
507
|
+
const local = scanned.files;
|
|
508
|
+
const skipped = scanned.skipped;
|
|
486
509
|
const remote = await fetchRemote(api, manifest);
|
|
487
510
|
const localMap = new Map(local.map((f) => [f.path, f]));
|
|
488
511
|
const remoteMap = new Map(remote.files.map((f) => [f.path, f]));
|
|
@@ -507,8 +530,12 @@ export async function planPush({ dir = '', api = null, prune = false, cwd = proc
|
|
|
507
530
|
manifest,
|
|
508
531
|
plan,
|
|
509
532
|
local,
|
|
533
|
+
skipped,
|
|
510
534
|
remote: remote.files,
|
|
511
|
-
warnings:
|
|
535
|
+
warnings: [
|
|
536
|
+
...remote.warnings,
|
|
537
|
+
...skipped.map((one) => oversizeWarning(one.path, { reason: one.reason, measured: one.measured, limit: one.reason === 'binary-bytes' ? MAX_FILE_BYTES : MAX_FILE_CHARS })),
|
|
538
|
+
],
|
|
512
539
|
};
|
|
513
540
|
}
|
|
514
541
|
|
|
@@ -541,6 +568,7 @@ export async function pushTemplate({
|
|
|
541
568
|
template: { id: planned.manifest.templateId || null, key: planned.manifest.key || null },
|
|
542
569
|
plan,
|
|
543
570
|
warnings: planned.warnings.slice(),
|
|
571
|
+
skipped: planned.skipped || [],
|
|
544
572
|
written: [],
|
|
545
573
|
failed: [],
|
|
546
574
|
};
|