prismic-ts-codegen 0.1.2 → 0.1.4
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 +139 -50
- package/dist/index.cjs +100 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +100 -28
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
- package/src/cli/loadConfig.ts +8 -6
- package/src/cli/types.ts +4 -2
- package/src/generateTypes.ts +2 -2
- package/src/lib/addInterfacePropertiesForFields.ts +39 -13
- 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
|
@@ -8,7 +8,7 @@ import { CUSTOM_TYPES_DOCUMENTATION_URL } from "../constants";
|
|
|
8
8
|
import { FieldConfigs } from "../types";
|
|
9
9
|
|
|
10
10
|
import { addInterfacePropertiesForFields } from "./addInterfacePropertiesForFields";
|
|
11
|
-
import {
|
|
11
|
+
import { buildTypeName } from "./buildTypeName";
|
|
12
12
|
|
|
13
13
|
const collectCustomTypeFields = (
|
|
14
14
|
model: CustomTypeModel,
|
|
@@ -36,7 +36,7 @@ export const addTypeAliasForCustomType = ({
|
|
|
36
36
|
let dataInterface: InterfaceDeclaration | TypeAliasDeclaration;
|
|
37
37
|
if (hasDataFields) {
|
|
38
38
|
dataInterface = sourceFile.addInterface({
|
|
39
|
-
name:
|
|
39
|
+
name: buildTypeName(model.id, "Document", "Data"),
|
|
40
40
|
docs: [
|
|
41
41
|
{
|
|
42
42
|
description: `Content for ${model.label} documents`,
|
|
@@ -65,7 +65,7 @@ export const addTypeAliasForCustomType = ({
|
|
|
65
65
|
}
|
|
66
66
|
} else {
|
|
67
67
|
dataInterface = sourceFile.addTypeAlias({
|
|
68
|
-
name:
|
|
68
|
+
name: buildTypeName(model.id, "Document", "Data"),
|
|
69
69
|
type: `Record<string, never>`,
|
|
70
70
|
docs: [
|
|
71
71
|
{
|
|
@@ -76,7 +76,7 @@ export const addTypeAliasForCustomType = ({
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
return sourceFile.addTypeAlias({
|
|
79
|
-
name:
|
|
79
|
+
name: buildTypeName(model.id, "Document"),
|
|
80
80
|
typeParameters: [
|
|
81
81
|
{
|
|
82
82
|
name: "Lang",
|
|
@@ -5,13 +5,14 @@ import type {
|
|
|
5
5
|
TypeAliasDeclaration,
|
|
6
6
|
} from "ts-morph";
|
|
7
7
|
|
|
8
|
-
import { addInterfacePropertiesForFields } from "./addInterfacePropertiesForFields";
|
|
9
|
-
import { buildSharedSliceInterfaceName } from "./buildSharedSliceInterfaceName";
|
|
10
|
-
import { pascalCase } from "./pascalCase";
|
|
11
|
-
import { getHumanReadableFieldPath } from "./getHumanReadableFieldPath";
|
|
12
8
|
import { SHARED_SLICES_DOCUMENTATION_URL } from "../constants";
|
|
13
9
|
import { FieldConfigs } from "../types";
|
|
14
10
|
|
|
11
|
+
import { addInterfacePropertiesForFields } from "./addInterfacePropertiesForFields";
|
|
12
|
+
import { buildSharedSliceInterfaceNamePart } from "./buildSharedSliceInterfaceNamePart";
|
|
13
|
+
import { buildTypeName } from "./buildTypeName";
|
|
14
|
+
import { getHumanReadableFieldPath } from "./getHumanReadableFieldPath";
|
|
15
|
+
|
|
15
16
|
type AddTypeAliasForSharedSliceConfig = {
|
|
16
17
|
model: SharedSliceModel;
|
|
17
18
|
sourceFile: SourceFile;
|
|
@@ -27,10 +28,10 @@ export const addTypeAliasForSharedSlice = (
|
|
|
27
28
|
let primaryInterface: InterfaceDeclaration | undefined;
|
|
28
29
|
if (variation.primary && Object.keys(variation.primary).length > 0) {
|
|
29
30
|
primaryInterface = config.sourceFile.addInterface({
|
|
30
|
-
name:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
name: buildTypeName(
|
|
32
|
+
buildSharedSliceInterfaceNamePart({ id: config.model.id }),
|
|
33
|
+
variation.id,
|
|
34
|
+
"Primary",
|
|
34
35
|
),
|
|
35
36
|
docs: [
|
|
36
37
|
{
|
|
@@ -74,10 +75,10 @@ export const addTypeAliasForSharedSlice = (
|
|
|
74
75
|
let itemInterface: InterfaceDeclaration | undefined;
|
|
75
76
|
if (variation.items && Object.keys(variation.items).length > 0) {
|
|
76
77
|
itemInterface = config.sourceFile.addInterface({
|
|
77
|
-
name:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
name: buildTypeName(
|
|
79
|
+
buildSharedSliceInterfaceNamePart({ id: config.model.id }),
|
|
80
|
+
variation.id,
|
|
81
|
+
"Item",
|
|
81
82
|
),
|
|
82
83
|
docs: [
|
|
83
84
|
{
|
|
@@ -120,10 +121,9 @@ export const addTypeAliasForSharedSlice = (
|
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
const variationType = config.sourceFile.addTypeAlias({
|
|
123
|
-
name:
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
})} ${variation.id}`,
|
|
124
|
+
name: buildTypeName(
|
|
125
|
+
buildSharedSliceInterfaceNamePart({ id: config.model.id }),
|
|
126
|
+
variation.id,
|
|
127
127
|
),
|
|
128
128
|
type: `prismicT.SharedSliceVariation<"${variation.id}", ${
|
|
129
129
|
primaryInterface
|
|
@@ -152,7 +152,7 @@ export const addTypeAliasForSharedSlice = (
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
const variationsType = config.sourceFile.addTypeAlias({
|
|
155
|
-
name:
|
|
155
|
+
name: buildTypeName(config.model.id, "Slice", "Variation"),
|
|
156
156
|
type:
|
|
157
157
|
variationTypeNames.length > 0 ? variationTypeNames.join(" | ") : "never",
|
|
158
158
|
docs: [
|
|
@@ -174,10 +174,8 @@ export const addTypeAliasForSharedSlice = (
|
|
|
174
174
|
});
|
|
175
175
|
|
|
176
176
|
return config.sourceFile.addTypeAlias({
|
|
177
|
-
name:
|
|
178
|
-
|
|
179
|
-
id: config.model.id,
|
|
180
|
-
}),
|
|
177
|
+
name: buildTypeName(
|
|
178
|
+
buildSharedSliceInterfaceNamePart({ id: config.model.id }),
|
|
181
179
|
),
|
|
182
180
|
type: `prismicT.SharedSlice<"${
|
|
183
181
|
config.model.id
|
|
@@ -0,0 +1,11 @@
|
|
|
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,11 +0,0 @@
|
|
|
1
|
-
import { pascalCase } from "./pascalCase";
|
|
2
|
-
|
|
3
|
-
type BuildSharedSliceInterfaceNameConfig = {
|
|
4
|
-
id: string;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export const buildSharedSliceInterfaceName = (
|
|
8
|
-
config: BuildSharedSliceInterfaceNameConfig,
|
|
9
|
-
): string => {
|
|
10
|
-
return pascalCase(`${config.id} Slice`);
|
|
11
|
-
};
|