prismic-ts-codegen 0.1.11 → 0.1.13
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/dist/_node_modules/quick-lru/index.cjs +234 -0
- package/dist/_node_modules/quick-lru/index.cjs.map +1 -0
- package/dist/_node_modules/quick-lru/index.js +235 -0
- package/dist/_node_modules/quick-lru/index.js.map +1 -0
- package/dist/constants.cjs +19 -21
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.ts +2 -3
- package/dist/constants.js +19 -21
- package/dist/constants.js.map +1 -1
- package/dist/generateTypes.cjs +71 -90
- package/dist/generateTypes.cjs.map +1 -1
- package/dist/generateTypes.d.ts +2 -1
- package/dist/generateTypes.js +71 -90
- package/dist/generateTypes.js.map +1 -1
- package/dist/lib/addBlankLine.cjs +12 -0
- package/dist/lib/addBlankLine.cjs.map +1 -0
- package/dist/lib/addBlankLine.d.ts +5 -0
- package/dist/lib/addBlankLine.js +12 -0
- package/dist/lib/addBlankLine.js.map +1 -0
- package/dist/lib/addLine.cjs +8 -0
- package/dist/lib/addLine.cjs.map +1 -0
- package/dist/lib/addLine.d.ts +1 -0
- package/dist/lib/addLine.js +8 -0
- package/dist/lib/addLine.js.map +1 -0
- package/dist/lib/addSection.cjs +8 -0
- package/dist/lib/addSection.cjs.map +1 -0
- package/dist/lib/addSection.d.ts +1 -0
- package/dist/lib/addSection.js +8 -0
- package/dist/lib/addSection.js.map +1 -0
- package/dist/lib/addTrailingNewLine.cjs +11 -0
- package/dist/lib/addTrailingNewLine.cjs.map +1 -0
- package/dist/lib/addTrailingNewLine.d.ts +5 -0
- package/dist/lib/addTrailingNewLine.js +11 -0
- package/dist/lib/addTrailingNewLine.js.map +1 -0
- package/dist/lib/buildCustomTypeDataType.cjs +51 -0
- package/dist/lib/buildCustomTypeDataType.cjs.map +1 -0
- package/dist/lib/buildCustomTypeDataType.d.ts +13 -0
- package/dist/lib/buildCustomTypeDataType.js +51 -0
- package/dist/lib/buildCustomTypeDataType.js.map +1 -0
- package/dist/lib/buildCustomTypeType.cjs +60 -0
- package/dist/lib/buildCustomTypeType.cjs.map +1 -0
- package/dist/lib/buildCustomTypeType.d.ts +17 -0
- package/dist/lib/buildCustomTypeType.js +60 -0
- package/dist/lib/buildCustomTypeType.js.map +1 -0
- package/dist/lib/buildFieldDocs.cjs +67 -35
- package/dist/lib/buildFieldDocs.cjs.map +1 -1
- package/dist/lib/buildFieldDocs.d.ts +7 -11
- package/dist/lib/buildFieldDocs.js +67 -35
- package/dist/lib/buildFieldDocs.js.map +1 -1
- package/dist/lib/buildFieldProperties.cjs +300 -0
- package/dist/lib/buildFieldProperties.cjs.map +1 -0
- package/dist/lib/buildFieldProperties.d.ts +14 -0
- package/dist/lib/buildFieldProperties.js +300 -0
- package/dist/lib/buildFieldProperties.js.map +1 -0
- package/dist/lib/buildSharedSliceType.cjs +140 -0
- package/dist/lib/buildSharedSliceType.cjs.map +1 -0
- package/dist/lib/buildSharedSliceType.d.ts +16 -0
- package/dist/lib/buildSharedSliceType.js +140 -0
- package/dist/lib/buildSharedSliceType.js.map +1 -0
- package/dist/lib/buildTypeName.cjs +4 -2
- package/dist/lib/buildTypeName.cjs.map +1 -1
- package/dist/lib/buildTypeName.js +4 -2
- package/dist/lib/buildTypeName.js.map +1 -1
- package/dist/lib/buildUnion.cjs +7 -0
- package/dist/lib/buildUnion.cjs.map +1 -0
- package/dist/lib/buildUnion.d.ts +1 -0
- package/dist/lib/buildUnion.js +7 -0
- package/dist/lib/buildUnion.js.map +1 -0
- package/dist/lib/checkHasUIDFIeld.cjs +7 -0
- package/dist/lib/checkHasUIDFIeld.cjs.map +1 -0
- package/dist/lib/checkHasUIDFIeld.d.ts +2 -0
- package/dist/lib/checkHasUIDFIeld.js +7 -0
- package/dist/lib/checkHasUIDFIeld.js.map +1 -0
- package/dist/lib/getAPIIDPath.cjs +18 -14
- package/dist/lib/getAPIIDPath.cjs.map +1 -1
- package/dist/lib/getAPIIDPath.d.ts +4 -8
- package/dist/lib/getAPIIDPath.js +18 -14
- package/dist/lib/getAPIIDPath.js.map +1 -1
- package/dist/lib/getCacheKey.cjs +25 -0
- package/dist/lib/getCacheKey.cjs.map +1 -0
- package/dist/lib/getCacheKey.d.ts +9 -0
- package/dist/lib/getCacheKey.js +8 -0
- package/dist/lib/getCacheKey.js.map +1 -0
- package/dist/lib/getHumanReadableModelName.cjs +13 -17
- package/dist/lib/getHumanReadableModelName.cjs.map +1 -1
- package/dist/lib/getHumanReadableModelName.d.ts +3 -3
- package/dist/lib/getHumanReadableModelName.js +13 -17
- package/dist/lib/getHumanReadableModelName.js.map +1 -1
- package/dist/lib/{getHumanReadableFieldPath.cjs → getHumanReadablePath.cjs} +8 -8
- package/dist/lib/getHumanReadablePath.cjs.map +1 -0
- package/dist/lib/getHumanReadablePath.d.ts +6 -0
- package/dist/lib/{getHumanReadableFieldPath.js → getHumanReadablePath.js} +8 -8
- package/dist/lib/getHumanReadablePath.js.map +1 -0
- package/dist/types.d.ts +9 -1
- package/package.json +18 -17
- package/src/constants.ts +19 -22
- package/src/generateTypes.ts +109 -108
- package/src/lib/addBlankLine.ts +13 -0
- package/src/lib/addLine.ts +5 -0
- package/src/lib/addSection.ts +5 -0
- package/src/lib/addTrailingNewLine.ts +14 -0
- package/src/lib/buildCustomTypeDataType.ts +74 -0
- package/src/lib/buildCustomTypeType.ts +101 -0
- package/src/lib/buildFieldDocs.ts +128 -68
- package/src/lib/buildFieldProperties.ts +513 -0
- package/src/lib/buildSharedSliceType.ts +213 -0
- package/src/lib/buildTypeName.ts +4 -2
- package/src/lib/buildUnion.ts +3 -0
- package/src/lib/checkHasUIDFIeld.ts +5 -0
- package/src/lib/getAPIIDPath.ts +40 -41
- package/src/lib/getCacheKey.ts +13 -0
- package/src/lib/getHumanReadableModelName.ts +23 -20
- package/src/lib/getHumanReadablePath.ts +24 -0
- package/src/types.ts +11 -1
- package/dist/lib/addInterfacePropertiesForFields.cjs +0 -489
- package/dist/lib/addInterfacePropertiesForFields.cjs.map +0 -1
- package/dist/lib/addInterfacePropertiesForFields.d.ts +0 -21
- package/dist/lib/addInterfacePropertiesForFields.js +0 -489
- package/dist/lib/addInterfacePropertiesForFields.js.map +0 -1
- package/dist/lib/addTypeAliasForCustomType.cjs +0 -81
- package/dist/lib/addTypeAliasForCustomType.cjs.map +0 -1
- package/dist/lib/addTypeAliasForCustomType.d.ts +0 -11
- package/dist/lib/addTypeAliasForCustomType.js +0 -81
- package/dist/lib/addTypeAliasForCustomType.js.map +0 -1
- package/dist/lib/addTypeAliasForSharedSlice.cjs +0 -149
- package/dist/lib/addTypeAliasForSharedSlice.cjs.map +0 -1
- package/dist/lib/addTypeAliasForSharedSlice.d.ts +0 -10
- package/dist/lib/addTypeAliasForSharedSlice.js +0 -149
- package/dist/lib/addTypeAliasForSharedSlice.js.map +0 -1
- package/dist/lib/buildSharedSliceInterfaceNamePart.cjs +0 -8
- package/dist/lib/buildSharedSliceInterfaceNamePart.cjs.map +0 -1
- package/dist/lib/buildSharedSliceInterfaceNamePart.d.ts +0 -5
- package/dist/lib/buildSharedSliceInterfaceNamePart.js +0 -8
- package/dist/lib/buildSharedSliceInterfaceNamePart.js.map +0 -1
- package/dist/lib/getFieldDocumentationURL.cjs +0 -8
- package/dist/lib/getFieldDocumentationURL.cjs.map +0 -1
- package/dist/lib/getFieldDocumentationURL.d.ts +0 -6
- package/dist/lib/getFieldDocumentationURL.js +0 -8
- package/dist/lib/getFieldDocumentationURL.js.map +0 -1
- package/dist/lib/getHumanReadableFieldPath.cjs.map +0 -1
- package/dist/lib/getHumanReadableFieldPath.d.ts +0 -10
- package/dist/lib/getHumanReadableFieldPath.js.map +0 -1
- package/dist/lib/getHumanReadableFieldType.cjs +0 -36
- package/dist/lib/getHumanReadableFieldType.cjs.map +0 -1
- package/dist/lib/getHumanReadableFieldType.d.ts +0 -6
- package/dist/lib/getHumanReadableFieldType.js +0 -36
- package/dist/lib/getHumanReadableFieldType.js.map +0 -1
- package/dist/lib/getSourceFileText.cjs +0 -9
- package/dist/lib/getSourceFileText.cjs.map +0 -1
- package/dist/lib/getSourceFileText.d.ts +0 -2
- package/dist/lib/getSourceFileText.js +0 -9
- package/dist/lib/getSourceFileText.js.map +0 -1
- package/dist/lib/hasOwnProperty.cjs +0 -7
- package/dist/lib/hasOwnProperty.cjs.map +0 -1
- package/dist/lib/hasOwnProperty.d.ts +0 -10
- package/dist/lib/hasOwnProperty.js +0 -7
- package/dist/lib/hasOwnProperty.js.map +0 -1
- package/dist/lib/isCustomTypeModel.cjs +0 -7
- package/dist/lib/isCustomTypeModel.cjs.map +0 -1
- package/dist/lib/isCustomTypeModel.d.ts +0 -2
- package/dist/lib/isCustomTypeModel.js +0 -7
- package/dist/lib/isCustomTypeModel.js.map +0 -1
- package/dist/lib/isCustomTypeModelField.cjs +0 -7
- package/dist/lib/isCustomTypeModelField.cjs.map +0 -1
- package/dist/lib/isCustomTypeModelField.d.ts +0 -2
- package/dist/lib/isCustomTypeModelField.js +0 -7
- package/dist/lib/isCustomTypeModelField.js.map +0 -1
- package/dist/lib/isCustomTypeModelSlice.cjs +0 -8
- package/dist/lib/isCustomTypeModelSlice.cjs.map +0 -1
- package/dist/lib/isCustomTypeModelSlice.d.ts +0 -2
- package/dist/lib/isCustomTypeModelSlice.js +0 -8
- package/dist/lib/isCustomTypeModelSlice.js.map +0 -1
- package/dist/lib/isSharedSliceModel.cjs +0 -8
- package/dist/lib/isSharedSliceModel.cjs.map +0 -1
- package/dist/lib/isSharedSliceModel.d.ts +0 -2
- package/dist/lib/isSharedSliceModel.js +0 -8
- package/dist/lib/isSharedSliceModel.js.map +0 -1
- package/dist/lib/pascalCase.cjs +0 -8
- package/dist/lib/pascalCase.cjs.map +0 -1
- package/dist/lib/pascalCase.d.ts +0 -1
- package/dist/lib/pascalCase.js +0 -8
- package/dist/lib/pascalCase.js.map +0 -1
- package/dist/lib/writeFieldDocsDescription.cjs +0 -29
- package/dist/lib/writeFieldDocsDescription.cjs.map +0 -1
- package/dist/lib/writeFieldDocsDescription.d.ts +0 -13
- package/dist/lib/writeFieldDocsDescription.js +0 -29
- package/dist/lib/writeFieldDocsDescription.js.map +0 -1
- package/src/lib/addInterfacePropertiesForFields.ts +0 -665
- package/src/lib/addTypeAliasForCustomType.ts +0 -120
- package/src/lib/addTypeAliasForSharedSlice.ts +0 -201
- package/src/lib/buildSharedSliceInterfaceNamePart.ts +0 -11
- package/src/lib/getFieldDocumentationURL.ts +0 -15
- package/src/lib/getHumanReadableFieldPath.ts +0 -36
- package/src/lib/getHumanReadableFieldType.ts +0 -55
- package/src/lib/getSourceFileText.ts +0 -14
- package/src/lib/hasOwnProperty.ts +0 -15
- package/src/lib/isCustomTypeModel.ts +0 -5
- package/src/lib/isCustomTypeModelField.ts +0 -7
- package/src/lib/isCustomTypeModelSlice.ts +0 -14
- package/src/lib/isSharedSliceModel.ts +0 -14
- package/src/lib/pascalCase.ts +0 -9
- package/src/lib/writeFieldDocsDescription.ts +0 -51
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import type { CustomTypeModel, CustomTypeModelField } from "@prismicio/client";
|
|
2
|
-
import type {
|
|
3
|
-
InterfaceDeclaration,
|
|
4
|
-
SourceFile,
|
|
5
|
-
TypeAliasDeclaration,
|
|
6
|
-
} from "ts-morph";
|
|
7
|
-
|
|
8
|
-
import { FieldConfigs } from "../types";
|
|
9
|
-
|
|
10
|
-
import { CUSTOM_TYPES_DOCUMENTATION_URL } from "../constants";
|
|
11
|
-
|
|
12
|
-
import { addInterfacePropertiesForFields } from "./addInterfacePropertiesForFields";
|
|
13
|
-
import { buildTypeName } from "./buildTypeName";
|
|
14
|
-
|
|
15
|
-
const collectCustomTypeFields = (
|
|
16
|
-
model: CustomTypeModel,
|
|
17
|
-
): Record<string, CustomTypeModelField> => {
|
|
18
|
-
return Object.assign({}, ...Object.values(model.json));
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
type AddTypeAliasForCustomTypeConfig = {
|
|
22
|
-
model: CustomTypeModel;
|
|
23
|
-
sourceFile: SourceFile;
|
|
24
|
-
localeIDs: string[];
|
|
25
|
-
fieldConfigs: FieldConfigs;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const addTypeAliasForCustomType = ({
|
|
29
|
-
model,
|
|
30
|
-
sourceFile,
|
|
31
|
-
localeIDs,
|
|
32
|
-
fieldConfigs,
|
|
33
|
-
}: AddTypeAliasForCustomTypeConfig): TypeAliasDeclaration => {
|
|
34
|
-
const { uid: uidField, ...fields } = collectCustomTypeFields(model);
|
|
35
|
-
const hasDataFields = Object.keys(fields).length > 0;
|
|
36
|
-
const hasUIDField = Boolean(uidField);
|
|
37
|
-
|
|
38
|
-
let dataInterface: InterfaceDeclaration | TypeAliasDeclaration;
|
|
39
|
-
if (hasDataFields) {
|
|
40
|
-
dataInterface = sourceFile.addInterface({
|
|
41
|
-
name: buildTypeName(model.id, "Document", "Data"),
|
|
42
|
-
docs: [
|
|
43
|
-
{
|
|
44
|
-
description: `Content for ${model.label} documents`,
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
for (const tabName in model.json) {
|
|
50
|
-
// This is destructured to ensure the UID field is
|
|
51
|
-
// ignored.
|
|
52
|
-
const { uid: _uidField, ...tabFields } = model.json[tabName];
|
|
53
|
-
|
|
54
|
-
addInterfacePropertiesForFields({
|
|
55
|
-
fields: tabFields,
|
|
56
|
-
interface: dataInterface,
|
|
57
|
-
sourceFile: sourceFile,
|
|
58
|
-
path: [
|
|
59
|
-
{
|
|
60
|
-
id: model.id,
|
|
61
|
-
model: model,
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
fieldConfigs,
|
|
65
|
-
tabName,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
dataInterface = sourceFile.addTypeAlias({
|
|
70
|
-
name: buildTypeName(model.id, "Document", "Data"),
|
|
71
|
-
type: `Record<string, never>`,
|
|
72
|
-
docs: [
|
|
73
|
-
{
|
|
74
|
-
description: `Content for ${model.label} documents`,
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return sourceFile.addTypeAlias({
|
|
81
|
-
name: buildTypeName(model.id, "Document"),
|
|
82
|
-
typeParameters: [
|
|
83
|
-
{
|
|
84
|
-
name: "Lang",
|
|
85
|
-
constraint: "string",
|
|
86
|
-
default:
|
|
87
|
-
localeIDs.length > 0
|
|
88
|
-
? localeIDs.map((localeID) => `"${localeID}"`).join(" | ")
|
|
89
|
-
: "string",
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
type: hasUIDField
|
|
93
|
-
? `prismic.PrismicDocumentWithUID<Simplify<${dataInterface.getName()}>, "${
|
|
94
|
-
model.id
|
|
95
|
-
}", Lang>`
|
|
96
|
-
: `prismic.PrismicDocumentWithoutUID<Simplify<${dataInterface.getName()}>, "${
|
|
97
|
-
model.id
|
|
98
|
-
}", Lang>`,
|
|
99
|
-
docs: [
|
|
100
|
-
{
|
|
101
|
-
description: (writer) => {
|
|
102
|
-
writer.writeLine(`${model.label} document from Prismic`);
|
|
103
|
-
writer.blankLine();
|
|
104
|
-
writer.writeLine(`- **API ID**: \`${model.id}\``);
|
|
105
|
-
writer.writeLine(`- **Repeatable**: \`${model.repeatable}\``);
|
|
106
|
-
writer.writeLine(
|
|
107
|
-
`- **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}`,
|
|
108
|
-
);
|
|
109
|
-
},
|
|
110
|
-
tags: [
|
|
111
|
-
{
|
|
112
|
-
tagName: "typeParam",
|
|
113
|
-
text: "Lang - Language API ID of the document.",
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
isExported: true,
|
|
119
|
-
});
|
|
120
|
-
};
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import type { SharedSliceModel } from "@prismicio/client";
|
|
2
|
-
import type {
|
|
3
|
-
InterfaceDeclaration,
|
|
4
|
-
SourceFile,
|
|
5
|
-
TypeAliasDeclaration,
|
|
6
|
-
} from "ts-morph";
|
|
7
|
-
|
|
8
|
-
import { FieldConfigs } from "../types";
|
|
9
|
-
|
|
10
|
-
import { SHARED_SLICES_DOCUMENTATION_URL } from "../constants";
|
|
11
|
-
|
|
12
|
-
import { addInterfacePropertiesForFields } from "./addInterfacePropertiesForFields";
|
|
13
|
-
import { buildSharedSliceInterfaceNamePart } from "./buildSharedSliceInterfaceNamePart";
|
|
14
|
-
import { buildTypeName } from "./buildTypeName";
|
|
15
|
-
import { getHumanReadableFieldPath } from "./getHumanReadableFieldPath";
|
|
16
|
-
|
|
17
|
-
type AddTypeAliasForSharedSliceConfig = {
|
|
18
|
-
model: SharedSliceModel;
|
|
19
|
-
sourceFile: SourceFile;
|
|
20
|
-
fieldConfigs: FieldConfigs;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const addTypeAliasForSharedSlice = (
|
|
24
|
-
config: AddTypeAliasForSharedSliceConfig,
|
|
25
|
-
): TypeAliasDeclaration => {
|
|
26
|
-
const variationTypeNames: string[] = [];
|
|
27
|
-
|
|
28
|
-
for (const variation of config.model.variations) {
|
|
29
|
-
let primaryInterface: InterfaceDeclaration | undefined;
|
|
30
|
-
if (variation.primary && Object.keys(variation.primary).length > 0) {
|
|
31
|
-
primaryInterface = config.sourceFile.addInterface({
|
|
32
|
-
name: buildTypeName(
|
|
33
|
-
buildSharedSliceInterfaceNamePart({ id: config.model.id }),
|
|
34
|
-
variation.id,
|
|
35
|
-
"Primary",
|
|
36
|
-
),
|
|
37
|
-
docs: [
|
|
38
|
-
{
|
|
39
|
-
description: (writer) => {
|
|
40
|
-
const humanReadablePath = getHumanReadableFieldPath({
|
|
41
|
-
path: [
|
|
42
|
-
{
|
|
43
|
-
id: config.model.id,
|
|
44
|
-
model: config.model,
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
id: "primary",
|
|
48
|
-
label: "Primary",
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
writer.writeLine(`Primary content in ${humanReadablePath}`);
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
});
|
|
58
|
-
addInterfacePropertiesForFields({
|
|
59
|
-
interface: primaryInterface,
|
|
60
|
-
sourceFile: config.sourceFile,
|
|
61
|
-
fields: variation.primary,
|
|
62
|
-
path: [
|
|
63
|
-
{
|
|
64
|
-
id: config.model.id,
|
|
65
|
-
model: config.model,
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
id: "primary",
|
|
69
|
-
label: "Primary",
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
fieldConfigs: config.fieldConfigs,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
let itemInterface: InterfaceDeclaration | undefined;
|
|
77
|
-
if (variation.items && Object.keys(variation.items).length > 0) {
|
|
78
|
-
itemInterface = config.sourceFile.addInterface({
|
|
79
|
-
name: buildTypeName(
|
|
80
|
-
buildSharedSliceInterfaceNamePart({ id: config.model.id }),
|
|
81
|
-
variation.id,
|
|
82
|
-
"Item",
|
|
83
|
-
),
|
|
84
|
-
docs: [
|
|
85
|
-
{
|
|
86
|
-
description: (writer) => {
|
|
87
|
-
const humanReadablePath = getHumanReadableFieldPath({
|
|
88
|
-
path: [
|
|
89
|
-
{
|
|
90
|
-
id: config.model.id,
|
|
91
|
-
model: config.model,
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
id: "items",
|
|
95
|
-
label: "Items",
|
|
96
|
-
},
|
|
97
|
-
],
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
writer.writeLine(`Item in ${humanReadablePath}`);
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
],
|
|
104
|
-
isExported: true,
|
|
105
|
-
});
|
|
106
|
-
addInterfacePropertiesForFields({
|
|
107
|
-
interface: itemInterface,
|
|
108
|
-
sourceFile: config.sourceFile,
|
|
109
|
-
fields: variation.items,
|
|
110
|
-
path: [
|
|
111
|
-
{
|
|
112
|
-
id: config.model.id,
|
|
113
|
-
model: config.model,
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
id: "items",
|
|
117
|
-
label: "Items",
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
fieldConfigs: config.fieldConfigs,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const variationType = config.sourceFile.addTypeAlias({
|
|
125
|
-
name: buildTypeName(
|
|
126
|
-
buildSharedSliceInterfaceNamePart({ id: config.model.id }),
|
|
127
|
-
variation.id,
|
|
128
|
-
),
|
|
129
|
-
type: `prismic.SharedSliceVariation<"${variation.id}", ${
|
|
130
|
-
primaryInterface
|
|
131
|
-
? `Simplify<${primaryInterface.getName()}>`
|
|
132
|
-
: "Record<string, never>"
|
|
133
|
-
}, ${itemInterface ? `Simplify<${itemInterface.getName()}>` : "never"}>`,
|
|
134
|
-
docs: [
|
|
135
|
-
{
|
|
136
|
-
description: (writer) => {
|
|
137
|
-
writer.writeLine(
|
|
138
|
-
`${variation.name} variation for ${config.model.name} Slice`,
|
|
139
|
-
);
|
|
140
|
-
writer.blankLine();
|
|
141
|
-
writer.writeLine(`- **API ID**: \`${variation.id}\``);
|
|
142
|
-
writer.writeLine(`- **Description**: \`${variation.description}\``);
|
|
143
|
-
writer.writeLine(
|
|
144
|
-
`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`,
|
|
145
|
-
);
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
isExported: true,
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
variationTypeNames.push(variationType.getName());
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const variationsType = config.sourceFile.addTypeAlias({
|
|
156
|
-
name: buildTypeName(config.model.id, "Slice", "Variation"),
|
|
157
|
-
type:
|
|
158
|
-
variationTypeNames.length > 0 ? variationTypeNames.join(" | ") : "never",
|
|
159
|
-
docs: [
|
|
160
|
-
{
|
|
161
|
-
description: (writer) => {
|
|
162
|
-
const humanReadablePath = getHumanReadableFieldPath({
|
|
163
|
-
path: [
|
|
164
|
-
{
|
|
165
|
-
id: config.model.id,
|
|
166
|
-
model: config.model,
|
|
167
|
-
},
|
|
168
|
-
],
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
writer.writeLine(`Slice variation for *${humanReadablePath}*`);
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
return config.sourceFile.addTypeAlias({
|
|
178
|
-
name: buildTypeName(
|
|
179
|
-
buildSharedSliceInterfaceNamePart({ id: config.model.id }),
|
|
180
|
-
),
|
|
181
|
-
type: `prismic.SharedSlice<"${
|
|
182
|
-
config.model.id
|
|
183
|
-
}", ${variationsType.getName()}>`,
|
|
184
|
-
docs: [
|
|
185
|
-
{
|
|
186
|
-
description: (writer) => {
|
|
187
|
-
writer.writeLine(`${config.model.name} Shared Slice`);
|
|
188
|
-
writer.blankLine();
|
|
189
|
-
writer.writeLine(`- **API ID**: \`${config.model.id}\``);
|
|
190
|
-
writer.writeLine(
|
|
191
|
-
`- **Description**: \`${config.model.description}\``,
|
|
192
|
-
);
|
|
193
|
-
writer.writeLine(
|
|
194
|
-
`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`,
|
|
195
|
-
);
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
],
|
|
199
|
-
isExported: true,
|
|
200
|
-
});
|
|
201
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { pascalCase } from "./pascalCase";
|
|
2
|
-
|
|
3
|
-
type BuildSharedSliceInterfaceNamePartConfig = {
|
|
4
|
-
id: string;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export const buildSharedSliceInterfaceNamePart = (
|
|
8
|
-
config: BuildSharedSliceInterfaceNamePartConfig,
|
|
9
|
-
): string => {
|
|
10
|
-
return pascalCase(`${config.id} Slice`);
|
|
11
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { CustomTypeModelField } from "@prismicio/client";
|
|
2
|
-
|
|
3
|
-
import { FIELD_DOCUMENTATION_URLS } from "../constants";
|
|
4
|
-
|
|
5
|
-
type GetFieldDocumentationURLConfig = {
|
|
6
|
-
model: CustomTypeModelField;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const getFieldDocumentationURL = (
|
|
10
|
-
config: GetFieldDocumentationURLConfig,
|
|
11
|
-
): string | undefined => {
|
|
12
|
-
return FIELD_DOCUMENTATION_URLS[
|
|
13
|
-
config.model.type as keyof typeof FIELD_DOCUMENTATION_URLS
|
|
14
|
-
];
|
|
15
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CustomTypeModel,
|
|
3
|
-
CustomTypeModelField,
|
|
4
|
-
CustomTypeModelSlice,
|
|
5
|
-
SharedSliceModel,
|
|
6
|
-
} from "@prismicio/client";
|
|
7
|
-
|
|
8
|
-
import { PathElement } from "../types";
|
|
9
|
-
|
|
10
|
-
import { getHumanReadableModelName } from "./getHumanReadableModelName";
|
|
11
|
-
|
|
12
|
-
type GetHumanReadableFieldPathConfig = {
|
|
13
|
-
path: [
|
|
14
|
-
PathElement<CustomTypeModel | SharedSliceModel>,
|
|
15
|
-
...PathElement<CustomTypeModelField | CustomTypeModelSlice>[],
|
|
16
|
-
];
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const getHumanReadableFieldPath = (
|
|
20
|
-
config: GetHumanReadableFieldPathConfig,
|
|
21
|
-
): string => {
|
|
22
|
-
return config.path
|
|
23
|
-
.map((element) => {
|
|
24
|
-
if (element.label) {
|
|
25
|
-
return element.label;
|
|
26
|
-
} else if (element.model) {
|
|
27
|
-
return getHumanReadableModelName({
|
|
28
|
-
id: element.id,
|
|
29
|
-
model: element.model,
|
|
30
|
-
});
|
|
31
|
-
} else {
|
|
32
|
-
return element.id;
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
.join(" → ");
|
|
36
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { CustomTypeModelField } from "@prismicio/client";
|
|
2
|
-
|
|
3
|
-
type GetFieldHumanReadableTypeConfig = {
|
|
4
|
-
model: CustomTypeModelField;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export const getHumanReadableFieldType = (
|
|
8
|
-
config: GetFieldHumanReadableTypeConfig,
|
|
9
|
-
): string => {
|
|
10
|
-
switch (config.model.type) {
|
|
11
|
-
case "StructuredText": {
|
|
12
|
-
const isTitleField =
|
|
13
|
-
config.model.config &&
|
|
14
|
-
"single" in config.model.config &&
|
|
15
|
-
config.model.config.single &&
|
|
16
|
-
config.model.config.single
|
|
17
|
-
.split(",")
|
|
18
|
-
.every((blockType) => /heading/.test(blockType));
|
|
19
|
-
|
|
20
|
-
return isTitleField ? "Title" : "Rich Text";
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
case "IntegrationFields": {
|
|
24
|
-
const catalog = config.model.config?.catalog;
|
|
25
|
-
|
|
26
|
-
return `Integration Fields (Catalog: ${
|
|
27
|
-
catalog ? `\`${catalog}\`` : "*unknown*"
|
|
28
|
-
})`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
case "Link": {
|
|
32
|
-
switch (config.model.config?.select) {
|
|
33
|
-
case "document": {
|
|
34
|
-
return "Content Relationship";
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
case "media": {
|
|
38
|
-
return "Link to Media";
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
default: {
|
|
42
|
-
return "Link";
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
case "Slices": {
|
|
48
|
-
return "Slice Zone";
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
default: {
|
|
52
|
-
return config.model.type;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as tsm from "ts-morph";
|
|
2
|
-
|
|
3
|
-
// import prettier from "prettier";
|
|
4
|
-
import { BLANK_LINE_IDENTIFIER } from "../constants";
|
|
5
|
-
|
|
6
|
-
export const getSourceFileText = (sourceFile: tsm.SourceFile): string => {
|
|
7
|
-
const text = sourceFile
|
|
8
|
-
.print()
|
|
9
|
-
.replace(new RegExp(BLANK_LINE_IDENTIFIER, "g"), "");
|
|
10
|
-
|
|
11
|
-
return text;
|
|
12
|
-
|
|
13
|
-
// return prettier.format(text, { parser: "typescript" });
|
|
14
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Determines if an object contains a given property. It augments the provided
|
|
3
|
-
* object's type to include the property.
|
|
4
|
-
*
|
|
5
|
-
* @remarks
|
|
6
|
-
* This function is only necessary because TypeScript does not narrow a type
|
|
7
|
-
* after using the `in` operator on `object`.
|
|
8
|
-
* @returns `true` if `obj` contains a `prop` property, `false` otherwise.
|
|
9
|
-
*/
|
|
10
|
-
export const hasOwnProperty = <X extends object, Y extends PropertyKey>(
|
|
11
|
-
obj: X,
|
|
12
|
-
prop: Y,
|
|
13
|
-
): obj is X & Record<Y, unknown> => {
|
|
14
|
-
return obj.hasOwnProperty(prop);
|
|
15
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { CustomTypeModelSlice } from "@prismicio/client";
|
|
2
|
-
|
|
3
|
-
import { hasOwnProperty } from "./hasOwnProperty";
|
|
4
|
-
|
|
5
|
-
export const isCustomTypeModelSlice = (
|
|
6
|
-
model: unknown,
|
|
7
|
-
): model is CustomTypeModelSlice => {
|
|
8
|
-
return (
|
|
9
|
-
typeof model === "object" &&
|
|
10
|
-
model !== null &&
|
|
11
|
-
hasOwnProperty(model, "type") &&
|
|
12
|
-
model.type === "Slice"
|
|
13
|
-
);
|
|
14
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { SharedSliceModel } from "@prismicio/client";
|
|
2
|
-
|
|
3
|
-
import { hasOwnProperty } from "./hasOwnProperty";
|
|
4
|
-
|
|
5
|
-
export const isSharedSliceModel = (
|
|
6
|
-
model: unknown,
|
|
7
|
-
): model is SharedSliceModel => {
|
|
8
|
-
return (
|
|
9
|
-
typeof model === "object" &&
|
|
10
|
-
model !== null &&
|
|
11
|
-
hasOwnProperty(model, "type") &&
|
|
12
|
-
model.type === "SharedSlice"
|
|
13
|
-
);
|
|
14
|
-
};
|
package/src/lib/pascalCase.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { CodeBlockWriter } from "ts-morph";
|
|
2
|
-
|
|
3
|
-
type BuildFieldDocsConfig = {
|
|
4
|
-
writer: CodeBlockWriter;
|
|
5
|
-
description?: string;
|
|
6
|
-
fieldType?: string;
|
|
7
|
-
defaultValue?: string | boolean;
|
|
8
|
-
placeholder?: string;
|
|
9
|
-
apiIDPath?: string;
|
|
10
|
-
tabName?: string;
|
|
11
|
-
documentationURL?: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const writeFieldDocsDescription = (
|
|
15
|
-
config: BuildFieldDocsConfig,
|
|
16
|
-
): void => {
|
|
17
|
-
if (config.description) {
|
|
18
|
-
config.writer.writeLine(config.description);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
config.writer.blankLineIfLastNot();
|
|
22
|
-
|
|
23
|
-
if (config.fieldType) {
|
|
24
|
-
config.writer.writeLine(`- **Field Type**: ${config.fieldType}`);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (config.placeholder) {
|
|
28
|
-
config.writer.writeLine(`- **Placeholder**: ${config.placeholder}`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (config.defaultValue !== undefined) {
|
|
32
|
-
const stringifiedDefaultValue =
|
|
33
|
-
typeof config.defaultValue === "boolean"
|
|
34
|
-
? `${config.defaultValue}`
|
|
35
|
-
: config.defaultValue;
|
|
36
|
-
|
|
37
|
-
config.writer.writeLine(`- **Default Value**: ${stringifiedDefaultValue}`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (config.apiIDPath) {
|
|
41
|
-
config.writer.writeLine(`- **API ID Path**: ${config.apiIDPath}`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (config.tabName) {
|
|
45
|
-
config.writer.writeLine(`- **Tab**: ${config.tabName}`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (config.documentationURL) {
|
|
49
|
-
config.writer.writeLine(`- **Documentation**: ${config.documentationURL}`);
|
|
50
|
-
}
|
|
51
|
-
};
|