@decocms/blocks-cli 7.72.1 → 7.73.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/package.json +2 -2
- package/scripts/generate-sections.ts +22 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/blocks-cli",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.73.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Deco codegen (generate-blocks, generate-schema, generate-invoke) and Fresh-to-TanStack migration tooling",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"lint:unused": "knip"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@decocms/blocks": "7.
|
|
36
|
+
"@decocms/blocks": "7.73.0",
|
|
37
37
|
"ts-morph": "^27.0.0",
|
|
38
38
|
"tsx": "^4.22.5"
|
|
39
39
|
},
|
|
@@ -54,6 +54,7 @@ interface SectionMeta {
|
|
|
54
54
|
clientOnly?: boolean;
|
|
55
55
|
seo?: boolean;
|
|
56
56
|
hasLoadingFallback?: boolean;
|
|
57
|
+
fallbackProps?: string[];
|
|
57
58
|
renderJson?: false;
|
|
58
59
|
hasRenderJson?: boolean;
|
|
59
60
|
}
|
|
@@ -77,6 +78,17 @@ const LOADING_FALLBACK_INLINE_RE = /export\s+(?:function|const|let|var)\s+Loadin
|
|
|
77
78
|
// `LoadingFallback`), but that's unrealistic in section files and would surface
|
|
78
79
|
// as a loud build error rather than silent CLS.
|
|
79
80
|
const LOADING_FALLBACK_REEXPORT_RE = /export\s*\{[^}]*\bLoadingFallback\b[^}]*\}/;
|
|
81
|
+
// `export const fallbackProps = ["title", "subtitle"]` — the props a deferred
|
|
82
|
+
// section lets its LoadingFallback render. Nothing a section does not name is
|
|
83
|
+
// serialized, so the list is the opt-in; array of string literals only.
|
|
84
|
+
const FALLBACK_PROPS_RE = /export\s+const\s+fallbackProps\s*=\s*\[([^\]]*)\]/;
|
|
85
|
+
|
|
86
|
+
function extractFallbackProps(content: string): string[] | null {
|
|
87
|
+
const match = content.match(FALLBACK_PROPS_RE);
|
|
88
|
+
if (!match) return null;
|
|
89
|
+
const props = [...match[1].matchAll(/["'`]([^"'`]+)["'`]/g)].map((m) => m[1]);
|
|
90
|
+
return props.length > 0 ? props : null;
|
|
91
|
+
}
|
|
80
92
|
|
|
81
93
|
function hasLoadingFallbackExport(content: string): boolean {
|
|
82
94
|
return (
|
|
@@ -106,6 +118,12 @@ function extractMeta(content: string): SectionMeta | null {
|
|
|
106
118
|
found = true;
|
|
107
119
|
}
|
|
108
120
|
|
|
121
|
+
const fallbackProps = extractFallbackProps(content);
|
|
122
|
+
if (fallbackProps) {
|
|
123
|
+
meta.fallbackProps = fallbackProps;
|
|
124
|
+
found = true;
|
|
125
|
+
}
|
|
126
|
+
|
|
109
127
|
if (RENDER_JSON_FALSE_RE.test(content)) {
|
|
110
128
|
meta.renderJson = false;
|
|
111
129
|
found = true;
|
|
@@ -235,6 +253,7 @@ lines.push(" sync?: boolean;");
|
|
|
235
253
|
lines.push(" clientOnly?: boolean;");
|
|
236
254
|
lines.push(" seo?: boolean;");
|
|
237
255
|
lines.push(" hasLoadingFallback?: boolean;");
|
|
256
|
+
lines.push(" fallbackProps?: string[];");
|
|
238
257
|
lines.push(" renderJson?: false;");
|
|
239
258
|
lines.push(" hasRenderJson?: boolean;");
|
|
240
259
|
lines.push("}");
|
|
@@ -242,7 +261,9 @@ lines.push("");
|
|
|
242
261
|
lines.push("export const sectionMeta: Record<string, SectionMetaEntry> = {");
|
|
243
262
|
for (const e of entries) {
|
|
244
263
|
const props = Object.entries(e.meta)
|
|
245
|
-
|
|
264
|
+
// Arrays (fallbackProps) need JSON — template interpolation would emit
|
|
265
|
+
// `title,subtitle` and the generated file would not parse.
|
|
266
|
+
.map(([k, v]) => `${k}: ${typeof v === "string" || Array.isArray(v) ? JSON.stringify(v) : v}`)
|
|
246
267
|
.join(", ");
|
|
247
268
|
lines.push(` "${e.key}": { ${props} },`);
|
|
248
269
|
}
|