prismic-ts-codegen 0.1.29 → 0.1.30-pr.82.80084b2

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 (173) hide show
  1. package/bin/prismic-ts-codegen.js +1 -1
  2. package/dist/cli/{configSchema.d.ts → configSchema.d.mts} +3 -5
  3. package/dist/cli/configSchema.d.mts.map +1 -0
  4. package/dist/cli/configSchema.mjs +154 -0
  5. package/dist/cli/configSchema.mjs.map +1 -0
  6. package/dist/cli/constants.d.mts +4 -0
  7. package/dist/cli/constants.d.mts.map +1 -0
  8. package/dist/cli/{constants.js → constants.mjs} +1 -1
  9. package/dist/cli/{constants.cjs.map → constants.mjs.map} +1 -1
  10. package/dist/cli/loadConfig.mjs +17 -0
  11. package/dist/cli/loadConfig.mjs.map +1 -0
  12. package/dist/cli/{loadLocaleIDs.js → loadLocaleIDs.mjs} +1 -2
  13. package/dist/cli/loadLocaleIDs.mjs.map +1 -0
  14. package/dist/cli/{loadModels.js → loadModels.mjs} +12 -11
  15. package/dist/cli/loadModels.mjs.map +1 -0
  16. package/dist/cli.d.mts +1 -0
  17. package/dist/{cli.js → cli.mjs} +51 -25
  18. package/dist/cli.mjs.map +1 -0
  19. package/dist/{constants.js → constants.mjs} +1 -1
  20. package/dist/{constants.cjs.map → constants.mjs.map} +1 -1
  21. package/dist/detectTypesProvider.d.mts +15 -0
  22. package/dist/detectTypesProvider.d.mts.map +1 -0
  23. package/dist/{detectTypesProvider.js → detectTypesProvider.mjs} +1 -1
  24. package/dist/{detectTypesProvider.cjs.map → detectTypesProvider.mjs.map} +1 -1
  25. package/dist/{generateTypes.d.ts → generateTypes.d.mts} +5 -7
  26. package/dist/generateTypes.d.mts.map +1 -0
  27. package/dist/{generateTypes.js → generateTypes.mjs} +21 -18
  28. package/dist/generateTypes.mjs.map +1 -0
  29. package/dist/{index.d.cts → index.d.mts} +4 -4
  30. package/dist/index.mjs +4 -0
  31. package/dist/lib/{addBlankLine.js → addBlankLine.mjs} +2 -2
  32. package/dist/lib/addBlankLine.mjs.map +1 -0
  33. package/dist/lib/{addLine.js → addLine.mjs} +2 -2
  34. package/dist/lib/addLine.mjs.map +1 -0
  35. package/dist/lib/{addSection.js → addSection.mjs} +2 -2
  36. package/dist/lib/addSection.mjs.map +1 -0
  37. package/dist/lib/{addTrailingNewLine.js → addTrailingNewLine.mjs} +1 -1
  38. package/dist/lib/{addTrailingNewLine.cjs.map → addTrailingNewLine.mjs.map} +1 -1
  39. package/dist/lib/{buildCustomTypeDataType.js → buildCustomTypeDataType.mjs} +6 -6
  40. package/dist/lib/buildCustomTypeDataType.mjs.map +1 -0
  41. package/dist/lib/{buildCustomTypeType.js → buildCustomTypeType.mjs} +11 -11
  42. package/dist/lib/buildCustomTypeType.mjs.map +1 -0
  43. package/dist/lib/{buildFieldDocs.js → buildFieldDocs.mjs} +15 -10
  44. package/dist/lib/buildFieldDocs.mjs.map +1 -0
  45. package/dist/lib/{buildFieldProperties.js → buildFieldProperties.mjs} +25 -21
  46. package/dist/lib/buildFieldProperties.mjs.map +1 -0
  47. package/dist/lib/{buildSharedSliceType.js → buildSharedSliceType.mjs} +19 -19
  48. package/dist/lib/buildSharedSliceType.mjs.map +1 -0
  49. package/dist/lib/buildTypeName.mjs +11 -0
  50. package/dist/lib/buildTypeName.mjs.map +1 -0
  51. package/dist/lib/{buildUnion.js → buildUnion.mjs} +1 -1
  52. package/dist/lib/{buildUnion.cjs.map → buildUnion.mjs.map} +1 -1
  53. package/dist/lib/{checkHasUIDFIeld.js → checkHasUIDFIeld.mjs} +1 -1
  54. package/dist/lib/{checkHasUIDFIeld.cjs.map → checkHasUIDFIeld.mjs.map} +1 -1
  55. package/dist/lib/dedent.mjs +11 -0
  56. package/dist/lib/dedent.mjs.map +1 -0
  57. package/dist/lib/{getAPIIDPath.js → getAPIIDPath.mjs} +1 -1
  58. package/dist/lib/{getAPIIDPath.cjs.map → getAPIIDPath.mjs.map} +1 -1
  59. package/dist/lib/{getCacheKey.js → getCacheKey.mjs} +1 -1
  60. package/dist/lib/getCacheKey.mjs.map +1 -0
  61. package/dist/lib/{getHumanReadableModelName.js → getHumanReadableModelName.mjs} +1 -1
  62. package/dist/lib/{getHumanReadableModelName.cjs.map → getHumanReadableModelName.mjs.map} +1 -1
  63. package/dist/lib/{getHumanReadablePath.js → getHumanReadablePath.mjs} +2 -2
  64. package/dist/lib/getHumanReadablePath.mjs.map +1 -0
  65. package/dist/package.mjs +7 -0
  66. package/dist/package.mjs.map +1 -0
  67. package/dist/{types.d.ts → types.d.mts} +2 -4
  68. package/dist/types.d.mts.map +1 -0
  69. package/package.json +19 -29
  70. package/src/cli/index.ts +38 -22
  71. package/src/cli/loadConfig.ts +5 -11
  72. package/src/cli/loadLocaleIDs.ts +0 -1
  73. package/src/cli/loadModels.ts +27 -12
  74. package/src/generateTypes.ts +3 -3
  75. package/src/lib/buildCustomTypeDataType.ts +2 -2
  76. package/src/lib/buildCustomTypeType.ts +6 -6
  77. package/src/lib/buildFieldProperties.ts +7 -7
  78. package/src/lib/buildSharedSliceType.ts +22 -33
  79. package/src/lib/buildTypeName.ts +9 -4
  80. package/src/lib/dedent.ts +10 -0
  81. package/dist/_virtual/_rolldown/runtime.cjs +0 -23
  82. package/dist/cli/configSchema.cjs +0 -31
  83. package/dist/cli/configSchema.cjs.map +0 -1
  84. package/dist/cli/configSchema.d.cts +0 -39
  85. package/dist/cli/configSchema.d.cts.map +0 -1
  86. package/dist/cli/configSchema.d.ts.map +0 -1
  87. package/dist/cli/configSchema.js +0 -30
  88. package/dist/cli/configSchema.js.map +0 -1
  89. package/dist/cli/constants.cjs +0 -6
  90. package/dist/cli/constants.d.cts +0 -5
  91. package/dist/cli/constants.d.cts.map +0 -1
  92. package/dist/cli/constants.d.ts +0 -5
  93. package/dist/cli/constants.d.ts.map +0 -1
  94. package/dist/cli/constants.js.map +0 -1
  95. package/dist/cli/loadConfig.cjs +0 -22
  96. package/dist/cli/loadConfig.cjs.map +0 -1
  97. package/dist/cli/loadConfig.js +0 -20
  98. package/dist/cli/loadConfig.js.map +0 -1
  99. package/dist/cli/loadLocaleIDs.cjs +0 -21
  100. package/dist/cli/loadLocaleIDs.cjs.map +0 -1
  101. package/dist/cli/loadLocaleIDs.js.map +0 -1
  102. package/dist/cli/loadModels.cjs +0 -54
  103. package/dist/cli/loadModels.cjs.map +0 -1
  104. package/dist/cli/loadModels.js.map +0 -1
  105. package/dist/cli.cjs +0 -110
  106. package/dist/cli.cjs.map +0 -1
  107. package/dist/cli.d.cts +0 -1
  108. package/dist/cli.d.ts +0 -1
  109. package/dist/cli.js.map +0 -1
  110. package/dist/constants.cjs +0 -33
  111. package/dist/constants.js.map +0 -1
  112. package/dist/detectTypesProvider.cjs +0 -25
  113. package/dist/detectTypesProvider.d.cts +0 -17
  114. package/dist/detectTypesProvider.d.cts.map +0 -1
  115. package/dist/detectTypesProvider.d.ts +0 -17
  116. package/dist/detectTypesProvider.d.ts.map +0 -1
  117. package/dist/detectTypesProvider.js.map +0 -1
  118. package/dist/generateTypes.cjs +0 -144
  119. package/dist/generateTypes.cjs.map +0 -1
  120. package/dist/generateTypes.d.cts +0 -21
  121. package/dist/generateTypes.d.cts.map +0 -1
  122. package/dist/generateTypes.d.ts.map +0 -1
  123. package/dist/generateTypes.js.map +0 -1
  124. package/dist/index.cjs +0 -7
  125. package/dist/index.d.ts +0 -5
  126. package/dist/index.js +0 -4
  127. package/dist/lib/addBlankLine.cjs +0 -10
  128. package/dist/lib/addBlankLine.cjs.map +0 -1
  129. package/dist/lib/addBlankLine.js.map +0 -1
  130. package/dist/lib/addLine.cjs +0 -9
  131. package/dist/lib/addLine.cjs.map +0 -1
  132. package/dist/lib/addLine.js.map +0 -1
  133. package/dist/lib/addSection.cjs +0 -9
  134. package/dist/lib/addSection.cjs.map +0 -1
  135. package/dist/lib/addSection.js.map +0 -1
  136. package/dist/lib/addTrailingNewLine.cjs +0 -9
  137. package/dist/lib/addTrailingNewLine.js.map +0 -1
  138. package/dist/lib/buildCustomTypeDataType.cjs +0 -51
  139. package/dist/lib/buildCustomTypeDataType.cjs.map +0 -1
  140. package/dist/lib/buildCustomTypeDataType.js.map +0 -1
  141. package/dist/lib/buildCustomTypeType.cjs +0 -63
  142. package/dist/lib/buildCustomTypeType.cjs.map +0 -1
  143. package/dist/lib/buildCustomTypeType.js.map +0 -1
  144. package/dist/lib/buildFieldDocs.cjs +0 -66
  145. package/dist/lib/buildFieldDocs.cjs.map +0 -1
  146. package/dist/lib/buildFieldDocs.js.map +0 -1
  147. package/dist/lib/buildFieldProperties.cjs +0 -285
  148. package/dist/lib/buildFieldProperties.cjs.map +0 -1
  149. package/dist/lib/buildFieldProperties.js.map +0 -1
  150. package/dist/lib/buildSharedSliceType.cjs +0 -152
  151. package/dist/lib/buildSharedSliceType.cjs.map +0 -1
  152. package/dist/lib/buildSharedSliceType.js.map +0 -1
  153. package/dist/lib/buildTypeName.cjs +0 -12
  154. package/dist/lib/buildTypeName.cjs.map +0 -1
  155. package/dist/lib/buildTypeName.js +0 -11
  156. package/dist/lib/buildTypeName.js.map +0 -1
  157. package/dist/lib/buildUnion.cjs +0 -8
  158. package/dist/lib/buildUnion.js.map +0 -1
  159. package/dist/lib/checkHasUIDFIeld.cjs +0 -8
  160. package/dist/lib/checkHasUIDFIeld.js.map +0 -1
  161. package/dist/lib/getAPIIDPath.cjs +0 -24
  162. package/dist/lib/getAPIIDPath.js.map +0 -1
  163. package/dist/lib/getCacheKey.cjs +0 -17
  164. package/dist/lib/getCacheKey.cjs.map +0 -1
  165. package/dist/lib/getCacheKey.js.map +0 -1
  166. package/dist/lib/getHumanReadableModelName.cjs +0 -15
  167. package/dist/lib/getHumanReadableModelName.js.map +0 -1
  168. package/dist/lib/getHumanReadablePath.cjs +0 -16
  169. package/dist/lib/getHumanReadablePath.cjs.map +0 -1
  170. package/dist/lib/getHumanReadablePath.js.map +0 -1
  171. package/dist/types.d.cts +0 -14
  172. package/dist/types.d.cts.map +0 -1
  173. package/dist/types.d.ts.map +0 -1
