prismic-ts-codegen 0.1.30 → 0.1.31

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.
Files changed (63) hide show
  1. package/dist/cli/configSchema.d.mts +2 -4
  2. package/dist/cli/configSchema.d.mts.map +1 -1
  3. package/dist/cli/configSchema.mjs +126 -2
  4. package/dist/cli/configSchema.mjs.map +1 -1
  5. package/dist/cli/constants.d.mts +1 -2
  6. package/dist/cli/constants.d.mts.map +1 -1
  7. package/dist/cli/loadConfig.mjs +7 -10
  8. package/dist/cli/loadConfig.mjs.map +1 -1
  9. package/dist/cli/loadLocaleIDs.mjs +0 -1
  10. package/dist/cli/loadLocaleIDs.mjs.map +1 -1
  11. package/dist/cli/loadModels.mjs +11 -10
  12. package/dist/cli/loadModels.mjs.map +1 -1
  13. package/dist/cli.d.mts +1 -1
  14. package/dist/cli.mjs +41 -16
  15. package/dist/cli.mjs.map +1 -1
  16. package/dist/constants.mjs.map +1 -1
  17. package/dist/detectTypesProvider.d.mts +2 -4
  18. package/dist/detectTypesProvider.d.mts.map +1 -1
  19. package/dist/detectTypesProvider.mjs.map +1 -1
  20. package/dist/generateTypes.d.mts +3 -5
  21. package/dist/generateTypes.d.mts.map +1 -1
  22. package/dist/generateTypes.mjs +15 -12
  23. package/dist/generateTypes.mjs.map +1 -1
  24. package/dist/lib/addBlankLine.mjs.map +1 -1
  25. package/dist/lib/addLine.mjs.map +1 -1
  26. package/dist/lib/addSection.mjs.map +1 -1
  27. package/dist/lib/addTrailingNewLine.mjs.map +1 -1
  28. package/dist/lib/buildCustomTypeDataType.mjs +2 -2
  29. package/dist/lib/buildCustomTypeDataType.mjs.map +1 -1
  30. package/dist/lib/buildCustomTypeType.mjs +2 -2
  31. package/dist/lib/buildCustomTypeType.mjs.map +1 -1
  32. package/dist/lib/buildFieldDocs.mjs +9 -4
  33. package/dist/lib/buildFieldDocs.mjs.map +1 -1
  34. package/dist/lib/buildFieldProperties.mjs +18 -14
  35. package/dist/lib/buildFieldProperties.mjs.map +1 -1
  36. package/dist/lib/buildSharedSliceType.mjs +10 -10
  37. package/dist/lib/buildSharedSliceType.mjs.map +1 -1
  38. package/dist/lib/buildTypeName.mjs +2 -2
  39. package/dist/lib/buildTypeName.mjs.map +1 -1
  40. package/dist/lib/buildUnion.mjs.map +1 -1
  41. package/dist/lib/checkHasUIDFIeld.mjs.map +1 -1
  42. package/dist/lib/dedent.mjs +11 -0
  43. package/dist/lib/dedent.mjs.map +1 -0
  44. package/dist/lib/getAPIIDPath.mjs.map +1 -1
  45. package/dist/lib/getCacheKey.mjs.map +1 -1
  46. package/dist/lib/getHumanReadableModelName.mjs.map +1 -1
  47. package/dist/lib/getHumanReadablePath.mjs.map +1 -1
  48. package/dist/package.mjs +7 -0
  49. package/dist/package.mjs.map +1 -0
  50. package/dist/types.d.mts +1 -3
  51. package/dist/types.d.mts.map +1 -1
  52. package/package.json +18 -25
  53. package/src/cli/index.ts +38 -22
  54. package/src/cli/loadConfig.ts +5 -11
  55. package/src/cli/loadLocaleIDs.ts +0 -1
  56. package/src/cli/loadModels.ts +27 -12
  57. package/src/generateTypes.ts +3 -3
  58. package/src/lib/buildCustomTypeDataType.ts +2 -2
  59. package/src/lib/buildCustomTypeType.ts +6 -6
  60. package/src/lib/buildFieldProperties.ts +7 -7
  61. package/src/lib/buildSharedSliceType.ts +22 -33
  62. package/src/lib/buildTypeName.ts +9 -4
  63. package/src/lib/dedent.ts +10 -0
