prismic-ts-codegen 0.1.1 → 0.1.3
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/bin/cli.mjs +134 -48
- package/dist/index.cjs +101 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +101 -29
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
- package/src/cli/types.ts +4 -2
- package/src/generateTypes.ts +2 -2
- package/src/lib/addInterfacePropertiesForFields.ts +40 -14
- package/src/lib/addTypeAliasForCustomType.ts +4 -4
- package/src/lib/addTypeAliasForSharedSlice.ts +19 -21
- package/src/lib/buildSharedSliceInterfaceNamePart.ts +11 -0
- package/src/lib/buildTypeName.ts +11 -0
- package/src/lib/buildSharedSliceInterfaceName.ts +0 -11
package/bin/cli.mjs
CHANGED
|
@@ -209,10 +209,18 @@ const pascalCase = (input) => pascalCase$1(input, {
|
|
|
209
209
|
transform: pascalCaseTransformMerge
|
|
210
210
|
});
|
|
211
211
|
|
|
212
|
-
const
|
|
212
|
+
const buildSharedSliceInterfaceNamePart = (config) => {
|
|
213
213
|
return pascalCase(`${config.id} Slice`);
|
|
214
214
|
};
|
|
215
215
|
|
|
216
|
+
const buildTypeName = (...parts) => {
|
|
217
|
+
let name = pascalCase(parts.filter(Boolean).join(" "));
|
|
218
|
+
if (/^[0-9]/.test(name) ? "_" : "") {
|
|
219
|
+
name = `_${name}`;
|
|
220
|
+
}
|
|
221
|
+
return name;
|
|
222
|
+
};
|
|
223
|
+
|
|
216
224
|
const addInterfacePropertyForField = (config) => {
|
|
217
225
|
switch (config.model.type) {
|
|
218
226
|
case "UID": {
|
|
@@ -262,12 +270,16 @@ const addInterfacePropertyForField = (config) => {
|
|
|
262
270
|
if (config.fieldConfigs.embed?.providerTypes) {
|
|
263
271
|
for (const providerType in config.fieldConfigs.embed?.providerTypes) {
|
|
264
272
|
const configuredProviderType = config.fieldConfigs.embed?.providerTypes[providerType];
|
|
265
|
-
providerTypes.push(
|
|
273
|
+
providerTypes.push(
|
|
274
|
+
`({ provider_name: "${providerType}" } & ${configuredProviderType})`
|
|
275
|
+
);
|
|
266
276
|
}
|
|
267
277
|
}
|
|
268
278
|
config.interface.addProperty({
|
|
269
279
|
name: config.id,
|
|
270
|
-
type: providerTypes.length > 0 ? `prismicT.EmbedField<prismicT.AnyOEmbed & prismicT.OEmbedExtra & (${providerTypes.join(
|
|
280
|
+
type: providerTypes.length > 0 ? `prismicT.EmbedField<prismicT.AnyOEmbed & prismicT.OEmbedExtra & (${providerTypes.join(
|
|
281
|
+
" | "
|
|
282
|
+
)})>` : "prismicT.EmbedField",
|
|
271
283
|
docs: buildFieldDocs({
|
|
272
284
|
id: config.id,
|
|
273
285
|
model: config.model,
|
|
@@ -306,7 +318,7 @@ const addInterfacePropertyForField = (config) => {
|
|
|
306
318
|
} else {
|
|
307
319
|
config.interface.addProperty({
|
|
308
320
|
name: config.id,
|
|
309
|
-
type: "prismicT.ImageField<
|
|
321
|
+
type: "prismicT.ImageField<never>",
|
|
310
322
|
docs: buildFieldDocs({
|
|
311
323
|
id: config.id,
|
|
312
324
|
model: config.model,
|
|
@@ -471,7 +483,13 @@ const addInterfacePropertyForField = (config) => {
|
|
|
471
483
|
}
|
|
472
484
|
case "Group": {
|
|
473
485
|
const itemInterface = config.sourceFile.addInterface({
|
|
474
|
-
name:
|
|
486
|
+
name: buildTypeName(
|
|
487
|
+
config.path[0].id,
|
|
488
|
+
"Document",
|
|
489
|
+
"Data",
|
|
490
|
+
config.id,
|
|
491
|
+
"Item"
|
|
492
|
+
),
|
|
475
493
|
docs: [
|
|
476
494
|
{
|
|
477
495
|
description: (writer) => {
|
|
@@ -523,12 +541,22 @@ const addInterfacePropertyForField = (config) => {
|
|
|
523
541
|
for (const choiceId in config.model.config.choices) {
|
|
524
542
|
const choice = config.model.config.choices[choiceId];
|
|
525
543
|
if (choice.type === CustomTypeModelSliceType.SharedSlice) {
|
|
526
|
-
choiceInterfaceNames.push(
|
|
544
|
+
choiceInterfaceNames.push(
|
|
545
|
+
buildSharedSliceInterfaceNamePart({ id: choiceId })
|
|
546
|
+
);
|
|
527
547
|
} else if (choice.type === CustomTypeModelSliceType.Slice) {
|
|
528
548
|
let primaryInterface;
|
|
529
549
|
if (choice["non-repeat"] && Object.keys(choice["non-repeat"]).length > 0) {
|
|
530
550
|
primaryInterface = config.sourceFile.addInterface({
|
|
531
|
-
name:
|
|
551
|
+
name: buildTypeName(
|
|
552
|
+
config.path[0].id,
|
|
553
|
+
"Document",
|
|
554
|
+
"Data",
|
|
555
|
+
config.id,
|
|
556
|
+
choiceId,
|
|
557
|
+
"Slice",
|
|
558
|
+
"Primary"
|
|
559
|
+
),
|
|
532
560
|
docs: [
|
|
533
561
|
{
|
|
534
562
|
description: (writer) => {
|
|
@@ -549,7 +577,9 @@ const addInterfacePropertyForField = (config) => {
|
|
|
549
577
|
}
|
|
550
578
|
]
|
|
551
579
|
});
|
|
552
|
-
writer.writeLine(
|
|
580
|
+
writer.writeLine(
|
|
581
|
+
`Primary content in ${humanReadablePath}`
|
|
582
|
+
);
|
|
553
583
|
}
|
|
554
584
|
}
|
|
555
585
|
]
|
|
@@ -579,7 +609,15 @@ const addInterfacePropertyForField = (config) => {
|
|
|
579
609
|
let itemInterface;
|
|
580
610
|
if (choice.repeat && Object.keys(choice.repeat).length > 0) {
|
|
581
611
|
itemInterface = config.sourceFile.addInterface({
|
|
582
|
-
name:
|
|
612
|
+
name: buildTypeName(
|
|
613
|
+
config.path[0].id,
|
|
614
|
+
"Document",
|
|
615
|
+
"Data",
|
|
616
|
+
config.id,
|
|
617
|
+
choiceId,
|
|
618
|
+
"Slice",
|
|
619
|
+
"Item"
|
|
620
|
+
),
|
|
583
621
|
docs: [
|
|
584
622
|
{
|
|
585
623
|
description: (writer) => {
|
|
@@ -629,7 +667,14 @@ const addInterfacePropertyForField = (config) => {
|
|
|
629
667
|
});
|
|
630
668
|
}
|
|
631
669
|
const sliceType = config.sourceFile.addTypeAlias({
|
|
632
|
-
name:
|
|
670
|
+
name: buildTypeName(
|
|
671
|
+
config.path[0].id,
|
|
672
|
+
"Document",
|
|
673
|
+
"Data",
|
|
674
|
+
config.id,
|
|
675
|
+
choiceId,
|
|
676
|
+
"Slice"
|
|
677
|
+
),
|
|
633
678
|
type: `prismicT.Slice<"${choiceId}", ${primaryInterface ? `Simplify<${primaryInterface.getName()}>` : "Record<string, never>"}, ${itemInterface ? `Simplify<${itemInterface.getName()}>` : "never"}>`,
|
|
634
679
|
isExported: true
|
|
635
680
|
});
|
|
@@ -638,7 +683,13 @@ const addInterfacePropertyForField = (config) => {
|
|
|
638
683
|
}
|
|
639
684
|
}
|
|
640
685
|
const slicesType = config.sourceFile.addTypeAlias({
|
|
641
|
-
name:
|
|
686
|
+
name: buildTypeName(
|
|
687
|
+
config.path[0].id,
|
|
688
|
+
"Document",
|
|
689
|
+
"Data",
|
|
690
|
+
config.id,
|
|
691
|
+
"Slice"
|
|
692
|
+
),
|
|
642
693
|
type: choiceInterfaceNames.length > 0 ? choiceInterfaceNames.join(" | ") : "never",
|
|
643
694
|
docs: [
|
|
644
695
|
{
|
|
@@ -709,7 +760,7 @@ const addTypeAliasForCustomType = ({
|
|
|
709
760
|
let dataInterface;
|
|
710
761
|
if (hasDataFields) {
|
|
711
762
|
dataInterface = sourceFile.addInterface({
|
|
712
|
-
name:
|
|
763
|
+
name: buildTypeName(model.id, "Document", "Data"),
|
|
713
764
|
docs: [
|
|
714
765
|
{
|
|
715
766
|
description: `Content for ${model.label} documents`
|
|
@@ -734,7 +785,7 @@ const addTypeAliasForCustomType = ({
|
|
|
734
785
|
}
|
|
735
786
|
} else {
|
|
736
787
|
dataInterface = sourceFile.addTypeAlias({
|
|
737
|
-
name:
|
|
788
|
+
name: buildTypeName(model.id, "Document", "Data"),
|
|
738
789
|
type: `Record<string, never>`,
|
|
739
790
|
docs: [
|
|
740
791
|
{
|
|
@@ -744,7 +795,7 @@ const addTypeAliasForCustomType = ({
|
|
|
744
795
|
});
|
|
745
796
|
}
|
|
746
797
|
return sourceFile.addTypeAlias({
|
|
747
|
-
name:
|
|
798
|
+
name: buildTypeName(model.id, "Document"),
|
|
748
799
|
typeParameters: [
|
|
749
800
|
{
|
|
750
801
|
name: "Lang",
|
|
@@ -760,7 +811,9 @@ const addTypeAliasForCustomType = ({
|
|
|
760
811
|
writer.blankLine();
|
|
761
812
|
writer.writeLine(`- **API ID**: \`${model.id}\``);
|
|
762
813
|
writer.writeLine(`- **Repeatable**: \`${model.repeatable}\``);
|
|
763
|
-
writer.writeLine(
|
|
814
|
+
writer.writeLine(
|
|
815
|
+
`- **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}`
|
|
816
|
+
);
|
|
764
817
|
},
|
|
765
818
|
tags: [
|
|
766
819
|
{
|
|
@@ -780,7 +833,11 @@ const addTypeAliasForSharedSlice = (config) => {
|
|
|
780
833
|
let primaryInterface;
|
|
781
834
|
if (variation.primary && Object.keys(variation.primary).length > 0) {
|
|
782
835
|
primaryInterface = config.sourceFile.addInterface({
|
|
783
|
-
name:
|
|
836
|
+
name: buildTypeName(
|
|
837
|
+
buildSharedSliceInterfaceNamePart({ id: config.model.id }),
|
|
838
|
+
variation.id,
|
|
839
|
+
"Primary"
|
|
840
|
+
),
|
|
784
841
|
docs: [
|
|
785
842
|
{
|
|
786
843
|
description: (writer) => {
|
|
@@ -821,7 +878,11 @@ const addTypeAliasForSharedSlice = (config) => {
|
|
|
821
878
|
let itemInterface;
|
|
822
879
|
if (variation.items && Object.keys(variation.items).length > 0) {
|
|
823
880
|
itemInterface = config.sourceFile.addInterface({
|
|
824
|
-
name:
|
|
881
|
+
name: buildTypeName(
|
|
882
|
+
buildSharedSliceInterfaceNamePart({ id: config.model.id }),
|
|
883
|
+
variation.id,
|
|
884
|
+
"Item"
|
|
885
|
+
),
|
|
825
886
|
docs: [
|
|
826
887
|
{
|
|
827
888
|
description: (writer) => {
|
|
@@ -861,18 +922,23 @@ const addTypeAliasForSharedSlice = (config) => {
|
|
|
861
922
|
});
|
|
862
923
|
}
|
|
863
924
|
const variationType = config.sourceFile.addTypeAlias({
|
|
864
|
-
name:
|
|
865
|
-
id: config.model.id
|
|
866
|
-
|
|
925
|
+
name: buildTypeName(
|
|
926
|
+
buildSharedSliceInterfaceNamePart({ id: config.model.id }),
|
|
927
|
+
variation.id
|
|
928
|
+
),
|
|
867
929
|
type: `prismicT.SharedSliceVariation<"${variation.id}", ${primaryInterface ? `Simplify<${primaryInterface.getName()}>` : "Record<string, never>"}, ${itemInterface ? `Simplify<${itemInterface.getName()}>` : "never"}>`,
|
|
868
930
|
docs: [
|
|
869
931
|
{
|
|
870
932
|
description: (writer) => {
|
|
871
|
-
writer.writeLine(
|
|
933
|
+
writer.writeLine(
|
|
934
|
+
`${variation.name} variation for ${config.model.name} Slice`
|
|
935
|
+
);
|
|
872
936
|
writer.blankLine();
|
|
873
937
|
writer.writeLine(`- **API ID**: \`${variation.id}\``);
|
|
874
938
|
writer.writeLine(`- **Description**: \`${variation.description}\``);
|
|
875
|
-
writer.writeLine(
|
|
939
|
+
writer.writeLine(
|
|
940
|
+
`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`
|
|
941
|
+
);
|
|
876
942
|
}
|
|
877
943
|
}
|
|
878
944
|
],
|
|
@@ -881,7 +947,7 @@ const addTypeAliasForSharedSlice = (config) => {
|
|
|
881
947
|
variationTypeNames.push(variationType.getName());
|
|
882
948
|
}
|
|
883
949
|
const variationsType = config.sourceFile.addTypeAlias({
|
|
884
|
-
name:
|
|
950
|
+
name: buildTypeName(config.model.id, "Slice", "Variation"),
|
|
885
951
|
type: variationTypeNames.length > 0 ? variationTypeNames.join(" | ") : "never",
|
|
886
952
|
docs: [
|
|
887
953
|
{
|
|
@@ -900,9 +966,9 @@ const addTypeAliasForSharedSlice = (config) => {
|
|
|
900
966
|
]
|
|
901
967
|
});
|
|
902
968
|
return config.sourceFile.addTypeAlias({
|
|
903
|
-
name:
|
|
904
|
-
id: config.model.id
|
|
905
|
-
|
|
969
|
+
name: buildTypeName(
|
|
970
|
+
buildSharedSliceInterfaceNamePart({ id: config.model.id })
|
|
971
|
+
),
|
|
906
972
|
type: `prismicT.SharedSlice<"${config.model.id}", ${variationsType.getName()}>`,
|
|
907
973
|
docs: [
|
|
908
974
|
{
|
|
@@ -910,8 +976,12 @@ const addTypeAliasForSharedSlice = (config) => {
|
|
|
910
976
|
writer.writeLine(`${config.model.name} Shared Slice`);
|
|
911
977
|
writer.blankLine();
|
|
912
978
|
writer.writeLine(`- **API ID**: \`${config.model.id}\``);
|
|
913
|
-
writer.writeLine(
|
|
914
|
-
|
|
979
|
+
writer.writeLine(
|
|
980
|
+
`- **Description**: \`${config.model.description}\``
|
|
981
|
+
);
|
|
982
|
+
writer.writeLine(
|
|
983
|
+
`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`
|
|
984
|
+
);
|
|
915
985
|
}
|
|
916
986
|
}
|
|
917
987
|
],
|
|
@@ -957,7 +1027,9 @@ const generateTypes = (config = {}) => {
|
|
|
957
1027
|
if (config.customTypeModels.length > 0) {
|
|
958
1028
|
sourceFile.addTypeAlias({
|
|
959
1029
|
name: "AllDocumentTypes",
|
|
960
|
-
type: config.customTypeModels.map(
|
|
1030
|
+
type: config.customTypeModels.map(
|
|
1031
|
+
(customTypeModel) => buildTypeName(customTypeModel.id, "Document")
|
|
1032
|
+
).join(" | "),
|
|
961
1033
|
isExported: true
|
|
962
1034
|
});
|
|
963
1035
|
}
|
|
@@ -1019,17 +1091,26 @@ const configSchema = Joi.object({
|
|
|
1019
1091
|
clientIntegration: Joi.object({
|
|
1020
1092
|
includeCreateClientInterface: Joi.boolean()
|
|
1021
1093
|
}),
|
|
1022
|
-
locales: Joi.alternatives(
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1094
|
+
locales: Joi.alternatives(
|
|
1095
|
+
Joi.array().items(Joi.string().required()),
|
|
1096
|
+
Joi.object({
|
|
1097
|
+
ids: Joi.array().items(Joi.string().required()),
|
|
1098
|
+
fetchFromRepository: Joi.boolean()
|
|
1099
|
+
})
|
|
1100
|
+
),
|
|
1101
|
+
models: Joi.alternatives(
|
|
1102
|
+
Joi.array().items(Joi.string()),
|
|
1103
|
+
Joi.object({
|
|
1104
|
+
files: Joi.array().items(Joi.string()),
|
|
1105
|
+
fetchFromRepository: Joi.boolean()
|
|
1106
|
+
})
|
|
1107
|
+
),
|
|
1030
1108
|
fields: Joi.object({
|
|
1031
1109
|
embed: Joi.object({
|
|
1032
|
-
providerTypes: Joi.object().pattern(
|
|
1110
|
+
providerTypes: Joi.object().pattern(
|
|
1111
|
+
Joi.string(),
|
|
1112
|
+
Joi.string().required()
|
|
1113
|
+
)
|
|
1033
1114
|
}),
|
|
1034
1115
|
integrationFields: Joi.object({
|
|
1035
1116
|
catalogTypes: Joi.object().pattern(Joi.string(), Joi.string().required())
|
|
@@ -1130,7 +1211,8 @@ const loadConfig = (config) => {
|
|
|
1130
1211
|
return {};
|
|
1131
1212
|
};
|
|
1132
1213
|
|
|
1133
|
-
const cli = meow(
|
|
1214
|
+
const cli = meow(
|
|
1215
|
+
`
|
|
1134
1216
|
Usage:
|
|
1135
1217
|
prismic-ts-codegen [options...]
|
|
1136
1218
|
prismic-ts-codegen init [options...]
|
|
@@ -1140,16 +1222,18 @@ const cli = meow(`
|
|
|
1140
1222
|
|
|
1141
1223
|
Options:
|
|
1142
1224
|
-c, --config <path> Path to a prismic-ts-codegen configuration file.
|
|
1143
|
-
`,
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1225
|
+
`,
|
|
1226
|
+
{
|
|
1227
|
+
importMeta: import.meta,
|
|
1228
|
+
flags: {
|
|
1229
|
+
config: {
|
|
1230
|
+
type: "string",
|
|
1231
|
+
alias: "c",
|
|
1232
|
+
isRequired: false
|
|
1233
|
+
}
|
|
1150
1234
|
}
|
|
1151
1235
|
}
|
|
1152
|
-
|
|
1236
|
+
);
|
|
1153
1237
|
const main = async () => {
|
|
1154
1238
|
if (cli.input[0] === "init") {
|
|
1155
1239
|
const configPath = cli.flags.config || "prismicCodegen.config.ts";
|
|
@@ -1211,7 +1295,9 @@ Created prismic-ts-codegen config file: ${configPath}`);
|
|
|
1211
1295
|
}
|
|
1212
1296
|
});
|
|
1213
1297
|
if (config.clientIntegration?.includeCreateClientInterface && !hasCustomTypeModels) {
|
|
1214
|
-
console.info(
|
|
1298
|
+
console.info(
|
|
1299
|
+
"[INFO]: prismic-ts-codegen was configured to automatically integrate with `@prismicio/client`, but the integration was generated because no Custom Type models were found. Automatic integration requires at least one Custom Type model."
|
|
1300
|
+
);
|
|
1215
1301
|
}
|
|
1216
1302
|
if (config.output) {
|
|
1217
1303
|
writeFileSync(resolve(config.output), types);
|
package/dist/index.cjs
CHANGED
|
@@ -202,10 +202,18 @@ const pascalCase = (input) => pascalCase$1.pascalCase(input, {
|
|
|
202
202
|
transform: pascalCase$1.pascalCaseTransformMerge
|
|
203
203
|
});
|
|
204
204
|
|
|
205
|
-
const
|
|
205
|
+
const buildSharedSliceInterfaceNamePart = (config) => {
|
|
206
206
|
return pascalCase(`${config.id} Slice`);
|
|
207
207
|
};
|
|
208
208
|
|
|
209
|
+
const buildTypeName = (...parts) => {
|
|
210
|
+
let name = pascalCase(parts.filter(Boolean).join(" "));
|
|
211
|
+
if (/^[0-9]/.test(name) ? "_" : "") {
|
|
212
|
+
name = `_${name}`;
|
|
213
|
+
}
|
|
214
|
+
return name;
|
|
215
|
+
};
|
|
216
|
+
|
|
209
217
|
const addInterfacePropertyForField = (config) => {
|
|
210
218
|
switch (config.model.type) {
|
|
211
219
|
case "UID": {
|
|
@@ -255,12 +263,16 @@ const addInterfacePropertyForField = (config) => {
|
|
|
255
263
|
if (config.fieldConfigs.embed?.providerTypes) {
|
|
256
264
|
for (const providerType in config.fieldConfigs.embed?.providerTypes) {
|
|
257
265
|
const configuredProviderType = config.fieldConfigs.embed?.providerTypes[providerType];
|
|
258
|
-
providerTypes.push(
|
|
266
|
+
providerTypes.push(
|
|
267
|
+
`({ provider_name: "${providerType}" } & ${configuredProviderType})`
|
|
268
|
+
);
|
|
259
269
|
}
|
|
260
270
|
}
|
|
261
271
|
config.interface.addProperty({
|
|
262
272
|
name: config.id,
|
|
263
|
-
type: providerTypes.length > 0 ? `prismicT.EmbedField<prismicT.AnyOEmbed & prismicT.OEmbedExtra & (${providerTypes.join(
|
|
273
|
+
type: providerTypes.length > 0 ? `prismicT.EmbedField<prismicT.AnyOEmbed & prismicT.OEmbedExtra & (${providerTypes.join(
|
|
274
|
+
" | "
|
|
275
|
+
)})>` : "prismicT.EmbedField",
|
|
264
276
|
docs: buildFieldDocs({
|
|
265
277
|
id: config.id,
|
|
266
278
|
model: config.model,
|
|
@@ -299,7 +311,7 @@ const addInterfacePropertyForField = (config) => {
|
|
|
299
311
|
} else {
|
|
300
312
|
config.interface.addProperty({
|
|
301
313
|
name: config.id,
|
|
302
|
-
type: "prismicT.ImageField<
|
|
314
|
+
type: "prismicT.ImageField<never>",
|
|
303
315
|
docs: buildFieldDocs({
|
|
304
316
|
id: config.id,
|
|
305
317
|
model: config.model,
|
|
@@ -464,7 +476,13 @@ const addInterfacePropertyForField = (config) => {
|
|
|
464
476
|
}
|
|
465
477
|
case "Group": {
|
|
466
478
|
const itemInterface = config.sourceFile.addInterface({
|
|
467
|
-
name:
|
|
479
|
+
name: buildTypeName(
|
|
480
|
+
config.path[0].id,
|
|
481
|
+
"Document",
|
|
482
|
+
"Data",
|
|
483
|
+
config.id,
|
|
484
|
+
"Item"
|
|
485
|
+
),
|
|
468
486
|
docs: [
|
|
469
487
|
{
|
|
470
488
|
description: (writer) => {
|
|
@@ -516,12 +534,22 @@ const addInterfacePropertyForField = (config) => {
|
|
|
516
534
|
for (const choiceId in config.model.config.choices) {
|
|
517
535
|
const choice = config.model.config.choices[choiceId];
|
|
518
536
|
if (choice.type === types.CustomTypeModelSliceType.SharedSlice) {
|
|
519
|
-
choiceInterfaceNames.push(
|
|
537
|
+
choiceInterfaceNames.push(
|
|
538
|
+
buildSharedSliceInterfaceNamePart({ id: choiceId })
|
|
539
|
+
);
|
|
520
540
|
} else if (choice.type === types.CustomTypeModelSliceType.Slice) {
|
|
521
541
|
let primaryInterface;
|
|
522
542
|
if (choice["non-repeat"] && Object.keys(choice["non-repeat"]).length > 0) {
|
|
523
543
|
primaryInterface = config.sourceFile.addInterface({
|
|
524
|
-
name:
|
|
544
|
+
name: buildTypeName(
|
|
545
|
+
config.path[0].id,
|
|
546
|
+
"Document",
|
|
547
|
+
"Data",
|
|
548
|
+
config.id,
|
|
549
|
+
choiceId,
|
|
550
|
+
"Slice",
|
|
551
|
+
"Primary"
|
|
552
|
+
),
|
|
525
553
|
docs: [
|
|
526
554
|
{
|
|
527
555
|
description: (writer) => {
|
|
@@ -542,7 +570,9 @@ const addInterfacePropertyForField = (config) => {
|
|
|
542
570
|
}
|
|
543
571
|
]
|
|
544
572
|
});
|
|
545
|
-
writer.writeLine(
|
|
573
|
+
writer.writeLine(
|
|
574
|
+
`Primary content in ${humanReadablePath}`
|
|
575
|
+
);
|
|
546
576
|
}
|
|
547
577
|
}
|
|
548
578
|
]
|
|
@@ -572,7 +602,15 @@ const addInterfacePropertyForField = (config) => {
|
|
|
572
602
|
let itemInterface;
|
|
573
603
|
if (choice.repeat && Object.keys(choice.repeat).length > 0) {
|
|
574
604
|
itemInterface = config.sourceFile.addInterface({
|
|
575
|
-
name:
|
|
605
|
+
name: buildTypeName(
|
|
606
|
+
config.path[0].id,
|
|
607
|
+
"Document",
|
|
608
|
+
"Data",
|
|
609
|
+
config.id,
|
|
610
|
+
choiceId,
|
|
611
|
+
"Slice",
|
|
612
|
+
"Item"
|
|
613
|
+
),
|
|
576
614
|
docs: [
|
|
577
615
|
{
|
|
578
616
|
description: (writer) => {
|
|
@@ -622,7 +660,14 @@ const addInterfacePropertyForField = (config) => {
|
|
|
622
660
|
});
|
|
623
661
|
}
|
|
624
662
|
const sliceType = config.sourceFile.addTypeAlias({
|
|
625
|
-
name:
|
|
663
|
+
name: buildTypeName(
|
|
664
|
+
config.path[0].id,
|
|
665
|
+
"Document",
|
|
666
|
+
"Data",
|
|
667
|
+
config.id,
|
|
668
|
+
choiceId,
|
|
669
|
+
"Slice"
|
|
670
|
+
),
|
|
626
671
|
type: `prismicT.Slice<"${choiceId}", ${primaryInterface ? `Simplify<${primaryInterface.getName()}>` : "Record<string, never>"}, ${itemInterface ? `Simplify<${itemInterface.getName()}>` : "never"}>`,
|
|
627
672
|
isExported: true
|
|
628
673
|
});
|
|
@@ -631,7 +676,13 @@ const addInterfacePropertyForField = (config) => {
|
|
|
631
676
|
}
|
|
632
677
|
}
|
|
633
678
|
const slicesType = config.sourceFile.addTypeAlias({
|
|
634
|
-
name:
|
|
679
|
+
name: buildTypeName(
|
|
680
|
+
config.path[0].id,
|
|
681
|
+
"Document",
|
|
682
|
+
"Data",
|
|
683
|
+
config.id,
|
|
684
|
+
"Slice"
|
|
685
|
+
),
|
|
635
686
|
type: choiceInterfaceNames.length > 0 ? choiceInterfaceNames.join(" | ") : "never",
|
|
636
687
|
docs: [
|
|
637
688
|
{
|
|
@@ -702,7 +753,7 @@ const addTypeAliasForCustomType = ({
|
|
|
702
753
|
let dataInterface;
|
|
703
754
|
if (hasDataFields) {
|
|
704
755
|
dataInterface = sourceFile.addInterface({
|
|
705
|
-
name:
|
|
756
|
+
name: buildTypeName(model.id, "Document", "Data"),
|
|
706
757
|
docs: [
|
|
707
758
|
{
|
|
708
759
|
description: `Content for ${model.label} documents`
|
|
@@ -727,7 +778,7 @@ const addTypeAliasForCustomType = ({
|
|
|
727
778
|
}
|
|
728
779
|
} else {
|
|
729
780
|
dataInterface = sourceFile.addTypeAlias({
|
|
730
|
-
name:
|
|
781
|
+
name: buildTypeName(model.id, "Document", "Data"),
|
|
731
782
|
type: `Record<string, never>`,
|
|
732
783
|
docs: [
|
|
733
784
|
{
|
|
@@ -737,7 +788,7 @@ const addTypeAliasForCustomType = ({
|
|
|
737
788
|
});
|
|
738
789
|
}
|
|
739
790
|
return sourceFile.addTypeAlias({
|
|
740
|
-
name:
|
|
791
|
+
name: buildTypeName(model.id, "Document"),
|
|
741
792
|
typeParameters: [
|
|
742
793
|
{
|
|
743
794
|
name: "Lang",
|
|
@@ -753,7 +804,9 @@ const addTypeAliasForCustomType = ({
|
|
|
753
804
|
writer.blankLine();
|
|
754
805
|
writer.writeLine(`- **API ID**: \`${model.id}\``);
|
|
755
806
|
writer.writeLine(`- **Repeatable**: \`${model.repeatable}\``);
|
|
756
|
-
writer.writeLine(
|
|
807
|
+
writer.writeLine(
|
|
808
|
+
`- **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}`
|
|
809
|
+
);
|
|
757
810
|
},
|
|
758
811
|
tags: [
|
|
759
812
|
{
|
|
@@ -773,7 +826,11 @@ const addTypeAliasForSharedSlice = (config) => {
|
|
|
773
826
|
let primaryInterface;
|
|
774
827
|
if (variation.primary && Object.keys(variation.primary).length > 0) {
|
|
775
828
|
primaryInterface = config.sourceFile.addInterface({
|
|
776
|
-
name:
|
|
829
|
+
name: buildTypeName(
|
|
830
|
+
buildSharedSliceInterfaceNamePart({ id: config.model.id }),
|
|
831
|
+
variation.id,
|
|
832
|
+
"Primary"
|
|
833
|
+
),
|
|
777
834
|
docs: [
|
|
778
835
|
{
|
|
779
836
|
description: (writer) => {
|
|
@@ -814,7 +871,11 @@ const addTypeAliasForSharedSlice = (config) => {
|
|
|
814
871
|
let itemInterface;
|
|
815
872
|
if (variation.items && Object.keys(variation.items).length > 0) {
|
|
816
873
|
itemInterface = config.sourceFile.addInterface({
|
|
817
|
-
name:
|
|
874
|
+
name: buildTypeName(
|
|
875
|
+
buildSharedSliceInterfaceNamePart({ id: config.model.id }),
|
|
876
|
+
variation.id,
|
|
877
|
+
"Item"
|
|
878
|
+
),
|
|
818
879
|
docs: [
|
|
819
880
|
{
|
|
820
881
|
description: (writer) => {
|
|
@@ -854,18 +915,23 @@ const addTypeAliasForSharedSlice = (config) => {
|
|
|
854
915
|
});
|
|
855
916
|
}
|
|
856
917
|
const variationType = config.sourceFile.addTypeAlias({
|
|
857
|
-
name:
|
|
858
|
-
id: config.model.id
|
|
859
|
-
|
|
918
|
+
name: buildTypeName(
|
|
919
|
+
buildSharedSliceInterfaceNamePart({ id: config.model.id }),
|
|
920
|
+
variation.id
|
|
921
|
+
),
|
|
860
922
|
type: `prismicT.SharedSliceVariation<"${variation.id}", ${primaryInterface ? `Simplify<${primaryInterface.getName()}>` : "Record<string, never>"}, ${itemInterface ? `Simplify<${itemInterface.getName()}>` : "never"}>`,
|
|
861
923
|
docs: [
|
|
862
924
|
{
|
|
863
925
|
description: (writer) => {
|
|
864
|
-
writer.writeLine(
|
|
926
|
+
writer.writeLine(
|
|
927
|
+
`${variation.name} variation for ${config.model.name} Slice`
|
|
928
|
+
);
|
|
865
929
|
writer.blankLine();
|
|
866
930
|
writer.writeLine(`- **API ID**: \`${variation.id}\``);
|
|
867
931
|
writer.writeLine(`- **Description**: \`${variation.description}\``);
|
|
868
|
-
writer.writeLine(
|
|
932
|
+
writer.writeLine(
|
|
933
|
+
`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`
|
|
934
|
+
);
|
|
869
935
|
}
|
|
870
936
|
}
|
|
871
937
|
],
|
|
@@ -874,7 +940,7 @@ const addTypeAliasForSharedSlice = (config) => {
|
|
|
874
940
|
variationTypeNames.push(variationType.getName());
|
|
875
941
|
}
|
|
876
942
|
const variationsType = config.sourceFile.addTypeAlias({
|
|
877
|
-
name:
|
|
943
|
+
name: buildTypeName(config.model.id, "Slice", "Variation"),
|
|
878
944
|
type: variationTypeNames.length > 0 ? variationTypeNames.join(" | ") : "never",
|
|
879
945
|
docs: [
|
|
880
946
|
{
|
|
@@ -893,9 +959,9 @@ const addTypeAliasForSharedSlice = (config) => {
|
|
|
893
959
|
]
|
|
894
960
|
});
|
|
895
961
|
return config.sourceFile.addTypeAlias({
|
|
896
|
-
name:
|
|
897
|
-
id: config.model.id
|
|
898
|
-
|
|
962
|
+
name: buildTypeName(
|
|
963
|
+
buildSharedSliceInterfaceNamePart({ id: config.model.id })
|
|
964
|
+
),
|
|
899
965
|
type: `prismicT.SharedSlice<"${config.model.id}", ${variationsType.getName()}>`,
|
|
900
966
|
docs: [
|
|
901
967
|
{
|
|
@@ -903,8 +969,12 @@ const addTypeAliasForSharedSlice = (config) => {
|
|
|
903
969
|
writer.writeLine(`${config.model.name} Shared Slice`);
|
|
904
970
|
writer.blankLine();
|
|
905
971
|
writer.writeLine(`- **API ID**: \`${config.model.id}\``);
|
|
906
|
-
writer.writeLine(
|
|
907
|
-
|
|
972
|
+
writer.writeLine(
|
|
973
|
+
`- **Description**: \`${config.model.description}\``
|
|
974
|
+
);
|
|
975
|
+
writer.writeLine(
|
|
976
|
+
`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`
|
|
977
|
+
);
|
|
908
978
|
}
|
|
909
979
|
}
|
|
910
980
|
],
|
|
@@ -950,7 +1020,9 @@ const generateTypes = (config = {}) => {
|
|
|
950
1020
|
if (config.customTypeModels.length > 0) {
|
|
951
1021
|
sourceFile.addTypeAlias({
|
|
952
1022
|
name: "AllDocumentTypes",
|
|
953
|
-
type: config.customTypeModels.map(
|
|
1023
|
+
type: config.customTypeModels.map(
|
|
1024
|
+
(customTypeModel) => buildTypeName(customTypeModel.id, "Document")
|
|
1025
|
+
).join(" | "),
|
|
954
1026
|
isExported: true
|
|
955
1027
|
});
|
|
956
1028
|
}
|