prismic-ts-codegen 0.1.30-pr.82.96148f3 → 0.1.30

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 +4 -2
  2. package/dist/cli/configSchema.d.mts.map +1 -1
  3. package/dist/cli/configSchema.mjs +2 -126
  4. package/dist/cli/configSchema.mjs.map +1 -1
  5. package/dist/cli/constants.d.mts +2 -1
  6. package/dist/cli/constants.d.mts.map +1 -1
  7. package/dist/cli/loadConfig.mjs +9 -9
  8. package/dist/cli/loadConfig.mjs.map +1 -1
  9. package/dist/cli/loadLocaleIDs.mjs +1 -0
  10. package/dist/cli/loadLocaleIDs.mjs.map +1 -1
  11. package/dist/cli/loadModels.mjs +10 -13
  12. package/dist/cli/loadModels.mjs.map +1 -1
  13. package/dist/cli.d.mts +1 -1
  14. package/dist/cli.mjs +16 -41
  15. package/dist/cli.mjs.map +1 -1
  16. package/dist/constants.mjs.map +1 -1
  17. package/dist/detectTypesProvider.d.mts +4 -2
  18. package/dist/detectTypesProvider.d.mts.map +1 -1
  19. package/dist/detectTypesProvider.mjs.map +1 -1
  20. package/dist/generateTypes.d.mts +5 -3
  21. package/dist/generateTypes.d.mts.map +1 -1
  22. package/dist/generateTypes.mjs +12 -15
  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 +4 -9
  33. package/dist/lib/buildFieldDocs.mjs.map +1 -1
  34. package/dist/lib/buildFieldProperties.mjs +14 -18
  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/getAPIIDPath.mjs.map +1 -1
  43. package/dist/lib/getCacheKey.mjs.map +1 -1
  44. package/dist/lib/getHumanReadableModelName.mjs.map +1 -1
  45. package/dist/lib/getHumanReadablePath.mjs.map +1 -1
  46. package/dist/types.d.mts +3 -1
  47. package/dist/types.d.mts.map +1 -1
  48. package/package.json +22 -18
  49. package/src/cli/index.ts +22 -38
  50. package/src/cli/loadConfig.ts +9 -7
  51. package/src/cli/loadLocaleIDs.ts +1 -0
  52. package/src/cli/loadModels.ts +12 -30
  53. package/src/generateTypes.ts +3 -3
  54. package/src/lib/buildCustomTypeDataType.ts +2 -2
  55. package/src/lib/buildCustomTypeType.ts +6 -6
  56. package/src/lib/buildFieldProperties.ts +7 -7
  57. package/src/lib/buildSharedSliceType.ts +33 -22
  58. package/src/lib/buildTypeName.ts +4 -9
  59. package/dist/lib/dedent.mjs +0 -12
  60. package/dist/lib/dedent.mjs.map +0 -1
  61. package/dist/package.mjs +0 -7
  62. package/dist/package.mjs.map +0 -1
  63. package/src/lib/dedent.ts +0 -14
@@ -1,4 +1,5 @@
1
1
  import type { SharedSliceModel } from "@prismicio/client";
2
+ import { source, stripIndent } from "common-tags";
2
3
  import type QuickLRU from "quick-lru";
3
4
 
4
5
  import { SHARED_SLICES_DOCUMENTATION_URL } from "../constants";
@@ -7,7 +8,6 @@ import { addSection } from "./addSection";
7
8
  import { buildFieldProperties } from "./buildFieldProperties";
8
9
  import { buildTypeName } from "./buildTypeName";