@@ -1,5 +1,4 @@
1
1
  import type { SharedSliceModel } from "@prismicio/client";
2
- import { source, stripIndent } from "common-tags";
3
2
  import type QuickLRU from "quick-lru";
4
3
 
5
4
  import { SHARED_SLICES_DOCUMENTATION_URL } from "../constants";
@@ -8,6 +7,7 @@ import { addSection } from "./addSection";
8
7
  import { buildFieldProperties } from "./buildFieldProperties";
9
8
  import { buildTypeName } from "./buildTypeName";
10
9
  import { buildUnion } from "./buildUnion";
10
+ import { dedent } from "./dedent";
11
11
  import { getCacheKey } from "./getCacheKey";
12
12
  import { getHumanReadableModelName } from "./getHumanReadableModelName";
13
13
  import { getHumanReadablePath } from "./getHumanReadablePath";
@@ -27,7 +27,7 @@ type BuildSharedSliceTypeReturnValue = {
27
27
  };
28
28
 
29
29
  export function buildSharedSliceType(
30
- args: BuildSharedSliceTypeArgs
30
+ args: BuildSharedSliceTypeArgs,
31
31
  ): BuildSharedSliceTypeReturnValue {
32
32
  if (args.cache) {
33
33
  const key = getCacheKey([args.model, args.fieldConfigs]);
@@ -54,10 +54,7 @@ export function buildSharedSliceType(
54
54
  const variationName = buildTypeName(name, variationModel.id);
55
55
 
56
56
  let primaryInterfaceName: string | undefined;
57
- if (
58
- variationModel.primary &&
59
- Object.keys(variationModel.primary).length > 0
60
- ) {
57
+ if (variationModel.primary && Object.keys(variationModel.primary).length > 0) {
61
58
  primaryInterfaceName = buildTypeName(variationName, "Primary");
62
59
 
63
60
  const path: FieldPath = [
@@ -86,7 +83,7 @@ export function buildSharedSliceType(
86
83
 
87
84
  contentTypeNames.push(primaryInterfaceName);
88
85
 
89
- const docs = stripIndent`
86
+ const docs = dedent`
90
87
  /**
91
88
  * Primary content in *${humanReadablePath}*
92
89
  */
@@ -94,17 +91,17 @@ export function buildSharedSliceType(
94
91
 
95
92
  code = addSection(
96
93
  primaryFieldProperties.code
97
- ? source`
94
+ ? dedent`
98
95
  ${docs}
99
96
  export interface ${primaryInterfaceName} {
100
97
  ${primaryFieldProperties.code}
101
98
  }
102
99
  `
103
- : source`
100
+ : dedent`
104
101
  ${docs}
105
102
  export interface ${primaryInterfaceName} {}
106
103
  `,
107
- code
104
+ code,
108
105
  );
109
106
  }
110
107
 
@@ -134,7 +131,7 @@ export function buildSharedSliceType(
134
131
 
135
132
  contentTypeNames.push(itemInterfaceName);
136
133
 
137
- const docs = stripIndent`
134
+ const docs = dedent`
138
135
  /**
139
136
  * Primary content in *${humanReadablePath}*
140
137
  */
@@ -142,22 +139,22 @@ export function buildSharedSliceType(
142
139
 
143
140
  code = addSection(
144
141
  itemFieldProperties.code
145
- ? source`
142
+ ? dedent`
146
143
  ${docs}
147
144
  export interface ${itemInterfaceName} {
148
145
  ${itemFieldProperties.code}
149
146
  }
150
147
  `
151
- : source`
148
+ : dedent`
152
149
  ${docs}
153
150
  export interface ${itemInterfaceName} {}
154
151
  `,
155
- code
152
+ code,
156
153
  );
157
154
  }
158
155
 
159
156
  code = addSection(
160
- source`
157
+ dedent`
161
158
  /**
162
159
  * ${variationModel.name} variation for ${humanReadableName} Slice
163
160
  *
@@ -165,15 +162,11 @@ export function buildSharedSliceType(
165
162
  * - **Description**: ${variationModel.description || "*None*"}
166
163
  * - **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}
167
164
  */
168
- export type ${variationName} = prismic.SharedSliceVariation<"${
169
- variationModel.id
170
- }", ${
171
- primaryInterfaceName
172
- ? `Simplify<${primaryInterfaceName}>`
173
- : `Record<string, never>`
174
- }, ${itemInterfaceName ? `Simplify<${itemInterfaceName}>` : `never`}>;
165
+ export type ${variationName} = prismic.SharedSliceVariation<"${variationModel.id}", ${
166
+ primaryInterfaceName ? `Simplify<${primaryInterfaceName}>` : `Record<string, never>`
167
+ }, ${itemInterfaceName ? `Simplify<${itemInterfaceName}>` : `never`}>;
175
168
  `,
176
- code
169
+ code,
177
170
  );
178
171
 
179
172
  variationNames.push(variationName);
@@ -186,19 +179,17 @@ export function buildSharedSliceType(
186
179
  contentTypeNames.push(...variationNames);
187
180
 
188
181
  code = addSection(
189
- source`
182
+ dedent`
190
183
  /**
191
184
  * Slice variation for *${humanReadableName}*
192
185
  */
193
- type ${variationUnionName} = ${
194
- variationNames.length > 0 ? variationsUnion : "never"
195
- }
186
+ type ${variationUnionName} = ${variationNames.length > 0 ? variationsUnion : "never"}
196
187
  `,
197
- code
188
+ code,
198
189
  );
199
190
 
200
191
  code = addSection(
201
- source`
192
+ dedent`
202
193
  /**
203
194
  * ${humanReadableName} Shared Slice
204
195
  *
@@ -206,11 +197,9 @@ export function buildSharedSliceType(
206
197
  * - **Description**: ${args.model.description || "*None*"}
207
198
  * - **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}
208
199
  */
209
- export type ${name} = prismic.SharedSlice<"${
210
- args.model.id
211
- }", ${variationUnionName}>;
200
+ export type ${name} = prismic.SharedSlice<"${args.model.id}", ${variationUnionName}>;
212
201
  `,
213
- code
202
+ code,
214
203
  );
215
204
 
216
205
  const result = {
@@ -1,9 +1,14 @@
1
- import { pascalCase, pascalCaseTransformMerge } from "pascal-case";
1
+ import { pascalCase } from "change-case";
2
2
 
3
3
  export const buildTypeName = (...parts: string[]): string => {
4
- let name = pascalCase(parts.filter(Boolean).join(" "), {
5
- transform: pascalCaseTransformMerge,
6
- });
4
+ // Non-ASCII characters are separators, as they were with the previous `pascal-case` package.
5
+ let name = pascalCase(
6
+ parts
7
+ .filter(Boolean)
8
+ .join(" ")
9
+ .replace(/[^A-Z0-9]+/gi, " "),
10
+ { mergeAmbiguousCharacters: true },
11
+ );
7
12
 
8
13
  if (/^[0-9]/.test(name) ? "_" : "") {
9
14
  name = `_${name}`;
@@ -0,0 +1,10 @@
1
+ import baseDedent from "dedent";
2
+
3
+ const baseDedentWithOptions = baseDedent.withOptions({ alignValues: true });
4
+
5
+ export const dedent = (strings: TemplateStringsArray, ...values: unknown[]): string => {
6
+ // dedent reads `strings.raw` by default, which keeps escapes in string literals. Point `raw` at
7
+ // the regular string segments instead, where escapes are already resolved.
8
+ const resolved = Array.from(strings);
9
+ return baseDedentWithOptions(Object.assign(resolved, { raw: resolved }), ...values);
10
+ };