@@ -12,4 +12,4 @@ const getCacheKey = (input) => {
12
12
  //#endregion
13
13
  export { getCacheKey };
14
14
 
15
- //# sourceMappingURL=getCacheKey.js.map
15
+ //# sourceMappingURL=getCacheKey.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCacheKey.mjs","names":[],"sources":["../../src/lib/getCacheKey.ts"],"sourcesContent":["import * as crypto from \"node:crypto\";\n\n/**\n * Returns a key based on the provided input that can be used as a cache identifier.\n *\n * @param input - The value used to create a key.\n * @returns The cache key.\n */\nexport const getCacheKey = (input: unknown): string => {\n\treturn crypto.createHash(\"sha1\").update(JSON.stringify(input)).digest(\"hex\");\n};\n"],"mappings":";;;;;;;;AAQA,MAAa,eAAe,UAA2B;CACtD,OAAO,OAAO,WAAW,MAAM,CAAC,CAAC,OAAO,KAAK,UAAU,KAAK,CAAC,CAAC,CAAC,OAAO,KAAK;AAC5E"}
@@ -12,4 +12,4 @@ const getHumanReadableModelName = (args) => {
12
12
  //#endregion
13
13
  export { getHumanReadableModelName };
14
14
 
15
- //# sourceMappingURL=getHumanReadableModelName.js.map
15
+ //# sourceMappingURL=getHumanReadableModelName.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getHumanReadableModelName.cjs","names":[],"sources":["../../src/lib/getHumanReadableModelName.ts"],"sourcesContent":["import type {\n\tCustomTypeModel,\n\tCustomTypeModelField,\n\tCustomTypeModelSlice,\n\tSharedSliceModel,\n} from \"@prismicio/client\";\n\ntype GetModelHumanNameArgs = {\n\tname: string;\n\tmodel: CustomTypeModel | SharedSliceModel | CustomTypeModelField | CustomTypeModelSlice;\n};\n\nexport const getHumanReadableModelName = (args: GetModelHumanNameArgs): string => {\n\tif (\"json\" in args.model) {\n\t\t// Custom type model\n\n\t\treturn args.model.label || args.model.id;\n\t} else if (\"type\" in args.model && args.model.type === \"SharedSlice\") {\n\t\t// Shared Slice model\n\n\t\treturn args.model.name;\n\t} else if (\"type\" in args.model && args.model.type === \"Slice\") {\n\t\t// Legacy Slice model\n\n\t\treturn args.model.fieldset || args.name;\n\t} else if (\"type\" in args.model) {\n\t\t// Field model\n\n\t\tif (args.model.config && \"label\" in args.model.config) {\n\t\t\t// Non-Slice Zone fields\n\t\t\treturn args.model.config.label || args.name;\n\t\t} else if (args.model.config && \"fieldset\" in args.model) {\n\t\t\t// Slice Zone\n\t\t\treturn args.model.fieldset || args.name;\n\t\t}\n\t}\n\n\treturn `\\`${args.name}\\``;\n};\n"],"mappings":";AAYA,MAAa,6BAA6B,SAAwC;AACjF,KAAI,UAAU,KAAK,MAGlB,QAAO,KAAK,MAAM,SAAS,KAAK,MAAM;UAC5B,UAAU,KAAK,SAAS,KAAK,MAAM,SAAS,cAGtD,QAAO,KAAK,MAAM;UACR,UAAU,KAAK,SAAS,KAAK,MAAM,SAAS,QAGtD,QAAO,KAAK,MAAM,YAAY,KAAK;UACzB,UAAU,KAAK;MAGrB,KAAK,MAAM,UAAU,WAAW,KAAK,MAAM,OAE9C,QAAO,KAAK,MAAM,OAAO,SAAS,KAAK;WAC7B,KAAK,MAAM,UAAU,cAAc,KAAK,MAElD,QAAO,KAAK,MAAM,YAAY,KAAK;;AAIrC,QAAO,KAAK,KAAK,KAAK"}
1
+ {"version":3,"file":"getHumanReadableModelName.mjs","names":[],"sources":["../../src/lib/getHumanReadableModelName.ts"],"sourcesContent":["import type {\n\tCustomTypeModel,\n\tCustomTypeModelField,\n\tCustomTypeModelSlice,\n\tSharedSliceModel,\n} from \"@prismicio/client\";\n\ntype GetModelHumanNameArgs = {\n\tname: string;\n\tmodel: CustomTypeModel | SharedSliceModel | CustomTypeModelField | CustomTypeModelSlice;\n};\n\nexport const getHumanReadableModelName = (args: GetModelHumanNameArgs): string => {\n\tif (\"json\" in args.model) {\n\t\t// Custom type model\n\n\t\treturn args.model.label || args.model.id;\n\t} else if (\"type\" in args.model && args.model.type === \"SharedSlice\") {\n\t\t// Shared Slice model\n\n\t\treturn args.model.name;\n\t} else if (\"type\" in args.model && args.model.type === \"Slice\") {\n\t\t// Legacy Slice model\n\n\t\treturn args.model.fieldset || args.name;\n\t} else if (\"type\" in args.model) {\n\t\t// Field model\n\n\t\tif (args.model.config && \"label\" in args.model.config) {\n\t\t\t// Non-Slice Zone fields\n\t\t\treturn args.model.config.label || args.name;\n\t\t} else if (args.model.config && \"fieldset\" in args.model) {\n\t\t\t// Slice Zone\n\t\t\treturn args.model.fieldset || args.name;\n\t\t}\n\t}\n\n\treturn `\\`${args.name}\\``;\n};\n"],"mappings":";AAYA,MAAa,6BAA6B,SAAwC;CACjF,IAAI,UAAU,KAAK,OAGlB,OAAO,KAAK,MAAM,SAAS,KAAK,MAAM;MAChC,IAAI,UAAU,KAAK,SAAS,KAAK,MAAM,SAAS,eAGtD,OAAO,KAAK,MAAM;MACZ,IAAI,UAAU,KAAK,SAAS,KAAK,MAAM,SAAS,SAGtD,OAAO,KAAK,MAAM,YAAY,KAAK;MAC7B,IAAI,UAAU,KAAK,OAAO;EAGhC,IAAI,KAAK,MAAM,UAAU,WAAW,KAAK,MAAM,QAE9C,OAAO,KAAK,MAAM,OAAO,SAAS,KAAK;OACjC,IAAI,KAAK,MAAM,UAAU,cAAc,KAAK,OAElD,OAAO,KAAK,MAAM,YAAY,KAAK;CAErC;CAEA,OAAO,KAAK,KAAK,KAAK;AACvB"}
@@ -1,4 +1,4 @@
1
- import { getHumanReadableModelName } from "./getHumanReadableModelName.js";
1
+ import { getHumanReadableModelName } from "./getHumanReadableModelName.mjs";
2
2
  //#region src/lib/getHumanReadablePath.ts
3
3
  function getHumanReadablePath(args) {
4
4
  return args.path.map((element) => {
@@ -13,4 +13,4 @@ function getHumanReadablePath(args) {
13
13
  //#endregion
14
14
  export { getHumanReadablePath };
15
15
 
16
- //# sourceMappingURL=getHumanReadablePath.js.map
16
+ //# sourceMappingURL=getHumanReadablePath.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getHumanReadablePath.mjs","names":[],"sources":["../../src/lib/getHumanReadablePath.ts"],"sourcesContent":["import type { FieldPath } from \"../types\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype GetHumanReadablePathArgs = {\n\tpath: FieldPath;\n};\n\nexport function getHumanReadablePath(args: GetHumanReadablePathArgs): string {\n\treturn args.path\n\t\t.map((element) => {\n\t\t\tif (element.label) {\n\t\t\t\treturn element.label;\n\t\t\t} else if (element.model) {\n\t\t\t\treturn getHumanReadableModelName({\n\t\t\t\t\tmodel: element.model,\n\t\t\t\t\tname: element.name,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\treturn element.name;\n\t\t\t}\n\t\t})\n\t\t.join(\" → \");\n}\n"],"mappings":";;AAOA,SAAgB,qBAAqB,MAAwC;CAC5E,OAAO,KAAK,KACV,KAAK,YAAY;EACjB,IAAI,QAAQ,OACX,OAAO,QAAQ;OACT,IAAI,QAAQ,OAClB,OAAO,0BAA0B;GAChC,OAAO,QAAQ;GACf,MAAM,QAAQ;EACf,CAAC;OAED,OAAO,QAAQ;CAEjB,CAAC,CAAC,CACD,KAAK,KAAK;AACb"}
@@ -0,0 +1,7 @@
1
+ //#region package.json
2
+ var version = "0.1.30-pr.82.80084b2";
3
+ var description = "An experimental Prismic model-to-TypeScript-type generator";
4
+ //#endregion
5
+ export { description, version };
6
+
7
+ //# sourceMappingURL=package.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.mjs","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
@@ -1,7 +1,6 @@
1
1
  import { CustomTypeModel, SharedSliceModel } from "@prismicio/client";
2
-
3
2
  //#region src/types.d.ts
4
- type FieldConfigs = {
3
+ export type FieldConfigs = {
5
4
  embed?: {
6
5
  providerTypes?: Record<string, string>;
7
6
  };
@@ -10,5 +9,4 @@ type FieldConfigs = {
10
9
  };
11
10
  };
12
11
  //#endregion
13
- export { FieldConfigs };
14
- //# sourceMappingURL=types.d.ts.map
12
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;YAyBY;EACX;IACC,gBAAgB;;EAEjB;IACC,eAAe"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prismic-ts-codegen",
3
- "version": "0.1.29",
3
+ "version": "0.1.30-pr.82.80084b2",
4
4
  "description": "An experimental Prismic model-to-TypeScript-type generator",
5
5
  "keywords": [
6
6
  "prismic",
@@ -21,14 +21,8 @@
21
21
  "bin"
22
22
  ],
23
23
  "type": "module",
24
- "main": "./dist/index.cjs",
25
- "module": "./dist/index.js",
26
- "types": "./dist/index.d.cts",
27
24
  "exports": {
28
- ".": {
29
- "import": "./dist/index.js",
30
- "require": "./dist/index.cjs"
31
- },
25
+ ".": "./dist/index.mjs",
32
26
  "./package.json": "./package.json"
33
27
  },
34
28
  "publishConfig": {
@@ -48,28 +42,24 @@
48
42
  "bench:watch": "vitest bench"
49
43
  },
50
44
  "dependencies": {
51
- "@prismicio/custom-types-client": "^1.3.1",
52
- "common-tags": "^1.8.2",
53
- "fast-glob": "^3.3.3",
54
- "jiti": "^1.21.7",
55
- "meow": "~12.0.1",
56
- "node-fetch": "^3.3.2",
57
- "pascal-case": "^3.1.2",
58
- "quick-lru": "^6.1.2",
59
- "zod": "^4.3.6"
45
+ "change-case": "^5.4.4",
46
+ "dedent": "^1.7.2",
47
+ "jiti": "^2.7.0",
48
+ "quick-lru": "^7.3.0",
49
+ "tinyglobby": "^0.2.17",
50
+ "zod": "^4.6.5"
60
51
  },
61
52
  "devDependencies": {
62
- "@prismicio/client": "7.18.0",
63
- "@prismicio/mock": "0.7.1",
64
- "@types/common-tags": "^1.8.1",
65
- "@types/node": "^25.5.2",
66
- "@vitest/coverage-v8": "^4.1.2",
67
- "oxfmt": "^0.43.0",
68
- "oxlint": "^1.58.0",
69
- "prismic-ts-codegen-v0-1-11": "npm:prismic-ts-codegen@0.1.11",
70
- "tsdown": "^0.21.7",
71
- "typescript": "^6.0.2",
72
- "vitest": "^4.1.2"
53
+ "@prismicio/client": "7.22.3",
54
+ "@prismicio/mock": "0.7.2",
55
+ "@types/node": "^26.6.4",
56
+ "@vitest/coverage-v8": "^5.0.3",
57
+ "oxfmt": "^0.72.0",
58
+ "oxlint": "^1.87.0",
59
+ "ts-morph": "^28.0.0",
60
+ "tsdown": "^0.23.0",
61
+ "typescript": "^7.0.2",
62
+ "vitest": "^5.0.3"
73
63
  },
74
64
  "peerDependencies": {
75
65
  "@prismicio/client": "^6.6 || ^7",
@@ -84,6 +74,6 @@
84
74
  }
85
75
  },
86
76
  "engines": {
87
- "node": ">=20"
77
+ "node": ">=22"
88
78
  }
89
79
  }
package/src/cli/index.ts CHANGED
@@ -1,18 +1,19 @@
1
1
  import { existsSync, writeFileSync } from "fs";
2
+ import { parseArgs } from "node:util";
2
3
  import { resolve as resolvePath } from "path";
3
4
 
4
- import { stripIndent } from "common-tags";
5
- import meow from "meow";
6
-
5
+ import packageJson from "../../package.json" with { type: "json" };
7
6
  import { detectTypesProvider, generateTypes } from "../index";
7
+ import { dedent } from "../lib/dedent";
8
8
  import { configSchema } from "./configSchema";
9
9
  import { NON_EDITABLE_FILE_HEADER } from "./constants";
10
10
  import { loadConfig } from "./loadConfig";
11
11
  import { loadLocaleIDs } from "./loadLocaleIDs";
12
12
  import { loadModels } from "./loadModels";
13
13
 
14
- const cli = meow(
15
- `
14
+ const HELP = dedent`
15
+ ${packageJson.description}
16
+
16
17
  Usage:
17
18
  prismic-ts-codegen [options...]
18
19
  prismic-ts-codegen init [options...]
@@ -22,22 +23,37 @@ const cli = meow(
22
23
 
23
24
  Options:
24
25
  -c, --config <path> Path to a prismic-ts-codegen configuration file.
25
- `,
26
- {
27
- importMeta: import.meta,
28
- flags: {
29
- config: {
30
- type: "string",
31
- shortFlag: "c",
32
- isRequired: false,
33
- },
34
- },
35
- },
36
- );
26
+ -h, --help Show this help.
27
+ -v, --version Show the version.
28
+ `;
37
29
 
38
30
  const main = async () => {
39
- if (cli.input[0] === "init") {
40
- const configPath = cli.flags.config || "prismicCodegen.config.ts";
31
+ const {
32
+ positionals: [command],
33
+ values: { config: configFlag, help, version },
34
+ } = parseArgs({
35
+ options: {
36
+ config: { type: "string", short: "c" },
37
+ help: { type: "boolean", short: "h" },
38
+ version: { type: "boolean", short: "v" },
39
+ },
40
+ allowPositionals: true,
41
+ strict: false,
42
+ });
43
+ const configPathFlag = typeof configFlag === "string" ? configFlag : undefined;
44
+
45
+ if (help) {
46
+ console.info(`\n${HELP}\n`);
47
+ return;
48
+ }
49
+
50
+ if (version) {
51
+ console.info(packageJson.version);
52
+ return;
53
+ }
54
+
55
+ if (command === "init") {
56
+ const configPath = configPathFlag || "prismicCodegen.config.ts";
41
57
 
42
58
  if (existsSync(configPath)) {
43
59
  console.info(`\n${configPath} already exists.`);
@@ -45,7 +61,7 @@ const main = async () => {
45
61
  let contents = "";
46
62
 
47
63
  if (existsSync("slicemachine.config.json") || existsSync("sm.json")) {
48
- contents = stripIndent`
64
+ contents = dedent`
49
65
  import type { Config } from "prismic-ts-codegen";
50
66
 
51
67
  const config: Config = {
@@ -56,7 +72,7 @@ const main = async () => {
56
72
  export default config;
57
73
  `;
58
74
  } else {
59
- contents = stripIndent`
75
+ contents = dedent`
60
76
  import type { Config } from "prismic-ts-codegen";
61
77
 
62
78
  const config: Config = {
@@ -72,7 +88,7 @@ const main = async () => {
72
88
  console.info(`\nCreated prismic-ts-codegen config file: ${configPath}`);
73
89
  }
74
90
  } else {
75
- const unvalidatedConfig = loadConfig({ path: cli.flags.config });
91
+ const unvalidatedConfig = await loadConfig({ path: configPathFlag });
76
92
 
77
93
  const result = configSchema.safeParse(unvalidatedConfig);
78
94
 
@@ -1,17 +1,11 @@
1
1
  import { existsSync } from "fs";
2
2
  import { resolve as resolvePath } from "path";
3
3
 
4
- import _jiti from "jiti";
4
+ import { createJiti } from "jiti";
5
5
 
6
6
  import type { Config } from "./configSchema";
7
7
 
8
- const jiti = _jiti(process.cwd());
9
-
10
- const loadModuleWithJiti = <TModule>(id: string): TModule => {
11
- const mod = jiti(id) as TModule | { default: TModule };
12
-
13
- return typeof mod === "object" && mod !== null && "default" in mod ? mod.default : mod;
14
- };
8
+ const jiti = createJiti(process.cwd());
15
9
 
16
10
  const DEFAULT_CONFIG_PATHS = ["prismicCodegen.config.ts", "prismicCodegen.config.js"];
17
11
 
@@ -19,17 +13,17 @@ type LoadConfigConfig = {
19
13
  path?: string;
20
14
  };
21
15
 
22
- export const loadConfig = (config: LoadConfigConfig): Config => {
16
+ export const loadConfig = async (config: LoadConfigConfig): Promise<Config> => {
23
17
  if (config.path) {
24
18
  if (existsSync(config.path)) {
25
- return loadModuleWithJiti(resolvePath(config.path));
19
+ return await jiti.import(resolvePath(config.path), { default: true });
26
20
  } else {
27
21
  throw new Error(`Config file does not exist: ${config.path}`);
28
22
  }
29
23
  } else {
30
24
  for (const configPath of DEFAULT_CONFIG_PATHS) {
31
25
  if (existsSync(configPath)) {
32
- return loadModuleWithJiti(resolvePath(configPath));
26
+ return await jiti.import(resolvePath(configPath), { default: true });
33
27
  }
34
28
  }
35
29
  }
@@ -1,5 +1,4 @@
1
1
  import * as prismic from "@prismicio/client";
2
- import fetch from "node-fetch";
3
2
 
4
3
  type LoadLocalesConfig =
5
4
  | {
@@ -1,9 +1,7 @@
1
1
  import { readFileSync } from "fs";
2
2
 
3
3
  import type { CustomTypeModel, SharedSliceModel } from "@prismicio/client";
4
- import * as prismicCT from "@prismicio/custom-types-client";
5
- import fg from "fast-glob";
6
- import fetch from "node-fetch";
4
+ import { glob } from "tinyglobby";
7
5
 
8
6
  const isCustomTypeModel = (input: unknown): input is CustomTypeModel => {
9
7
  return typeof input === "object" && input !== null && "json" in input;
@@ -14,7 +12,10 @@ const isSharedSliceModel = (input: unknown): input is SharedSliceModel => {
14
12
  };
15
13
 
16
14
  const readJSONFromGlob = async <T>(globs: string): Promise<T[]> => {
17
- const paths = await fg(globs.split(",").map((path) => path.trim()));
15
+ const paths = await glob(
16
+ globs.split(",").map((path) => path.trim()),
17
+ { expandDirectories: false },
18
+ );
18
19
 
19
20
  return paths.map((path) => {
20
21
  const raw = readFileSync(path, "utf8");
@@ -23,6 +24,26 @@ const readJSONFromGlob = async <T>(globs: string): Promise<T[]> => {
23
24
  });
24
25
  };
25
26
 
27
+ const fetchCustomTypesAPI = async <T>(
28
+ path: string,
29
+ config: { repositoryName: string; customTypesAPIToken: string },
30
+ ): Promise<T[]> => {
31
+ const res = await fetch(new URL(path, "https://customtypes.prismic.io/"), {
32
+ headers: {
33
+ repository: config.repositoryName,
34
+ Authorization: `Bearer ${config.customTypesAPIToken}`,
35
+ },
36
+ });
37
+
38
+ if (!res.ok) {
39
+ throw new Error(
40
+ `Failed to fetch models from the Custom Types API (${res.status}): ${await res.text()}`,
41
+ );
42
+ }
43
+
44
+ return await res.json();
45
+ };
46
+
26
47
  type LoadModelsConfig =
27
48
  | {
28
49
  localPaths?: string[];
@@ -44,16 +65,10 @@ export const loadModels = async (config: LoadModelsConfig): Promise<LoadModelsRe
44
65
  const sharedSliceModels: Record<string, SharedSliceModel> = {};
45
66
 
46
67
  if ("customTypesAPIToken" in config) {
47
- const customTypesClient = prismicCT.createClient({
48
- repositoryName: config.repositoryName,
49
- token: config.customTypesAPIToken,
50
- fetch,
51
- });
52
-
53
68
  if (config.fetchFromRepository) {
54
69
  const [remoteCustomTypeModels, remoteSharedSliceModels] = await Promise.all([
55
- customTypesClient.getAllCustomTypes(),
56
- customTypesClient.getAllSharedSlices(),
70
+ fetchCustomTypesAPI<CustomTypeModel>("customtypes", config),
71
+ fetchCustomTypesAPI<SharedSliceModel>("slices", config),
57
72
  ]);
58
73
 
59
74
  for (const customTypeModel of remoteCustomTypeModels) {
@@ -1,5 +1,4 @@
1
1
  import type { CustomTypeModel, SharedSliceModel } from "@prismicio/client";
2
- import { source } from "common-tags";
3
2
  import QuickLRU from "quick-lru";
4
3
 
5
4
  import { addLine } from "./lib/addLine";
@@ -7,6 +6,7 @@ import { addSection } from "./lib/addSection";
7
6
  import { buildCustomTypeType } from "./lib/buildCustomTypeType";
8
7
  import { buildSharedSliceType } from "./lib/buildSharedSliceType";
9
8
  import { buildUnion } from "./lib/buildUnion";
9
+ import { dedent } from "./lib/dedent";
10
10
  import type { FieldConfigs } from "./types";
11
11
 
12
12
  export type TypesProvider = "@prismicio/client" | "@prismicio/types";
@@ -207,7 +207,7 @@ type ContentRelationshipFieldWithData<
207
207
 
208
208
  if (config.clientIntegration.includeContentNamespace) {
209
209
  clientModuleCode = addSection(
210
- source`
210
+ dedent`
211
211
  namespace Content {
212
212
  export type {
213
213
  ${contentTypeNames.join(",\n")}
@@ -219,7 +219,7 @@ type ContentRelationshipFieldWithData<
219
219
  }
220
220
 
221
221
  code = addSection(
222
- source`
222
+ dedent`
223
223
  declare module "@prismicio/client" {
224
224
  ${clientModuleCode}
225
225
  }
@@ -1,9 +1,9 @@
1
1
  import type { CustomTypeModel } from "@prismicio/client";
2
- import { source } from "common-tags";
3
2
 
4
3
  import { buildTypeName } from "../lib/buildTypeName";
5
4
  import type { AuxiliaryType, FieldConfigs } from "../types";
6
5
  import { buildFieldProperties } from "./buildFieldProperties";
6
+ import { dedent } from "./dedent";
7
7
  import { getHumanReadableModelName } from "./getHumanReadableModelName";
8
8
 
9
9
  type BuildCustomTypeDataTypeArgs = {
@@ -55,7 +55,7 @@ export function buildCustomTypeDataType(
55
55
  }
56
56
 
57
57
  if (fieldProperties) {
58
- code = source`
58
+ code = dedent`
59
59
  /**
60
60
  * Content for ${humanReadableName} documents
61
61
  */
@@ -1,5 +1,4 @@
1
1
  import type { CustomTypeModel } from "@prismicio/client";
2
- import { source } from "common-tags";
3
2
  import type QuickLRU from "quick-lru";
4
3
 
5
4
  import { CUSTOM_TYPES_DOCUMENTATION_URL } from "../constants";
@@ -9,6 +8,7 @@ import { buildCustomTypeDataType } from "./buildCustomTypeDataType";
9
8
  import { buildTypeName } from "./buildTypeName";
10
9
  import { buildUnion } from "./buildUnion";
11
10
  import { checkHasUIDField } from "./checkHasUIDFIeld";
11
+ import { dedent } from "./dedent";
12
12
  import { getCacheKey } from "./getCacheKey";
13
13
  import { getHumanReadableModelName } from "./getHumanReadableModelName";
14
14
 
@@ -27,7 +27,7 @@ type BuildCustomTypeTypeReturnValue = {
27
27
  };
28
28
 
29
29
  export function buildCustomTypeType(
30
- args: BuildCustomTypeTypesArgs
30
+ args: BuildCustomTypeTypesArgs,
31
31
  ): BuildCustomTypeTypeReturnValue {
32
32
  if (args.cache) {
33
33
  const key = getCacheKey(args.model);
@@ -68,7 +68,7 @@ export function buildCustomTypeType(
68
68
  code = addSection(dataType.code, code);
69
69
 
70
70
  code = addSection(
71
- source`
71
+ dedent`
72
72
  /**
73
73
  * ${humanReadableName} document from Prismic
74
74
  *
@@ -79,10 +79,10 @@ export function buildCustomTypeType(
79
79
  * @typeParam Lang - Language API ID of the document.
80
80
  */
81
81
  export type ${name}<Lang extends string = ${langDefault}> = prismic.${baseDocumentType}<Simplify<${
82
- dataType.name
83
- }>, "${args.model.id}", Lang>;
82
+ dataType.name
83
+ }>, "${args.model.id}", Lang>;
84
84
  `,
85
- code
85
+ code,
86
86
  );
87
87
 
88
88
  const result = {
@@ -1,5 +1,4 @@
1
1
  import { type CustomTypeModelField, CustomTypeModelFieldType } from "@prismicio/client";
2
- import { source, stripIndent } from "common-tags";
3
2
 
4
3
  import type { AuxiliaryType, FieldConfigs, FieldPath } from "../types";
5
4
  import { addLine } from "./addLine";
@@ -7,6 +6,7 @@ import { addSection } from "./addSection";
7
6
  import { buildFieldDocs } from "./buildFieldDocs";
8
7
  import { buildTypeName } from "./buildTypeName";
9
8
  import { buildUnion } from "./buildUnion";
9
+ import { dedent } from "./dedent";
10
10
  import { getHumanReadablePath } from "./getHumanReadablePath";
11
11
 
12
12
  type BuildFieldPropertyArgs = Pick<
@@ -284,7 +284,7 @@ function buildFieldProperty(args: BuildFieldPropertyArgs): BuildFieldPropertyRet
284
284
 
285
285
  auxiliaryTypes.push({
286
286
  name: itemName,
287
- code: source`
287
+ code: dedent`
288
288
  /**
289
289
  * Item in *${humanReadablePath}*
290
290
  */
@@ -362,14 +362,14 @@ function buildFieldProperty(args: BuildFieldPropertyArgs): BuildFieldPropertyRet
362
362
  auxiliaryTypes.push(...primaryFieldProperties.auxiliaryTypes);
363
363
  contentTypeNames.push(...primaryFieldProperties.contentTypeNames);
364
364
 
365
- let primaryCode = stripIndent`
365
+ let primaryCode = dedent`
366
366
  /**
367
367
  * Primary content in *${humanReadablePath}*
368
368
  */
369
369
  `;
370
370
  primaryCode = primaryFieldProperties.code
371
371
  ? addLine(
372
- source`
372
+ dedent`
373
373
  export interface ${primaryInterfaceName} {
374
374
  ${primaryFieldProperties.code}
375
375
  }
@@ -414,14 +414,14 @@ function buildFieldProperty(args: BuildFieldPropertyArgs): BuildFieldPropertyRet
414
414
  auxiliaryTypes.push(...itemFieldProperties.auxiliaryTypes);
415
415
  contentTypeNames.push(...itemFieldProperties.contentTypeNames);
416
416
 
417
- let itemCode = stripIndent`
417
+ let itemCode = dedent`
418
418
  /**
419
419
  * Item content in *${humanReadablePath}*
420
420
  */
421
421
  `;
422
422
  itemCode = itemFieldProperties.code
423
423
  ? addLine(
424
- source`
424
+ dedent`
425
425
  export interface ${itemInterfaceName} {
426
426
  ${itemFieldProperties.code}
427
427
  }
@@ -439,7 +439,7 @@ function buildFieldProperty(args: BuildFieldPropertyArgs): BuildFieldPropertyRet
439
439
 
440
440
  auxiliaryTypes.push({
441
441
  name: sliceName,
442
- code: stripIndent`
442
+ code: dedent`
443
443
  /**
444
444
  * Slice for *${getHumanReadablePath({
445
445
  path: [