@ecomcx/create-ecomweb 1.28.0 → 1.29.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.
Files changed (2) hide show
  1. package/lib/validate.mjs +17 -3
  2. package/package.json +2 -2
package/lib/validate.mjs CHANGED
@@ -90,12 +90,17 @@ export function validate(dir) {
90
90
  if (j.category && !/^[a-z][a-z0-9-]{0,30}$/.test(j.category)) errors.push(`patterns/${f}: category "${j.category}" không hợp lệ`);
91
91
  } catch (e) { errors.push(`patterns/${f}: JSON lỗi — ${e.message}`); }
92
92
  }
93
+ contentDeclarations(manifest, errors, true);
94
+ if (["postTypes", "taxonomies", "postMeta", "userMeta"].some((k) => manifest[k] && Object.keys(manifest[k]).length))
95
+ warnings.push("Theme khai báo kiểu nội dung / phân loại / meta: cần CMS ≥ 1.15.0; đổi theme có khai báo khác thì API tự khởi động lại vài giây");
93
96
  if (manifest.screenshot && !fs.existsSync(path.join(dir, manifest.screenshot))) warnings.push(`Không thấy ảnh ${manifest.screenshot}`);
94
97
  if (fs.existsSync(path.join(dir, "node_modules"))) warnings.push("node_modules sẽ bị loại khỏi gói");
95
98
  } else {
96
- const declared = ["collections", "settings", "postTypes", "taxonomies", "postStatuses", "postMeta", "capabilities", "menus"].some((k) => manifest[k] && Object.keys(manifest[k]).length);
97
- for (const key of Object.keys(manifest.postMeta ?? {}))
98
- if (!/^[A-Za-z0-9_][A-Za-z0-9_.:-]{0,99}$/.test(key)) errors.push(`postMeta: khoá "${key}" không hợp lệ (chữ, số, _ - . :, tối đa 100 ký tự)`);
99
+ const declared = ["collections", "settings", "postTypes", "taxonomies", "postStatuses", "postMeta", "userMeta", "imageSizes", "capabilities", "menus"].some((k) => manifest[k] && Object.keys(manifest[k]).length);
100
+ contentDeclarations(manifest, errors);
101
+ for (const [name, size] of Object.entries(manifest.imageSizes ?? {}))
102
+ if (!/^[a-z0-9_-]{1,40}$/.test(name) || !(size?.width >= 1 && size.width <= 4000) || !((size.height ?? 0) >= 0 && (size.height ?? 0) <= 4000))
103
+ errors.push(`imageSizes: cỡ "${name}" không hợp lệ (tên a-z 0-9 _ -, width 1–4000, height 0–4000)`);
99
104
  for (const name of Object.keys(manifest.pageTemplates ?? {}))
100
105
  if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(name)) errors.push(`pageTemplates: tên template "${name}" không hợp lệ (chữ thường, số, gạch ngang)`);
101
106
  if (!manifest.backend && !manifest.admin && !manifest.frontend && !declared) errors.push("Plugin cần ít nhất một phần: backend, admin, frontend hoặc khai báo (collections, settings, postTypes…)");
@@ -273,3 +278,12 @@ function findLegacyCalls(srcDir) {
273
278
  return out;
274
279
  }
275
280
 
281
+ /** Khai báo nội dung dùng chung cho plugin.json và theme.json (cùng quy tắc với core — Cms.Packaging/Manifests.cs). */
282
+ function contentDeclarations(manifest, errors, checkNames = false) {
283
+ for (const key of Object.keys(manifest.postMeta ?? {}))
284
+ if (!/^[A-Za-z0-9_][A-Za-z0-9_.:-]{0,99}$/.test(key)) errors.push(`postMeta: khoá "${key}" không hợp lệ (chữ, số, _ - . :, tối đa 100 ký tự)`);
285
+ for (const key of Object.keys(manifest.userMeta ?? {}))
286
+ if (!/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,99}$/.test(key)) errors.push(`userMeta: khoá "${key}" không hợp lệ (chữ, số, _ - . :, tối đa 100 ký tự, không bắt đầu bằng _)`);
287
+ if (checkNames) for (const name of [...Object.keys(manifest.postTypes ?? {}), ...Object.keys(manifest.taxonomies ?? {})])
288
+ if (!/^[a-z][a-z0-9_-]{0,31}$/.test(name)) errors.push(`Tên kiểu nội dung / phân loại "${name}" không hợp lệ (a-z, 0-9, _ -, bắt đầu bằng chữ, tối đa 32 ký tự)`);
289
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecomcx/create-ecomweb",
3
- "version": "1.28.0",
3
+ "version": "1.29.0",
4
4
  "description": "CLI tạo, kiểm tra, đóng gói và triển khai theme/plugin cho Ecomweb",
5
5
  "type": "module",
6
6
  "bin": {
@@ -13,7 +13,7 @@
13
13
  "README.md"
14
14
  ],
15
15
  "dependencies": {
16
- "@ecomcx/ecomweb-admin-sdk": "1.28.0",
16
+ "@ecomcx/ecomweb-admin-sdk": "1.29.0",
17
17
  "@ecomcx/ecomweb-content": "^1.14.0",
18
18
  "adm-zip": "0.5.18",
19
19
  "esbuild": "0.25.12",