@decocms/blocks-cli 7.79.3 → 7.79.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/blocks-cli",
|
|
3
|
-
"version": "7.79.
|
|
3
|
+
"version": "7.79.5",
|
|
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.79.
|
|
36
|
+
"@decocms/blocks": "7.79.5",
|
|
37
37
|
"ts-morph": "^27.0.0",
|
|
38
38
|
"tsx": "^4.22.5"
|
|
39
39
|
},
|
|
@@ -30,6 +30,7 @@ describe("generate-schema site multivariate flags", () => {
|
|
|
30
30
|
|
|
31
31
|
const FLAG = "site/flags/multivariate/content.ts";
|
|
32
32
|
const LIST_FLAG = "site/flags/multivariate/products.ts";
|
|
33
|
+
const IMAGE_FLAG = "website/flags/multivariate/image.ts";
|
|
33
34
|
|
|
34
35
|
beforeAll(() => {
|
|
35
36
|
fixture = mkdtempSync(path.join(tmpdir(), "schema-flags-"));
|
|
@@ -59,7 +60,8 @@ describe("generate-schema site multivariate flags", () => {
|
|
|
59
60
|
);
|
|
60
61
|
write(
|
|
61
62
|
"src/types.ts",
|
|
62
|
-
`export
|
|
63
|
+
`export type ImageWidget = string;
|
|
64
|
+
export interface Content { matcher?: string[]; label: string; }
|
|
63
65
|
export interface Kit { name: string; content: Content; }
|
|
64
66
|
export interface Product { productID: string; }`,
|
|
65
67
|
);
|
|
@@ -92,8 +94,10 @@ describe("generate-schema site multivariate flags", () => {
|
|
|
92
94
|
);
|
|
93
95
|
write(
|
|
94
96
|
"src/sections/Example.tsx",
|
|
95
|
-
`import type { Content, Product } from "../types";
|
|
97
|
+
`import type { Content, ImageWidget, Product } from "../types";
|
|
96
98
|
export interface Props {
|
|
99
|
+
banner?: ImageWidget;
|
|
100
|
+
gallery?: ImageWidget[];
|
|
97
101
|
/**
|
|
98
102
|
* @title Main content
|
|
99
103
|
* @description Shown on top
|
|
@@ -151,6 +155,7 @@ describe("generate-schema site multivariate flags", () => {
|
|
|
151
155
|
|
|
152
156
|
it("registers each flag in the manifest and in root.flags", () => {
|
|
153
157
|
expect(meta.manifest.blocks.flags).toEqual({
|
|
158
|
+
[IMAGE_FLAG]: { $ref: `#/definitions/${btoa(IMAGE_FLAG)}`, namespace: "website" },
|
|
154
159
|
[FLAG]: { $ref: `#/definitions/${btoa(FLAG)}`, namespace: "site" },
|
|
155
160
|
[LIST_FLAG]: { $ref: `#/definitions/${btoa(LIST_FLAG)}`, namespace: "site" },
|
|
156
161
|
});
|
|
@@ -213,4 +218,25 @@ describe("generate-schema site multivariate flags", () => {
|
|
|
213
218
|
expect(hidden.anyOf).toBeUndefined();
|
|
214
219
|
expect(hidden.type).toBe("object");
|
|
215
220
|
});
|
|
221
|
+
|
|
222
|
+
it("offers image variants on an ImageWidget prop, as deco-cx/deco did", () => {
|
|
223
|
+
const { banner, gallery } = sectionProps();
|
|
224
|
+
expect(banner.anyOf).toEqual([
|
|
225
|
+
{ type: "string", format: "image-uri", title: "Banner" },
|
|
226
|
+
{
|
|
227
|
+
title: "Image Variants",
|
|
228
|
+
type: "object",
|
|
229
|
+
allOf: [{ $ref: `#/definitions/${btoa(IMAGE_FLAG)}@Props` }],
|
|
230
|
+
required: ["__resolveType"],
|
|
231
|
+
properties: {
|
|
232
|
+
__resolveType: { type: "string", enum: [IMAGE_FLAG], default: IMAGE_FLAG },
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
]);
|
|
236
|
+
const value = def(`${btoa(IMAGE_FLAG)}@Props`).properties!.variants.items!.properties!.value;
|
|
237
|
+
expect(value).toMatchObject({ type: "string", format: "image-uri" });
|
|
238
|
+
// A list of images is not an image: deco-cx/deco offered no variants there.
|
|
239
|
+
expect(gallery.anyOf).toBeUndefined();
|
|
240
|
+
expect(gallery.type).toBe("array");
|
|
241
|
+
});
|
|
216
242
|
});
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
EITRI_FORMAT_ALIASES,
|
|
9
9
|
WIDGET_TYPE_FORMATS,
|
|
10
10
|
applyWidgetFormat,
|
|
11
|
+
beautify,
|
|
11
12
|
definitionIdForPath,
|
|
12
13
|
normalizeFormats,
|
|
13
14
|
typeToJsonSchema,
|
|
@@ -569,3 +570,35 @@ describe("typeToJsonSchema with RequestURLParam", () => {
|
|
|
569
570
|
expect(schema.properties.plain.type).toBe("string");
|
|
570
571
|
});
|
|
571
572
|
});
|
|
573
|
+
|
|
574
|
+
describe("default prop titles (deco-cx/deco beautify)", () => {
|
|
575
|
+
it.each([
|
|
576
|
+
["marginTop", "Margin Top"],
|
|
577
|
+
["hideUnavailableItems", "Hide Unavailable Items"],
|
|
578
|
+
["title", "Title"],
|
|
579
|
+
// Acronyms stay whole (deco-cx/deco split them letter by letter).
|
|
580
|
+
["CTA", "CTA"],
|
|
581
|
+
["titleCTA", "Title CTA"],
|
|
582
|
+
["taxID", "Tax ID"],
|
|
583
|
+
["jsonLDs", "Json L Ds"], // a plural acronym is ambiguous; same as upstream
|
|
584
|
+
["XMLHttpRequest", "XML Http Request"],
|
|
585
|
+
["RangePriceProps", "Range Price Props"],
|
|
586
|
+
])("%s → %s", (name, title) => {
|
|
587
|
+
expect(beautify(name)).toBe(title);
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
it("titles an un-annotated prop, keeps an explicit @title", () => {
|
|
591
|
+
const project = strictProject();
|
|
592
|
+
const sf = project.createSourceFile(
|
|
593
|
+
"/titles.ts",
|
|
594
|
+
`export interface Props {
|
|
595
|
+
marginTop?: number;
|
|
596
|
+
/** @title Custom */
|
|
597
|
+
noFlex?: boolean;
|
|
598
|
+
}`,
|
|
599
|
+
);
|
|
600
|
+
const schema = typeToJsonSchema(sf.getInterfaceOrThrow("Props").getType());
|
|
601
|
+
expect(schema.properties.marginTop.title).toBe("Margin Top");
|
|
602
|
+
expect(schema.properties.noFlex.title).toBe("Custom");
|
|
603
|
+
});
|
|
604
|
+
});
|
|
@@ -132,6 +132,20 @@ export function definitionIdForPath(filePath: string, rootDir: string): string {
|
|
|
132
132
|
return toBase64(rel.startsWith("..") ? cleaned : rel);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Default title for a prop without `@title`, as deco-cx/deco derives it
|
|
137
|
+
* (`engine/schema/utils.ts`): words split at capitals, first character
|
|
138
|
+
* uppercased — `marginTop` → "Margin Top". Unlike deco-cx/deco, a run of
|
|
139
|
+
* capitals stays one word (`CTA` → "CTA", `titleCTA` → "Title CTA", where
|
|
140
|
+
* upstream gave " C T A") and a PascalCase name gets no leading space.
|
|
141
|
+
*/
|
|
142
|
+
export function beautify(propName: string): string {
|
|
143
|
+
return propName
|
|
144
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
145
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
|
|
146
|
+
.replace(/^./, (c) => c.toUpperCase());
|
|
147
|
+
}
|
|
148
|
+
|
|
135
149
|
/**
|
|
136
150
|
* Map JSDoc tags to JSON Schema 7 keywords.
|
|
137
151
|
* Supports all 20+ tags from deco-cx/deco.
|
|
@@ -545,6 +559,19 @@ export function extractFlagValueType(sourceFile: SourceFile): Type | null {
|
|
|
545
559
|
return value ? value.getTypeAtLocation(sourceFile) : null;
|
|
546
560
|
}
|
|
547
561
|
|
|
562
|
+
/**
|
|
563
|
+
* deco-cx/apps' typed multivariate flags over a widget type (annotation name).
|
|
564
|
+
* `website/flags/multivariate/image.ts` is `MultivariateFlag<ImageWidget>`.
|
|
565
|
+
*/
|
|
566
|
+
const BUILTIN_WIDGET_FLAGS = [
|
|
567
|
+
{
|
|
568
|
+
key: "website/flags/multivariate/image.ts",
|
|
569
|
+
title: "Image Variants",
|
|
570
|
+
widget: "ImageWidget",
|
|
571
|
+
valueSchema: { type: "string", format: "image-uri" },
|
|
572
|
+
},
|
|
573
|
+
];
|
|
574
|
+
|
|
548
575
|
/**
|
|
549
576
|
* A flag block as an `anyOf` branch of a prop it can fill, in deco-cx/deco's
|
|
550
577
|
* shape: inline, carrying its own `__resolveType`, with the variants schema
|
|
@@ -811,11 +838,11 @@ export function typeToJsonSchema(type: Type, visited = new Set<string>(), ctx?:
|
|
|
811
838
|
? {
|
|
812
839
|
type: "array",
|
|
813
840
|
items: { $ref: `#/definitions/${SECTION_REF_DEF_KEY}` },
|
|
814
|
-
title:
|
|
841
|
+
title: beautify(name),
|
|
815
842
|
}
|
|
816
843
|
: {
|
|
817
844
|
$ref: `#/definitions/${SECTION_REF_DEF_KEY}`,
|
|
818
|
-
title:
|
|
845
|
+
title: beautify(name),
|
|
819
846
|
};
|
|
820
847
|
if (prop.isOptional() || typeHint.includes("null") || typeHint.includes("undefined")) {
|
|
821
848
|
sectionSchema.nullable = true;
|
|
@@ -836,7 +863,7 @@ export function typeToJsonSchema(type: Type, visited = new Set<string>(), ctx?:
|
|
|
836
863
|
if (baseHint === "RequestURLParam" && nonNullTypes.every((t) => t.isString())) {
|
|
837
864
|
const paramSchema: any = {
|
|
838
865
|
$ref: `#/definitions/${REQUEST_URL_PARAM_DEF_KEY}`,
|
|
839
|
-
title:
|
|
866
|
+
title: beautify(name),
|
|
840
867
|
};
|
|
841
868
|
applyJsDocToSchema(paramSchema, tags);
|
|
842
869
|
properties[name] = paramSchema;
|
|
@@ -845,8 +872,12 @@ export function typeToJsonSchema(type: Type, visited = new Set<string>(), ctx?:
|
|
|
845
872
|
}
|
|
846
873
|
|
|
847
874
|
const outputTypeName = loaderTypeName(propType);
|
|
875
|
+
// By resolved type name, else by the annotation: `ImageWidget` is an
|
|
876
|
+
// alias of `string`, and TypeScript keeps no alias symbol on primitives.
|
|
848
877
|
const matchingFlags =
|
|
849
|
-
(outputTypeName ? ctx?.outputTypeToFlags?.get(outputTypeName) : undefined) ??
|
|
878
|
+
(outputTypeName ? ctx?.outputTypeToFlags?.get(outputTypeName) : undefined) ??
|
|
879
|
+
ctx?.outputTypeToFlags?.get(baseHint) ??
|
|
880
|
+
[];
|
|
850
881
|
|
|
851
882
|
// Loader output type → block-ref: emit anyOf [Resolvable, ...matchingLoaders]
|
|
852
883
|
// baseHint strips "| null | undefined" so "ProductListingPage | null" → "ProductListingPage"
|
|
@@ -865,7 +896,7 @@ export function typeToJsonSchema(type: Type, visited = new Set<string>(), ctx?:
|
|
|
865
896
|
...matchingLoaders.map((k) => ({ $ref: `#/definitions/${toBase64(k)}` })),
|
|
866
897
|
...matchingFlags.map((f) => ({ $ref: `#/definitions/${f.defKey}` })),
|
|
867
898
|
],
|
|
868
|
-
title:
|
|
899
|
+
title: beautify(name),
|
|
869
900
|
};
|
|
870
901
|
if (prop.isOptional() || typeHint.includes("null") || typeHint.includes("undefined")) {
|
|
871
902
|
blockRefSchema.nullable = true;
|
|
@@ -886,7 +917,7 @@ export function typeToJsonSchema(type: Type, visited = new Set<string>(), ctx?:
|
|
|
886
917
|
schema.format = "password";
|
|
887
918
|
}
|
|
888
919
|
|
|
889
|
-
if (!schema.title) schema.title =
|
|
920
|
+
if (!schema.title) schema.title = beautify(name);
|
|
890
921
|
|
|
891
922
|
// A site flag over this prop's type → the value may also be that flag
|
|
892
923
|
// (`{ __resolveType: "site/flags/…", variants }`). Without the branch the
|
|
@@ -1264,6 +1295,28 @@ function generateMeta(): MetaResponse {
|
|
|
1264
1295
|
// a `Product[]` inside a flag's value is a loader picker, not the whole
|
|
1265
1296
|
// inlined Product type.
|
|
1266
1297
|
// ---------------------------------------------------------------------------
|
|
1298
|
+
// deco-cx/apps' typed multivariate flags over widget types, which deco-cx/deco
|
|
1299
|
+
// offered on every field of that type (an image field could hold image
|
|
1300
|
+
// variants). Their value schema is the widget's own.
|
|
1301
|
+
for (const builtin of BUILTIN_WIDGET_FLAGS) {
|
|
1302
|
+
const flag: FlagBlock = {
|
|
1303
|
+
key: builtin.key,
|
|
1304
|
+
title: builtin.title,
|
|
1305
|
+
defKey: toBase64(builtin.key),
|
|
1306
|
+
};
|
|
1307
|
+
const existing = outputTypeToFlags.get(builtin.widget) ?? [];
|
|
1308
|
+
existing.push(flag);
|
|
1309
|
+
outputTypeToFlags.set(builtin.widget, existing);
|
|
1310
|
+
definitions[`${flag.defKey}@Props`] = multivariatePropsSchema(builtin.valueSchema);
|
|
1311
|
+
const { allOf, required, properties } = flagBranch(flag);
|
|
1312
|
+
definitions[flag.defKey] = { title: flag.title, type: "object", allOf, required, properties };
|
|
1313
|
+
flagBlocks[flag.key] = { $ref: `#/definitions/${flag.defKey}`, namespace: "website" };
|
|
1314
|
+
flagRootAnyOf.push({
|
|
1315
|
+
$ref: `#/definitions/${flag.defKey}`,
|
|
1316
|
+
inputSchema: `#/definitions/${flag.defKey}@Props`,
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1267
1320
|
const flagFiles = fs.existsSync(flagsDir) ? findTsxFiles(flagsDir) : [];
|
|
1268
1321
|
const siteFlags: Array<{ flag: FlagBlock; valueType: Type; valueTypeName: string | null }> = [];
|
|
1269
1322
|
for (const filePath of flagFiles) {
|