9
10
  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,7 +54,10 @@ export function buildSharedSliceType(
54
54
  const variationName = buildTypeName(name, variationModel.id);
55
55
 
56
56
  let primaryInterfaceName: string | undefined;
57
- if (variationModel.primary && Object.keys(variationModel.primary).length > 0) {
57
+ if (
58
+ variationModel.primary &&
59
+ Object.keys(variationModel.primary).length > 0
60
+ ) {
58
61
  primaryInterfaceName = buildTypeName(variationName, "Primary");
59
62
 
60
63
  const path: FieldPath = [
@@ -83,7 +86,7 @@ export function buildSharedSliceType(
83
86
 
84
87
  contentTypeNames.push(primaryInterfaceName);
85
88
 
86
- const docs = dedent`
89
+ const docs = stripIndent`
87
90
  /**
88
91
  * Primary content in *${humanReadablePath}*
89
92
  */
@@ -91,17 +94,17 @@ export function buildSharedSliceType(
91
94
 
92
95
  code = addSection(
93
96
  primaryFieldProperties.code
94
- ? dedent`
97
+ ? source`
95
98
  ${docs}
96
99
  export interface ${primaryInterfaceName} {
97
100
  ${primaryFieldProperties.code}
98
101
  }
99
102
  `
100
- : dedent`
103
+ : source`
101
104
  ${docs}
102
105
  export interface ${primaryInterfaceName} {}
103
106
  `,
104
- code,
107
+ code
105
108
  );
106
109
  }
107
110
 
@@ -131,7 +134,7 @@ export function buildSharedSliceType(
131
134
 
132
135
  contentTypeNames.push(itemInterfaceName);
133
136
 
134
- const docs = dedent`
137
+ const docs = stripIndent`
135
138
  /**
136
139
  * Primary content in *${humanReadablePath}*
137
140
  */
@@ -139,22 +142,22 @@ export function buildSharedSliceType(
139
142
 
140
143
  code = addSection(
141
144
  itemFieldProperties.code
142
- ? dedent`
145
+ ? source`
143
146
  ${docs}
144
147
  export interface ${itemInterfaceName} {
145
148
  ${itemFieldProperties.code}
146
149
  }
147
150
  `
148
- : dedent`
151
+ : source`
149
152
  ${docs}
150
153
  export interface ${itemInterfaceName} {}
151
154
  `,
152
- code,
155
+ code
153
156
  );
154
157
  }
155
158
 
156
159
  code = addSection(
157
- dedent`
160
+ source`
158
161
  /**
159
162
  * ${variationModel.name} variation for ${humanReadableName} Slice
160
163
  *
@@ -162,11 +165,15 @@ export function buildSharedSliceType(
162
165
  * - **Description**: ${variationModel.description || "*None*"}
163
166
  * - **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}
164
167
  */
165
- export type ${variationName} = prismic.SharedSliceVariation<"${variationModel.id}", ${
166
- primaryInterfaceName ? `Simplify<${primaryInterfaceName}>` : `Record<string, never>`
167
- }, ${itemInterfaceName ? `Simplify<${itemInterfaceName}>` : `never`}>;
168
+ export type ${variationName} = prismic.SharedSliceVariation<"${
169
+ variationModel.id
170
+ }", ${
171
+ primaryInterfaceName
172
+ ? `Simplify<${primaryInterfaceName}>`
173
+ : `Record<string, never>`
174
+ }, ${itemInterfaceName ? `Simplify<${itemInterfaceName}>` : `never`}>;
168
175
  `,
169
- code,
176
+ code
170
177
  );
171
178
 
172
179
  variationNames.push(variationName);
@@ -179,17 +186,19 @@ export function buildSharedSliceType(
179
186
  contentTypeNames.push(...variationNames);
180
187
 
181
188
  code = addSection(
182
- dedent`
189
+ source`
183
190
  /**
184
191
  * Slice variation for *${humanReadableName}*
185
192
  */
186
- type ${variationUnionName} = ${variationNames.length > 0 ? variationsUnion : "never"}
193
+ type ${variationUnionName} = ${
194
+ variationNames.length > 0 ? variationsUnion : "never"
195
+ }
187
196
  `,
188
- code,
197
+ code
189
198
  );
190
199
 
191
200
  code = addSection(
192
- dedent`
201
+ source`
193
202
  /**
194
203
  * ${humanReadableName} Shared Slice
195
204
  *
@@ -197,9 +206,11 @@ export function buildSharedSliceType(
197
206
  * - **Description**: ${args.model.description || "*None*"}
198
207
  * - **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}
199
208
  */
200
- export type ${name} = prismic.SharedSlice<"${args.model.id}", ${variationUnionName}>;
209
+ export type ${name} = prismic.SharedSlice<"${
210
+ args.model.id
211
+ }", ${variationUnionName}>;
201
212
  `,
202
- code,
213
+ code
203
214
  );
204
215
 
205
216
  const result = {
@@ -1,14 +1,9 @@
1
- import { pascalCase } from "change-case";
1
+ import { pascalCase, pascalCaseTransformMerge } from "pascal-case";
2
2
 
3
3
  export const buildTypeName = (...parts: string[]): string => {
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
- );
4
+ let name = pascalCase(parts.filter(Boolean).join(" "), {
5
+ transform: pascalCaseTransformMerge,
6
+ });
12
7
 
13
8
  if (/^[0-9]/.test(name) ? "_" : "") {
14
9
  name = `_${name}`;
@@ -1,12 +0,0 @@
1
- import baseDedent from "dedent";
2
- //#region src/lib/dedent.ts
3
- const baseDedentWithOptions = baseDedent.withOptions({ alignValues: true });
4
- function dedent(strings, ...values) {
5
- if (typeof strings === "string") return baseDedentWithOptions(strings);
6
- const resolved = Array.from(strings);
7
- return baseDedentWithOptions(Object.assign(resolved, { raw: resolved }), ...values);
8
- }
9
- //#endregion
10
- export { dedent };
11
-
12
- //# sourceMappingURL=dedent.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dedent.mjs","names":[],"sources":["../../src/lib/dedent.ts"],"sourcesContent":["import baseDedent from \"dedent\";\n\nconst baseDedentWithOptions = baseDedent.withOptions({ alignValues: true });\n\nexport function dedent(strings: TemplateStringsArray | string, ...values: unknown[]): string {\n\tif (typeof strings === \"string\") {\n\t\treturn baseDedentWithOptions(strings);\n\t}\n\n\t// dedent reads `strings.raw` by default, which keeps escapes in string literals. Point `raw` at\n\t// the regular string segments instead, where escapes are already resolved.\n\tconst resolved = Array.from(strings);\n\treturn baseDedentWithOptions(Object.assign(resolved, { raw: resolved }), ...values);\n}\n"],"mappings":";;AAEA,MAAM,wBAAwB,WAAW,YAAY,EAAE,aAAa,KAAK,CAAC;AAE1E,SAAgB,OAAO,SAAwC,GAAG,QAA2B;CAC5F,IAAI,OAAO,YAAY,UACtB,OAAO,sBAAsB,OAAO;CAKrC,MAAM,WAAW,MAAM,KAAK,OAAO;CACnC,OAAO,sBAAsB,OAAO,OAAO,UAAU,EAAE,KAAK,SAAS,CAAC,GAAG,GAAG,MAAM;AACnF"}
package/dist/package.mjs DELETED
@@ -1,7 +0,0 @@
1
- //#region package.json
2
- var version = "0.1.30-pr.82.96148f3";
3
- var description = "An experimental Prismic model-to-TypeScript-type generator";
4
- //#endregion
5
- export { description, version };
6
-
7
- //# sourceMappingURL=package.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"package.mjs","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
package/src/lib/dedent.ts DELETED
@@ -1,14 +0,0 @@
1
- import baseDedent from "dedent";
2
-
3
- const baseDedentWithOptions = baseDedent.withOptions({ alignValues: true });
4
-
5
- export function dedent(strings: TemplateStringsArray | string, ...values: unknown[]): string {
6
- if (typeof strings === "string") {
7
- return baseDedentWithOptions(strings);
8
- }
9
-
10
- // dedent reads `strings.raw` by default, which keeps escapes in string literals. Point `raw` at
11
- // the regular string segments instead, where escapes are already resolved.
12
- const resolved = Array.from(strings);
13
- return baseDedentWithOptions(Object.assign(resolved, { raw: resolved }), ...values);
14
- }