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
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import("../dist/cli.cjs");
3
+ import("../dist/cli.mjs");
@@ -1,8 +1,7 @@
1
1
  import { z } from "zod";
2
-
3
2
  //#region src/cli/configSchema.d.ts
4
3
  /** Configuration to control the generated types. */
5
- declare const configSchema: z.ZodObject<{
4
+ export declare const configSchema: z.ZodObject<{
6
5
  repositoryName: z.ZodOptional<z.ZodString>;
7
6
  accessToken: z.ZodOptional<z.ZodString>;
8
7
  customTypesAPIToken: z.ZodOptional<z.ZodString>;
@@ -33,7 +32,6 @@ declare const configSchema: z.ZodObject<{
33
32
  }, z.core.$strip>>;
34
33
  }, z.core.$strip>;
35
34
  /** Configuration to control the generated types. */
36
- type Config = z.infer<typeof configSchema>;
35
+ export type Config = z.infer<typeof configSchema>;
37
36
  //#endregion
38
- export { Config };
39
- //# sourceMappingURL=configSchema.d.ts.map
37
+ //# sourceMappingURL=configSchema.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configSchema.d.mts","names":[],"sources":["../../src/cli/configSchema.ts"],"mappings":";;;qBAGa,cAAY,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkLvB,EAAA,KAAA;;YAGU,SAAS,EAAE,aAAa"}
@@ -0,0 +1,154 @@
1
+ import { z } from "zod";
2
+ //#region src/cli/configSchema.ts
3
+ /** Configuration to control the generated types. */
4
+ const configSchema = z.object({
5
+ /** The name of the Prismic repository. */
6
+ repositoryName: z.string().optional(),
7
+ /**
8
+ * The access token for the Prismic repository. If the repository is private and
9
+ * `locales.fetchFromRepository` is `true`, providing a token is required.
10
+ */
11
+ accessToken: z.string().optional(),
12
+ /**
13
+ * The Custom Types API token for the Prismic repository. If `models.fetchFromRepository` is
14
+ * `true`, providing a token is required.
15
+ */
16
+ customTypesAPIToken: z.string().optional(),
17
+ /**
18
+ * The file path where the generated types will be saved. This path is relative to where the
19
+ * command is called.
20
+ */
21
+ output: z.string().optional(),
22
+ /**
23
+ * The package that provides TypeScript types for Prismic data. Most projects will not need to
24
+ * configure this option.
25
+ *
26
+ * @defaultValue Automatically detected using the project's `package.json`.
27
+ */
28
+ typesProvider: z.enum(["@prismicio/client", "@prismicio/types"]).optional(),
29
+ /** Configuration for automatic `@prismicio/client` integration. */
30
+ clientIntegration: z.object({
31
+ /**
32
+ * Determines if a `@prismicio/client` integration with automatic typing should be included in
33
+ * the output.
34
+ *
35
+ * If set to `true`, Prismic clients will automatically be typed with the generated Custom
36
+ * Types and Slices.
37
+ *
38
+ * **Note**: If your project queries content from multiple Prismic repositories, set
39
+ * `includeCreateClientInterface` to `true` for the primary repository and `false` or any
40
+ * other repository. The generated `AllDocumentTypes` type for non-primary repositories can be
41
+ * provided to `@prismicio/client`'s `createClient()` function as its only type parameter to
42
+ * type the client.
43
+ *
44
+ * @defaultValue `true`
45
+ */
46
+ includeCreateClientInterface: z.boolean().optional(),
47
+ /**
48
+ * Determines if a `@prismicio/client` namespace named `Content` containing all Document and
49
+ * Slice types should be included in the output.
50
+ *
51
+ * If set to `true`, a `Content` namespace from `@prismicio/client` will be available to
52
+ * import to easily access types for your Prismic repository content.
53
+ *
54
+ * **Note**: If your project queries content from multiple Prismic repositories, set
55
+ * `includeContentNamespace` to `true` for the primary repository and `false` or any other
56
+ * repository. Types for non-primary repositories should be imported directly from the
57
+ * generated file rather than via the `Content` namespace.
58
+ *
59
+ * @defaultValue `true`
60
+ */
61
+ includeContentNamespace: z.boolean().optional()
62
+ }).optional(),
63
+ /**
64
+ * Configuration for languages for the Prismic repository.
65
+ *
66
+ * It can be configured by providing an array of locale IDs configured for the repository or an
67
+ * object with finer control.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * ["en-us", "fr-fr"];
72
+ * ```;
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * {
77
+ * "ids": ["en-us", "fr-fr"],
78
+ * "fetchFromRepository": true
79
+ * }
80
+ * ```;
81
+ */
82
+ locales: z.union([z.array(z.string()), z.object({
83
+ /**
84
+ * A list of locales configured for the Prismic repository. This is used to type a
85
+ * document's `lang` property.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * ["en-us", "fr-fr"];
90
+ * ```;
91
+ */
92
+ ids: z.array(z.string()).optional(),
93
+ /**
94
+ * Determines if the Prismic repository's locales should be fetched from the repository's
95
+ * API.
96
+ */
97
+ fetchFromRepository: z.boolean().optional()
98
+ })]).optional(),
99
+ /**
100
+ * Configuration for Custom Type and Slice models for the Prismic repository.
101
+ *
102
+ * It can be configured by providing an array of file paths to Custom Type and Slice JSON models
103
+ * or an object with finer control.
104
+ */
105
+ models: z.union([z.array(z.string()), z.object({
106
+ /** A list of file paths to Custom Type and Slice models. Globs are supported. */
107
+ files: z.array(z.string()).optional(),
108
+ /**
109
+ * Determines if the Prismic repository's Custom Type and Slice models should be fetched
110
+ * from the repository's API.
111
+ *
112
+ * `customTypesAPIToken` must be provided if set to `true`.
113
+ */
114
+ fetchFromRepository: z.boolean().optional()
115
+ })]).optional(),
116
+ /** Configuration for types generated for fields. */
117
+ fields: z.object({
118
+ /** Configuration for Embed fields. */
119
+ embed: z.object({
120
+ /**
121
+ * An object mapping oEmbed providers to their type. The type should be provided as a
122
+ * string and is added directly into the generated types.
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * {
127
+ * "YouTube": "import('./types').OEmbedYouTube"
128
+ * "Twitter": "import('./types').OEmbedTwitter"
129
+ * "Vimeo": "import('./types').OEmbedVimeo"
130
+ * }
131
+ * ```;
132
+ */
133
+ providerTypes: z.record(z.string(), z.string()).optional() }).optional(),
134
+ /** Configuration for Integration Fields. */
135
+ integrationFields: z.object({
136
+ /**
137
+ * An object mapping catalog IDs to their type. The type should be provided as a string
138
+ * and is added directly into the generated types.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * {
143
+ * "shopify_products": "import('./types').IntegrationFieldShopifyProduct"
144
+ * "mux_videos": "import('./types').IntegrationFieldMuxVideo"
145
+ * }
146
+ * ```;
147
+ */
148
+ catalogTypes: z.record(z.string(), z.string()).optional() }).optional()
149
+ }).optional()
150
+ });
151
+ //#endregion
152
+ export { configSchema };
153
+
154
+ //# sourceMappingURL=configSchema.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configSchema.mjs","names":[],"sources":["../../src/cli/configSchema.ts"],"sourcesContent":["import { z } from \"zod\";\n\n/** Configuration to control the generated types. */\nexport const configSchema = z.object({\n\t/** The name of the Prismic repository. */\n\trepositoryName: z.string().optional(),\n\n\t/**\n\t * The access token for the Prismic repository. If the repository is private and\n\t * `locales.fetchFromRepository` is `true`, providing a token is required.\n\t */\n\taccessToken: z.string().optional(),\n\n\t/**\n\t * The Custom Types API token for the Prismic repository. If `models.fetchFromRepository` is\n\t * `true`, providing a token is required.\n\t */\n\tcustomTypesAPIToken: z.string().optional(),\n\n\t/**\n\t * The file path where the generated types will be saved. This path is relative to where the\n\t * command is called.\n\t */\n\toutput: z.string().optional(),\n\n\t/**\n\t * The package that provides TypeScript types for Prismic data. Most projects will not need to\n\t * configure this option.\n\t *\n\t * @defaultValue Automatically detected using the project's `package.json`.\n\t */\n\ttypesProvider: z.enum([\"@prismicio/client\", \"@prismicio/types\"]).optional(),\n\n\t/** Configuration for automatic `@prismicio/client` integration. */\n\tclientIntegration: z\n\t\t.object({\n\t\t\t/**\n\t\t\t * Determines if a `@prismicio/client` integration with automatic typing should be included in\n\t\t\t * the output.\n\t\t\t *\n\t\t\t * If set to `true`, Prismic clients will automatically be typed with the generated Custom\n\t\t\t * Types and Slices.\n\t\t\t *\n\t\t\t * **Note**: If your project queries content from multiple Prismic repositories, set\n\t\t\t * `includeCreateClientInterface` to `true` for the primary repository and `false` or any\n\t\t\t * other repository. The generated `AllDocumentTypes` type for non-primary repositories can be\n\t\t\t * provided to `@prismicio/client`'s `createClient()` function as its only type parameter to\n\t\t\t * type the client.\n\t\t\t *\n\t\t\t * @defaultValue `true`\n\t\t\t */\n\t\t\tincludeCreateClientInterface: z.boolean().optional(),\n\n\t\t\t/**\n\t\t\t * Determines if a `@prismicio/client` namespace named `Content` containing all Document and\n\t\t\t * Slice types should be included in the output.\n\t\t\t *\n\t\t\t * If set to `true`, a `Content` namespace from `@prismicio/client` will be available to\n\t\t\t * import to easily access types for your Prismic repository content.\n\t\t\t *\n\t\t\t * **Note**: If your project queries content from multiple Prismic repositories, set\n\t\t\t * `includeContentNamespace` to `true` for the primary repository and `false` or any other\n\t\t\t * repository. Types for non-primary repositories should be imported directly from the\n\t\t\t * generated file rather than via the `Content` namespace.\n\t\t\t *\n\t\t\t * @defaultValue `true`\n\t\t\t */\n\t\t\tincludeContentNamespace: z.boolean().optional(),\n\t\t})\n\t\t.optional(),\n\n\t/**\n\t * Configuration for languages for the Prismic repository.\n\t *\n\t * It can be configured by providing an array of locale IDs configured for the repository or an\n\t * object with finer control.\n\t *\n\t * @example\n\t * \t```ts\n\t * \t[\"en-us\", \"fr-fr\"];\n\t * \t```;\n\t *\n\t * @example\n\t * \t```ts\n\t * \t{\n\t * \t\"ids\": [\"en-us\", \"fr-fr\"],\n\t * \t\"fetchFromRepository\": true\n\t * \t}\n\t * \t```;\n\t */\n\tlocales: z\n\t\t.union([\n\t\t\tz.array(z.string()),\n\t\t\tz.object({\n\t\t\t\t/**\n\t\t\t\t * A list of locales configured for the Prismic repository. This is used to type a\n\t\t\t\t * document's `lang` property.\n\t\t\t\t *\n\t\t\t\t * @example\n\t\t\t\t * \t```ts\n\t\t\t\t * \t[\"en-us\", \"fr-fr\"];\n\t\t\t\t * \t```;\n\t\t\t\t */\n\t\t\t\tids: z.array(z.string()).optional(),\n\n\t\t\t\t/**\n\t\t\t\t * Determines if the Prismic repository's locales should be fetched from the repository's\n\t\t\t\t * API.\n\t\t\t\t */\n\t\t\t\tfetchFromRepository: z.boolean().optional(),\n\t\t\t}),\n\t\t])\n\t\t.optional(),\n\n\t/**\n\t * Configuration for Custom Type and Slice models for the Prismic repository.\n\t *\n\t * It can be configured by providing an array of file paths to Custom Type and Slice JSON models\n\t * or an object with finer control.\n\t */\n\tmodels: z\n\t\t.union([\n\t\t\tz.array(z.string()),\n\t\t\tz.object({\n\t\t\t\t/** A list of file paths to Custom Type and Slice models. Globs are supported. */\n\t\t\t\tfiles: z.array(z.string()).optional(),\n\n\t\t\t\t/**\n\t\t\t\t * Determines if the Prismic repository's Custom Type and Slice models should be fetched\n\t\t\t\t * from the repository's API.\n\t\t\t\t *\n\t\t\t\t * `customTypesAPIToken` must be provided if set to `true`.\n\t\t\t\t */\n\t\t\t\tfetchFromRepository: z.boolean().optional(),\n\t\t\t}),\n\t\t])\n\t\t.optional(),\n\n\t/** Configuration for types generated for fields. */\n\tfields: z\n\t\t.object({\n\t\t\t/** Configuration for Embed fields. */\n\t\t\tembed: z\n\t\t\t\t.object({\n\t\t\t\t\t/**\n\t\t\t\t\t * An object mapping oEmbed providers to their type. The type should be provided as a\n\t\t\t\t\t * string and is added directly into the generated types.\n\t\t\t\t\t *\n\t\t\t\t\t * @example\n\t\t\t\t\t * \t```ts\n\t\t\t\t\t * \t{\n\t\t\t\t\t * \t\"YouTube\": \"import('./types').OEmbedYouTube\"\n\t\t\t\t\t * \t\"Twitter\": \"import('./types').OEmbedTwitter\"\n\t\t\t\t\t * \t\"Vimeo\": \"import('./types').OEmbedVimeo\"\n\t\t\t\t\t * \t}\n\t\t\t\t\t * \t```;\n\t\t\t\t\t */\n\t\t\t\t\tproviderTypes: z.record(z.string(), z.string()).optional(),\n\t\t\t\t})\n\t\t\t\t.optional(),\n\n\t\t\t/** Configuration for Integration Fields. */\n\t\t\tintegrationFields: z\n\t\t\t\t.object({\n\t\t\t\t\t/**\n\t\t\t\t\t * An object mapping catalog IDs to their type. The type should be provided as a string\n\t\t\t\t\t * and is added directly into the generated types.\n\t\t\t\t\t *\n\t\t\t\t\t * @example\n\t\t\t\t\t * \t```ts\n\t\t\t\t\t * \t{\n\t\t\t\t\t * \t\"shopify_products\": \"import('./types').IntegrationFieldShopifyProduct\"\n\t\t\t\t\t * \t\"mux_videos\": \"import('./types').IntegrationFieldMuxVideo\"\n\t\t\t\t\t * \t}\n\t\t\t\t\t * \t```;\n\t\t\t\t\t */\n\t\t\t\t\tcatalogTypes: z.record(z.string(), z.string()).optional(),\n\t\t\t\t})\n\t\t\t\t.optional(),\n\t\t})\n\t\t.optional(),\n});\n\n/** Configuration to control the generated types. */\nexport type Config = z.infer<typeof configSchema>;\n"],"mappings":";;;AAGA,MAAa,eAAe,EAAE,OAAO;;CAEpC,gBAAgB,EAAE,OAAO,CAAC,CAAC,SAAS;;;;;CAMpC,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;;;;;CAMjC,qBAAqB,EAAE,OAAO,CAAC,CAAC,SAAS;;;;;CAMzC,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;;;;;;;CAQ5B,eAAe,EAAE,KAAK,CAAC,qBAAqB,kBAAkB,CAAC,CAAC,CAAC,SAAS;;CAG1E,mBAAmB,EACjB,OAAO;;;;;;;;;;;;;;;;EAgBP,8BAA8B,EAAE,QAAQ,CAAC,CAAC,SAAS;;;;;;;;;;;;;;;EAgBnD,yBAAyB,EAAE,QAAQ,CAAC,CAAC,SAAS;CAC/C,CAAC,CAAC,CACD,SAAS;;;;;;;;;;;;;;;;;;;;CAqBX,SAAS,EACP,MAAM,CACN,EAAE,MAAM,EAAE,OAAO,CAAC,GAClB,EAAE,OAAO;;;;;;;;;;EAUR,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS;;;;;EAMlC,qBAAqB,EAAE,QAAQ,CAAC,CAAC,SAAS;CAC3C,CAAC,CACF,CAAC,CAAC,CACD,SAAS;;;;;;;CAQX,QAAQ,EACN,MAAM,CACN,EAAE,MAAM,EAAE,OAAO,CAAC,GAClB,EAAE,OAAO;;EAER,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS;;;;;;;EAQpC,qBAAqB,EAAE,QAAQ,CAAC,CAAC,SAAS;CAC3C,CAAC,CACF,CAAC,CAAC,CACD,SAAS;;CAGX,QAAQ,EACN,OAAO;;EAEP,OAAO,EACL,OAAO;;;;;;;;;;;;;;AAcP,eAAe,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,EAC1D,CAAC,CAAC,CACD,SAAS;;EAGX,mBAAmB,EACjB,OAAO;;;;;;;;;;;;;AAaP,cAAc,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,EACzD,CAAC,CAAC,CACD,SAAS;CACZ,CAAC,CAAC,CACD,SAAS;AACZ,CAAC"}
@@ -0,0 +1,4 @@
1
+ //#region src/cli/constants.d.ts
2
+ export declare const NON_EDITABLE_FILE_HEADER = "// Code generated by prismic-ts-codegen. DO NOT EDIT.";
3
+ //#endregion
4
+ //# sourceMappingURL=constants.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.mts","names":[],"sources":["../../src/cli/constants.ts"],"mappings":";qBAAa"}
@@ -3,4 +3,4 @@ const NON_EDITABLE_FILE_HEADER = "// Code generated by prismic-ts-codegen. DO NO
3
3
  //#endregion
4
4
  export { NON_EDITABLE_FILE_HEADER };
5
5
 
6
- //# sourceMappingURL=constants.js.map
6
+ //# sourceMappingURL=constants.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.cjs","names":[],"sources":["../../src/cli/constants.ts"],"sourcesContent":["export const NON_EDITABLE_FILE_HEADER = \"// Code generated by prismic-ts-codegen. DO NOT EDIT.\";\n"],"mappings":";AAAA,MAAa,2BAA2B"}
1
+ {"version":3,"file":"constants.mjs","names":[],"sources":["../../src/cli/constants.ts"],"sourcesContent":["export const NON_EDITABLE_FILE_HEADER = \"// Code generated by prismic-ts-codegen. DO NOT EDIT.\";\n"],"mappings":";AAAA,MAAa,2BAA2B"}
@@ -0,0 +1,17 @@
1
+ import { existsSync } from "fs";
2
+ import { resolve } from "path";
3
+ import { createJiti } from "jiti";
4
+ //#region src/cli/loadConfig.ts
5
+ const jiti = createJiti(process.cwd());
6
+ const DEFAULT_CONFIG_PATHS = ["prismicCodegen.config.ts", "prismicCodegen.config.js"];
7
+ const loadConfig = async (config) => {
8
+ if (config.path) {
9
+ if (existsSync(config.path)) return await jiti.import(resolve(config.path), { default: true });
10
+ else throw new Error(`Config file does not exist: ${config.path}`);
11
+ } else for (const configPath of DEFAULT_CONFIG_PATHS) if (existsSync(configPath)) return await jiti.import(resolve(configPath), { default: true });
12
+ return {};
13
+ };
14
+ //#endregion
15
+ export { loadConfig };
16
+
17
+ //# sourceMappingURL=loadConfig.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadConfig.mjs","names":["resolvePath"],"sources":["../../src/cli/loadConfig.ts"],"sourcesContent":["import { existsSync } from \"fs\";\nimport { resolve as resolvePath } from \"path\";\n\nimport { createJiti } from \"jiti\";\n\nimport type { Config } from \"./configSchema\";\n\nconst jiti = createJiti(process.cwd());\n\nconst DEFAULT_CONFIG_PATHS = [\"prismicCodegen.config.ts\", \"prismicCodegen.config.js\"];\n\ntype LoadConfigConfig = {\n\tpath?: string;\n};\n\nexport const loadConfig = async (config: LoadConfigConfig): Promise<Config> => {\n\tif (config.path) {\n\t\tif (existsSync(config.path)) {\n\t\t\treturn await jiti.import(resolvePath(config.path), { default: true });\n\t\t} else {\n\t\t\tthrow new Error(`Config file does not exist: ${config.path}`);\n\t\t}\n\t} else {\n\t\tfor (const configPath of DEFAULT_CONFIG_PATHS) {\n\t\t\tif (existsSync(configPath)) {\n\t\t\t\treturn await jiti.import(resolvePath(configPath), { default: true });\n\t\t\t}\n\t\t}\n\t}\n\n\t// If no config file exists, an empty config is returned.\n\treturn {};\n};\n"],"mappings":";;;;AAOA,MAAM,OAAO,WAAW,QAAQ,IAAI,CAAC;AAErC,MAAM,uBAAuB,CAAC,4BAA4B,0BAA0B;AAMpF,MAAa,aAAa,OAAO,WAA8C;CAC9E,IAAI,OAAO,MAAM;EAChB,IAAI,WAAW,OAAO,IAAI,GACzB,OAAO,MAAM,KAAK,OAAOA,QAAY,OAAO,IAAI,GAAG,EAAE,SAAS,KAAK,CAAC;OAEpE,MAAM,IAAI,MAAM,+BAA+B,OAAO,MAAM;CAE9D,OACC,KAAK,MAAM,cAAc,sBACxB,IAAI,WAAW,UAAU,GACxB,OAAO,MAAM,KAAK,OAAOA,QAAY,UAAU,GAAG,EAAE,SAAS,KAAK,CAAC;CAMtE,OAAO,CAAC;AACT"}
@@ -1,5 +1,4 @@
1
1
  import * as prismic from "@prismicio/client";
2
- import fetch from "node-fetch";
3
2
  //#region src/cli/loadLocaleIDs.ts
4
3
  const loadLocaleIDs = async (config) => {
5
4
  const localeIDs = new Set(config.localeIDs || []);
@@ -15,4 +14,4 @@ const loadLocaleIDs = async (config) => {
15
14
  //#endregion
16
15
  export { loadLocaleIDs };
17
16
 
18
- //# sourceMappingURL=loadLocaleIDs.js.map
17
+ //# sourceMappingURL=loadLocaleIDs.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadLocaleIDs.mjs","names":[],"sources":["../../src/cli/loadLocaleIDs.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\ntype LoadLocalesConfig =\n\t| {\n\t\t\tlocaleIDs?: string[];\n\t }\n\t| {\n\t\t\tlocaleIDs?: string[];\n\t\t\trepositoryName: string;\n\t\t\taccessToken: string;\n\t\t\tfetchFromRepository?: boolean;\n\t };\n\nexport const loadLocaleIDs = async (config: LoadLocalesConfig): Promise<string[]> => {\n\tconst localeIDs = new Set<string>(config.localeIDs || []);\n\n\tif (\"repositoryName\" in config && config.fetchFromRepository) {\n\t\tconst client = prismic.createClient(config.repositoryName, {\n\t\t\taccessToken: config.accessToken,\n\t\t\tfetch,\n\t\t});\n\n\t\tconst repository = await client.getRepository();\n\n\t\tfor (const language of repository.languages) {\n\t\t\tlocaleIDs.add(language.id);\n\t\t}\n\t}\n\n\treturn [...localeIDs];\n};\n"],"mappings":";;AAaA,MAAa,gBAAgB,OAAO,WAAiD;CACpF,MAAM,YAAY,IAAI,IAAY,OAAO,aAAa,CAAC,CAAC;CAExD,IAAI,oBAAoB,UAAU,OAAO,qBAAqB;EAM7D,MAAM,aAAa,MALJ,QAAQ,aAAa,OAAO,gBAAgB;GAC1D,aAAa,OAAO;GACpB;EACD,CAE8B,CAAC,CAAC,cAAc;EAE9C,KAAK,MAAM,YAAY,WAAW,WACjC,UAAU,IAAI,SAAS,EAAE;CAE3B;CAEA,OAAO,CAAC,GAAG,SAAS;AACrB"}
@@ -1,7 +1,5 @@
1
1
  import { readFileSync } from "fs";
2
- import fetch from "node-fetch";
3
- import * as prismicCT from "@prismicio/custom-types-client";
4
- import fg from "fast-glob";
2
+ import { glob } from "tinyglobby";
5
3
  //#region src/cli/loadModels.ts
6
4
  const isCustomTypeModel = (input) => {
7
5
  return typeof input === "object" && input !== null && "json" in input;
@@ -10,22 +8,25 @@ const isSharedSliceModel = (input) => {
10
8
  return typeof input === "object" && input !== null && "variations" in input;
11
9
  };
12
10
  const readJSONFromGlob = async (globs) => {
13
- return (await fg(globs.split(",").map((path) => path.trim()))).map((path) => {
11
+ return (await glob(globs.split(",").map((path) => path.trim()), { expandDirectories: false })).map((path) => {
14
12
  const raw = readFileSync(path, "utf8");
15
13
  return JSON.parse(raw);
16
14
  });
17
15
  };
16
+ const fetchCustomTypesAPI = async (path, config) => {
17
+ const res = await fetch(new URL(path, "https://customtypes.prismic.io/"), { headers: {
18
+ repository: config.repositoryName,
19
+ Authorization: `Bearer ${config.customTypesAPIToken}`
20
+ } });
21
+ if (!res.ok) throw new Error(`Failed to fetch models from the Custom Types API (${res.status}): ${await res.text()}`);
22
+ return await res.json();
23
+ };
18
24
  const loadModels = async (config) => {
19
25
  const customTypeModels = {};
20
26
  const sharedSliceModels = {};
21
27
  if ("customTypesAPIToken" in config) {
22
- const customTypesClient = prismicCT.createClient({
23
- repositoryName: config.repositoryName,
24
- token: config.customTypesAPIToken,
25
- fetch
26
- });
27
28
  if (config.fetchFromRepository) {
28
- const [remoteCustomTypeModels, remoteSharedSliceModels] = await Promise.all([customTypesClient.getAllCustomTypes(), customTypesClient.getAllSharedSlices()]);
29
+ const [remoteCustomTypeModels, remoteSharedSliceModels] = await Promise.all([fetchCustomTypesAPI("customtypes", config), fetchCustomTypesAPI("slices", config)]);
29
30
  for (const customTypeModel of remoteCustomTypeModels) customTypeModels[customTypeModel.id] = customTypeModel;
30
31
  for (const sharedSliceModel of remoteSharedSliceModels) sharedSliceModels[sharedSliceModel.id] = sharedSliceModel;
31
32
  }
@@ -47,4 +48,4 @@ const loadModels = async (config) => {
47
48
  //#endregion
48
49
  export { loadModels };
49
50
 
50
- //# sourceMappingURL=loadModels.js.map
51
+ //# sourceMappingURL=loadModels.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadModels.mjs","names":[],"sources":["../../src/cli/loadModels.ts"],"sourcesContent":["import { readFileSync } from \"fs\";\n\nimport type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { glob } from \"tinyglobby\";\n\nconst isCustomTypeModel = (input: unknown): input is CustomTypeModel => {\n\treturn typeof input === \"object\" && input !== null && \"json\" in input;\n};\n\nconst isSharedSliceModel = (input: unknown): input is SharedSliceModel => {\n\treturn typeof input === \"object\" && input !== null && \"variations\" in input;\n};\n\nconst readJSONFromGlob = async <T>(globs: string): Promise<T[]> => {\n\tconst paths = await glob(\n\t\tglobs.split(\",\").map((path) => path.trim()),\n\t\t{ expandDirectories: false },\n\t);\n\n\treturn paths.map((path) => {\n\t\tconst raw = readFileSync(path, \"utf8\");\n\n\t\treturn JSON.parse(raw);\n\t});\n};\n\nconst fetchCustomTypesAPI = async <T>(\n\tpath: string,\n\tconfig: { repositoryName: string; customTypesAPIToken: string },\n): Promise<T[]> => {\n\tconst res = await fetch(new URL(path, \"https://customtypes.prismic.io/\"), {\n\t\theaders: {\n\t\t\trepository: config.repositoryName,\n\t\t\tAuthorization: `Bearer ${config.customTypesAPIToken}`,\n\t\t},\n\t});\n\n\tif (!res.ok) {\n\t\tthrow new Error(\n\t\t\t`Failed to fetch models from the Custom Types API (${res.status}): ${await res.text()}`,\n\t\t);\n\t}\n\n\treturn await res.json();\n};\n\ntype LoadModelsConfig =\n\t| {\n\t\t\tlocalPaths?: string[];\n\t }\n\t| {\n\t\t\tlocalPaths?: string[];\n\t\t\trepositoryName: string;\n\t\t\tcustomTypesAPIToken: string;\n\t\t\tfetchFromRepository?: boolean;\n\t };\n\ntype LoadModelsReturnType = {\n\tcustomTypeModels: CustomTypeModel[];\n\tsharedSliceModels: SharedSliceModel[];\n};\n\nexport const loadModels = async (config: LoadModelsConfig): Promise<LoadModelsReturnType> => {\n\tconst customTypeModels: Record<string, CustomTypeModel> = {};\n\tconst sharedSliceModels: Record<string, SharedSliceModel> = {};\n\n\tif (\"customTypesAPIToken\" in config) {\n\t\tif (config.fetchFromRepository) {\n\t\t\tconst [remoteCustomTypeModels, remoteSharedSliceModels] = await Promise.all([\n\t\t\t\tfetchCustomTypesAPI<CustomTypeModel>(\"customtypes\", config),\n\t\t\t\tfetchCustomTypesAPI<SharedSliceModel>(\"slices\", config),\n\t\t\t]);\n\n\t\t\tfor (const customTypeModel of remoteCustomTypeModels) {\n\t\t\t\tcustomTypeModels[customTypeModel.id] = customTypeModel;\n\t\t\t}\n\t\t\tfor (const sharedSliceModel of remoteSharedSliceModels) {\n\t\t\t\tsharedSliceModels[sharedSliceModel.id] = sharedSliceModel;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (config.localPaths) {\n\t\tconst models = (\n\t\t\tawait Promise.all(config.localPaths.map((glob) => readJSONFromGlob(glob)))\n\t\t).flat();\n\n\t\tfor (const model of models) {\n\t\t\tif (isCustomTypeModel(model)) {\n\t\t\t\tcustomTypeModels[model.id] = model;\n\t\t\t} else if (isSharedSliceModel(model)) {\n\t\t\t\tsharedSliceModels[model.id] = model;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\tcustomTypeModels: Object.values(customTypeModels).sort((a, b) => {\n\t\t\treturn a.id.localeCompare(b.id);\n\t\t}),\n\t\tsharedSliceModels: Object.values(sharedSliceModels).sort((a, b) => {\n\t\t\treturn a.id.localeCompare(b.id);\n\t\t}),\n\t};\n};\n"],"mappings":";;;AAKA,MAAM,qBAAqB,UAA6C;CACvE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU;AACjE;AAEA,MAAM,sBAAsB,UAA8C;CACzE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,gBAAgB;AACvE;AAEA,MAAM,mBAAmB,OAAU,UAAgC;CAMlE,QAAO,MALa,KACnB,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,SAAS,KAAK,KAAK,CAAC,GAC1C,EAAE,mBAAmB,MAAM,CAC5B,EAAA,CAEa,KAAK,SAAS;EAC1B,MAAM,MAAM,aAAa,MAAM,MAAM;EAErC,OAAO,KAAK,MAAM,GAAG;CACtB,CAAC;AACF;AAEA,MAAM,sBAAsB,OAC3B,MACA,WACkB;CAClB,MAAM,MAAM,MAAM,MAAM,IAAI,IAAI,MAAM,iCAAiC,GAAG,EACzE,SAAS;EACR,YAAY,OAAO;EACnB,eAAe,UAAU,OAAO;CACjC,EACD,CAAC;CAED,IAAI,CAAC,IAAI,IACR,MAAM,IAAI,MACT,qDAAqD,IAAI,OAAO,KAAK,MAAM,IAAI,KAAK,GACrF;CAGD,OAAO,MAAM,IAAI,KAAK;AACvB;AAkBA,MAAa,aAAa,OAAO,WAA4D;CAC5F,MAAM,mBAAoD,CAAC;CAC3D,MAAM,oBAAsD,CAAC;CAE7D,IAAI,yBAAyB,QACxB;MAAA,OAAO,qBAAqB;GAC/B,MAAM,CAAC,wBAAwB,2BAA2B,MAAM,QAAQ,IAAI,CAC3E,oBAAqC,eAAe,MAAM,GAC1D,oBAAsC,UAAU,MAAM,CACvD,CAAC;GAED,KAAK,MAAM,mBAAmB,wBAC7B,iBAAiB,gBAAgB,MAAM;GAExC,KAAK,MAAM,oBAAoB,yBAC9B,kBAAkB,iBAAiB,MAAM;EAE3C;;CAGD,IAAI,OAAO,YAAY;EACtB,MAAM,UACL,MAAM,QAAQ,IAAI,OAAO,WAAW,KAAK,SAAS,iBAAiB,IAAI,CAAC,CAAC,EAAA,CACxE,KAAK;EAEP,KAAK,MAAM,SAAS,QACnB,IAAI,kBAAkB,KAAK,GAC1B,iBAAiB,MAAM,MAAM;OACvB,IAAI,mBAAmB,KAAK,GAClC,kBAAkB,MAAM,MAAM;CAGjC;CAEA,OAAO;EACN,kBAAkB,OAAO,OAAO,gBAAgB,CAAC,CAAC,MAAM,GAAG,MAAM;GAChE,OAAO,EAAE,GAAG,cAAc,EAAE,EAAE;EAC/B,CAAC;EACD,mBAAmB,OAAO,OAAO,iBAAiB,CAAC,CAAC,MAAM,GAAG,MAAM;GAClE,OAAO,EAAE,GAAG,cAAc,EAAE,EAAE;EAC/B,CAAC;CACF;AACD"}
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export {}
@@ -1,17 +1,20 @@
1
- import { generateTypes } from "./generateTypes.js";
2
- import { detectTypesProvider } from "./detectTypesProvider.js";
3
- import { NON_EDITABLE_FILE_HEADER } from "./cli/constants.js";
4
- import "./index.js";
5
- import { configSchema } from "./cli/configSchema.js";
6
- import { loadConfig } from "./cli/loadConfig.js";
7
- import { loadLocaleIDs } from "./cli/loadLocaleIDs.js";
8
- import { loadModels } from "./cli/loadModels.js";
9
- import { stripIndent } from "common-tags";
1
+ import { dedent } from "./lib/dedent.mjs";
2
+ import { generateTypes } from "./generateTypes.mjs";
3
+ import { detectTypesProvider } from "./detectTypesProvider.mjs";
4
+ import { NON_EDITABLE_FILE_HEADER } from "./cli/constants.mjs";
5
+ import "./index.mjs";
6
+ import { description, version } from "./package.mjs";
7
+ import { configSchema } from "./cli/configSchema.mjs";
8
+ import { loadConfig } from "./cli/loadConfig.mjs";
9
+ import { loadLocaleIDs } from "./cli/loadLocaleIDs.mjs";
10
+ import { loadModels } from "./cli/loadModels.mjs";
10
11
  import { existsSync, writeFileSync } from "fs";
12
+ import { parseArgs } from "node:util";
11
13
  import { resolve } from "path";
12
- import meow from "meow";
13
14
  //#region src/cli/index.ts
14
- const cli = meow(`
15
+ const HELP = dedent`
16
+ ${description}
17
+
15
18
  Usage:
16
19
  prismic-ts-codegen [options...]
17
20
  prismic-ts-codegen init [options...]
@@ -21,21 +24,43 @@ const cli = meow(`
21
24
 
22
25
  Options:
23
26
  -c, --config <path> Path to a prismic-ts-codegen configuration file.
24
- `, {
25
- importMeta: import.meta,
26
- flags: { config: {
27
- type: "string",
28
- shortFlag: "c",
29
- isRequired: false
30
- } }
31
- });
27
+ -h, --help Show this help.
28
+ -v, --version Show the version.
29
+ `;
32
30
  const main = async () => {
33
- if (cli.input[0] === "init") {
34
- const configPath = cli.flags.config || "prismicCodegen.config.ts";
31
+ const { positionals: [command], values: { config: configFlag, help, version: version$1 } } = parseArgs({
32
+ options: {
33
+ config: {
34
+ type: "string",
35
+ short: "c"
36
+ },
37
+ help: {
38
+ type: "boolean",
39
+ short: "h"
40
+ },
41
+ version: {
42
+ type: "boolean",
43
+ short: "v"
44
+ }
45
+ },
46
+ allowPositionals: true,
47
+ strict: false
48
+ });
49
+ const configPathFlag = typeof configFlag === "string" ? configFlag : void 0;
50
+ if (help) {
51
+ console.info(`\n${HELP}\n`);
52
+ return;
53
+ }
54
+ if (version$1) {
55
+ console.info(version);
56
+ return;
57
+ }
58
+ if (command === "init") {
59
+ const configPath = configPathFlag || "prismicCodegen.config.ts";
35
60
  if (existsSync(configPath)) console.info(`\n${configPath} already exists.`);
36
61
  else {
37
62
  let contents = "";
38
- if (existsSync("slicemachine.config.json") || existsSync("sm.json")) contents = stripIndent`
63
+ if (existsSync("slicemachine.config.json") || existsSync("sm.json")) contents = dedent`
39
64
  import type { Config } from "prismic-ts-codegen";
40
65
 
41
66
  const config: Config = {
@@ -45,7 +70,7 @@ const main = async () => {
45
70
 
46
71
  export default config;
47
72
  `;
48
- else contents = stripIndent`
73
+ else contents = dedent`
49
74
  import type { Config } from "prismic-ts-codegen";
50
75
 
51
76
  const config: Config = {
@@ -58,7 +83,7 @@ const main = async () => {
58
83
  console.info(`\nCreated prismic-ts-codegen config file: ${configPath}`);
59
84
  }
60
85
  } else {
61
- const unvalidatedConfig = loadConfig({ path: cli.flags.config });
86
+ const unvalidatedConfig = await loadConfig({ path: configPathFlag });
62
87
  const result = configSchema.safeParse(unvalidatedConfig);
63
88
  if (result.success) {
64
89
  const config = result.data;
@@ -104,5 +129,6 @@ main().catch((error) => {
104
129
  process.exit(1);
105
130
  });
106
131
  //#endregion
132
+ export {};
107
133
 
108
- //# sourceMappingURL=cli.js.map
134
+ //# sourceMappingURL=cli.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.mjs","names":["packageJson.description","version","packageJson.version","resolvePath"],"sources":["../src/cli/index.ts"],"sourcesContent":["import { existsSync, writeFileSync } from \"fs\";\nimport { parseArgs } from \"node:util\";\nimport { resolve as resolvePath } from \"path\";\n\nimport packageJson from \"../../package.json\" with { type: \"json\" };\nimport { detectTypesProvider, generateTypes } from \"../index\";\nimport { dedent } from \"../lib/dedent\";\nimport { configSchema } from \"./configSchema\";\nimport { NON_EDITABLE_FILE_HEADER } from \"./constants\";\nimport { loadConfig } from \"./loadConfig\";\nimport { loadLocaleIDs } from \"./loadLocaleIDs\";\nimport { loadModels } from \"./loadModels\";\n\nconst HELP = dedent`\n\t${packageJson.description}\n\n\tUsage:\n\t prismic-ts-codegen [options...]\n\t prismic-ts-codegen init [options...]\n\n\tCommands:\n\t init [options]\n\n\tOptions:\n\t -c, --config <path> Path to a prismic-ts-codegen configuration file.\n\t -h, --help Show this help.\n\t -v, --version Show the version.\n`;\n\nconst main = async () => {\n\tconst {\n\t\tpositionals: [command],\n\t\tvalues: { config: configFlag, help, version },\n\t} = parseArgs({\n\t\toptions: {\n\t\t\tconfig: { type: \"string\", short: \"c\" },\n\t\t\thelp: { type: \"boolean\", short: \"h\" },\n\t\t\tversion: { type: \"boolean\", short: \"v\" },\n\t\t},\n\t\tallowPositionals: true,\n\t\tstrict: false,\n\t});\n\tconst configPathFlag = typeof configFlag === \"string\" ? configFlag : undefined;\n\n\tif (help) {\n\t\tconsole.info(`\\n${HELP}\\n`);\n\t\treturn;\n\t}\n\n\tif (version) {\n\t\tconsole.info(packageJson.version);\n\t\treturn;\n\t}\n\n\tif (command === \"init\") {\n\t\tconst configPath = configPathFlag || \"prismicCodegen.config.ts\";\n\n\t\tif (existsSync(configPath)) {\n\t\t\tconsole.info(`\\n${configPath} already exists.`);\n\t\t} else {\n\t\t\tlet contents = \"\";\n\n\t\t\tif (existsSync(\"slicemachine.config.json\") || existsSync(\"sm.json\")) {\n\t\t\t\tcontents = dedent`\n\t\t\t\t\timport type { Config } from \"prismic-ts-codegen\";\n\n\t\t\t\t\tconst config: Config = {\n\t\t\t\t\t output: \"./types.generated.ts\",\n\t\t\t\t\t models: [\"./customtypes/**/index.json\", \"./slices/**/model.json\"],\n\t\t\t\t\t};\n\n\t\t\t\t\texport default config;\n\t\t\t\t`;\n\t\t\t} else {\n\t\t\t\tcontents = dedent`\n\t\t\t\t\timport type { Config } from \"prismic-ts-codegen\";\n\n\t\t\t\t\tconst config: Config = {\n\t\t\t\t\t output: \"./types.generated.ts\",\n\t\t\t\t\t};\n\n\t\t\t\t\texport default config;\n\t\t\t\t`;\n\t\t\t}\n\n\t\t\twriteFileSync(configPath, contents);\n\n\t\t\tconsole.info(`\\nCreated prismic-ts-codegen config file: ${configPath}`);\n\t\t}\n\t} else {\n\t\tconst unvalidatedConfig = await loadConfig({ path: configPathFlag });\n\n\t\tconst result = configSchema.safeParse(unvalidatedConfig);\n\n\t\tif (result.success) {\n\t\t\tconst config = result.data;\n\t\t\tconst { customTypeModels, sharedSliceModels } = await loadModels({\n\t\t\t\tlocalPaths: Array.isArray(config.models) ? config.models : config.models?.files,\n\t\t\t\trepositoryName: config.repositoryName,\n\t\t\t\tcustomTypesAPIToken: config.customTypesAPIToken,\n\t\t\t\tfetchFromRepository:\n\t\t\t\t\tconfig.models &&\n\t\t\t\t\t\"fetchFromRepository\" in config.models &&\n\t\t\t\t\tconfig.models.fetchFromRepository,\n\t\t\t});\n\n\t\t\tconst localeIDs = await loadLocaleIDs({\n\t\t\t\tlocaleIDs: Array.isArray(config.locales) ? config.locales : config.locales?.ids,\n\t\t\t\trepositoryName: config.repositoryName,\n\t\t\t\taccessToken: config.accessToken,\n\t\t\t\tfetchFromRepository:\n\t\t\t\t\tconfig.locales &&\n\t\t\t\t\t\"fetchFromRepository\" in config.locales &&\n\t\t\t\t\tconfig.locales.fetchFromRepository,\n\t\t\t});\n\n\t\t\tconst typesProvider = config.typesProvider || (await detectTypesProvider());\n\n\t\t\tconst hasCustomTypeModels = customTypeModels.length > 0;\n\n\t\t\tif (config.clientIntegration?.includeCreateClientInterface && !hasCustomTypeModels) {\n\t\t\t\tconsole.info(\n\t\t\t\t\t\"[INFO]: prismic-ts-codegen was configured to automatically integrate with `@prismicio/client`, but the integration was not generated because no Custom Type models were found. Automatic integration requires at least one Custom Type model.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst types = generateTypes({\n\t\t\t\tcustomTypeModels,\n\t\t\t\tsharedSliceModels,\n\t\t\t\tlocaleIDs,\n\t\t\t\tfieldConfigs: config.fields,\n\t\t\t\tclientIntegration: {\n\t\t\t\t\tincludeCreateClientInterface: hasCustomTypeModels\n\t\t\t\t\t\t? (config.clientIntegration?.includeCreateClientInterface ?? true)\n\t\t\t\t\t\t: false,\n\t\t\t\t\tincludeContentNamespace: config.clientIntegration?.includeContentNamespace ?? true,\n\t\t\t\t},\n\t\t\t\ttypesProvider,\n\t\t\t});\n\n\t\t\tconst fileContents = `${NON_EDITABLE_FILE_HEADER}\\n\\n${types}`;\n\n\t\t\tif (config.output) {\n\t\t\t\twriteFileSync(resolvePath(config.output), fileContents);\n\n\t\t\t\tconsole.info(`\\nGenerated types in: ${config.output}`);\n\t\t\t} else {\n\t\t\t\tprocess.stdout.write(types + \"\\n\");\n\t\t\t}\n\t\t} else {\n\t\t\tconsole.error(result.error.message);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n};\n\nmain().catch((error) => {\n\tconsole.error(error);\n\tprocess.exit(1);\n});\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAM,OAAO,MAAM;GAChBA,YAAwB;;;;;;;;;;;;;;AAe3B,MAAM,OAAO,YAAY;CACxB,MAAM,EACL,aAAa,CAAC,UACd,QAAQ,EAAE,QAAQ,YAAY,MAAM,SAAA,gBACjC,UAAU;EACb,SAAS;GACR,QAAQ;IAAE,MAAM;IAAU,OAAO;GAAI;GACrC,MAAM;IAAE,MAAM;IAAW,OAAO;GAAI;GACpC,SAAS;IAAE,MAAM;IAAW,OAAO;GAAI;EACxC;EACA,kBAAkB;EAClB,QAAQ;CACT,CAAC;CACD,MAAM,iBAAiB,OAAO,eAAe,WAAW,aAAa,KAAA;CAErE,IAAI,MAAM;EACT,QAAQ,KAAK,KAAK,KAAK,GAAG;EAC1B;CACD;CAEA,IAAIC,WAAS;EACZ,QAAQ,KAAKC,OAAmB;EAChC;CACD;CAEA,IAAI,YAAY,QAAQ;EACvB,MAAM,aAAa,kBAAkB;EAErC,IAAI,WAAW,UAAU,GACxB,QAAQ,KAAK,KAAK,WAAW,iBAAiB;OACxC;GACN,IAAI,WAAW;GAEf,IAAI,WAAW,0BAA0B,KAAK,WAAW,SAAS,GACjE,WAAW,MAAM;;;;;;;;;;QAWjB,WAAW,MAAM;;;;;;;;;GAWlB,cAAc,YAAY,QAAQ;GAElC,QAAQ,KAAK,6CAA6C,YAAY;EACvE;CACD,OAAO;EACN,MAAM,oBAAoB,MAAM,WAAW,EAAE,MAAM,eAAe,CAAC;EAEnE,MAAM,SAAS,aAAa,UAAU,iBAAiB;EAEvD,IAAI,OAAO,SAAS;GACnB,MAAM,SAAS,OAAO;GACtB,MAAM,EAAE,kBAAkB,sBAAsB,MAAM,WAAW;IAChE,YAAY,MAAM,QAAQ,OAAO,MAAM,IAAI,OAAO,SAAS,OAAO,QAAQ;IAC1E,gBAAgB,OAAO;IACvB,qBAAqB,OAAO;IAC5B,qBACC,OAAO,UACP,yBAAyB,OAAO,UAChC,OAAO,OAAO;GAChB,CAAC;GAED,MAAM,YAAY,MAAM,cAAc;IACrC,WAAW,MAAM,QAAQ,OAAO,OAAO,IAAI,OAAO,UAAU,OAAO,SAAS;IAC5E,gBAAgB,OAAO;IACvB,aAAa,OAAO;IACpB,qBACC,OAAO,WACP,yBAAyB,OAAO,WAChC,OAAO,QAAQ;GACjB,CAAC;GAED,MAAM,gBAAgB,OAAO,iBAAkB,MAAM,oBAAoB;GAEzE,MAAM,sBAAsB,iBAAiB,SAAS;GAEtD,IAAI,OAAO,mBAAmB,gCAAgC,CAAC,qBAC9D,QAAQ,KACP,+OACD;GAGD,MAAM,QAAQ,cAAc;IAC3B;IACA;IACA;IACA,cAAc,OAAO;IACrB,mBAAmB;KAClB,8BAA8B,sBAC1B,OAAO,mBAAmB,gCAAgC,OAC3D;KACH,yBAAyB,OAAO,mBAAmB,2BAA2B;IAC/E;IACA;GACD,CAAC;GAED,MAAM,eAAe,GAAG,yBAAyB,MAAM;GAEvD,IAAI,OAAO,QAAQ;IAClB,cAAcC,QAAY,OAAO,MAAM,GAAG,YAAY;IAEtD,QAAQ,KAAK,yBAAyB,OAAO,QAAQ;GACtD,OACC,QAAQ,OAAO,MAAM,QAAQ,IAAI;EAEnC,OAAO;GACN,QAAQ,MAAM,OAAO,MAAM,OAAO;GAClC,QAAQ,KAAK,CAAC;EACf;CACD;AACD;AAEA,KAAK,CAAC,CAAC,OAAO,UAAU;CACvB,QAAQ,MAAM,KAAK;CACnB,QAAQ,KAAK,CAAC;AACf,CAAC"}
@@ -28,4 +28,4 @@ const FIELD_DOCUMENTATION_URLS = {
28
28
  //#endregion
29
29
  export { CUSTOM_TYPES_DOCUMENTATION_URL, FIELD_DOCUMENTATION_URLS, SHARED_SLICES_DOCUMENTATION_URL };
30
30
 
31
- //# sourceMappingURL=constants.js.map
31
+ //# sourceMappingURL=constants.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.cjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import type { CustomTypeModelFieldType } from \"@prismicio/client\";\n\nexport const CUSTOM_TYPES_DOCUMENTATION_URL = \"https://prismic.io/docs/content-modeling\";\n\nexport const SHARED_SLICES_DOCUMENTATION_URL = \"https://prismic.io/docs/slices\";\n\nexport const FIELD_DOCUMENTATION_URLS = {\n\tUID: \"https://prismic.io/docs/fields/uid\",\n\tBoolean: \"https://prismic.io/docs/fields/boolean\",\n\tColor: \"https://prismic.io/docs/fields/color\",\n\tDate: \"https://prismic.io/docs/fields/date\",\n\tTimestamp: \"https://prismic.io/docs/fields/timestamp\",\n\tNumber: \"https://prismic.io/docs/fields/number\",\n\tText: \"https://prismic.io/docs/fields/text\",\n\tSelect: \"https://prismic.io/docs/fields/select\",\n\tStructuredText: \"https://prismic.io/docs/fields/rich-text\",\n\tImage: \"https://prismic.io/docs/fields/image\",\n\tLink: {\n\t\tcontentRelationship: \"https://prismic.io/docs/fields/content-relationship\",\n\t\tlink: \"https://prismic.io/docs/fields/link\",\n\t\tlinkToMedia: \"https://prismic.io/docs/fields/link-to-media\",\n\t},\n\tEmbed: \"https://prismic.io/docs/fields/embed\",\n\tGeoPoint: \"https://prismic.io/docs/fields/geopoint\",\n\tTable: \"https://prismic.io/docs/fields/table\",\n\tGroup: \"https://prismic.io/docs/fields/repeatable-group\",\n\tIntegrationFields: \"https://prismic.io/docs/fields/integration\",\n\tSlices: \"https://prismic.io/docs/slices\",\n\tChoice: \"https://prismic.io/docs/slices\",\n} satisfies Record<\n\tExclude<\n\t\t(typeof CustomTypeModelFieldType)[keyof typeof CustomTypeModelFieldType],\n\t\t\"Range\" | \"Separator\"\n\t>,\n\tstring | Record<string, string>\n>;\n"],"mappings":";AAEA,MAAa,iCAAiC;AAE9C,MAAa,kCAAkC;AAE/C,MAAa,2BAA2B;CACvC,KAAK;CACL,SAAS;CACT,OAAO;CACP,MAAM;CACN,WAAW;CACX,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,gBAAgB;CAChB,OAAO;CACP,MAAM;EACL,qBAAqB;EACrB,MAAM;EACN,aAAa;EACb;CACD,OAAO;CACP,UAAU;CACV,OAAO;CACP,OAAO;CACP,mBAAmB;CACnB,QAAQ;CACR,QAAQ;CACR"}
1
+ {"version":3,"file":"constants.mjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import type { CustomTypeModelFieldType } from \"@prismicio/client\";\n\nexport const CUSTOM_TYPES_DOCUMENTATION_URL = \"https://prismic.io/docs/content-modeling\";\n\nexport const SHARED_SLICES_DOCUMENTATION_URL = \"https://prismic.io/docs/slices\";\n\nexport const FIELD_DOCUMENTATION_URLS = {\n\tUID: \"https://prismic.io/docs/fields/uid\",\n\tBoolean: \"https://prismic.io/docs/fields/boolean\",\n\tColor: \"https://prismic.io/docs/fields/color\",\n\tDate: \"https://prismic.io/docs/fields/date\",\n\tTimestamp: \"https://prismic.io/docs/fields/timestamp\",\n\tNumber: \"https://prismic.io/docs/fields/number\",\n\tText: \"https://prismic.io/docs/fields/text\",\n\tSelect: \"https://prismic.io/docs/fields/select\",\n\tStructuredText: \"https://prismic.io/docs/fields/rich-text\",\n\tImage: \"https://prismic.io/docs/fields/image\",\n\tLink: {\n\t\tcontentRelationship: \"https://prismic.io/docs/fields/content-relationship\",\n\t\tlink: \"https://prismic.io/docs/fields/link\",\n\t\tlinkToMedia: \"https://prismic.io/docs/fields/link-to-media\",\n\t},\n\tEmbed: \"https://prismic.io/docs/fields/embed\",\n\tGeoPoint: \"https://prismic.io/docs/fields/geopoint\",\n\tTable: \"https://prismic.io/docs/fields/table\",\n\tGroup: \"https://prismic.io/docs/fields/repeatable-group\",\n\tIntegrationFields: \"https://prismic.io/docs/fields/integration\",\n\tSlices: \"https://prismic.io/docs/slices\",\n\tChoice: \"https://prismic.io/docs/slices\",\n} satisfies Record<\n\tExclude<\n\t\t(typeof CustomTypeModelFieldType)[keyof typeof CustomTypeModelFieldType],\n\t\t\"Range\" | \"Separator\"\n\t>,\n\tstring | Record<string, string>\n>;\n"],"mappings":";AAEA,MAAa,iCAAiC;AAE9C,MAAa,kCAAkC;AAE/C,MAAa,2BAA2B;CACvC,KAAK;CACL,SAAS;CACT,OAAO;CACP,MAAM;CACN,WAAW;CACX,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,gBAAgB;CAChB,OAAO;CACP,MAAM;EACL,qBAAqB;EACrB,MAAM;EACN,aAAa;CACd;CACA,OAAO;CACP,UAAU;CACV,OAAO;CACP,OAAO;CACP,mBAAmB;CACnB,QAAQ;CACR,QAAQ;AACT"}
@@ -0,0 +1,15 @@
1
+ import { TypesProvider } from "./generateTypes.mjs";
2
+ //#region src/detectTypesProvider.d.ts
3
+ export type DetectTypesProviderConfig = {
4
+ cwd?: string;
5
+ };
6
+ /**
7
+ * Detects which types provider should be used for a project.
8
+ *
9
+ * @param config - Configures the detection.
10
+ * @returns The types provider identifier to use, or `undefined` if on cannot be
11
+ * determined.
12
+ */
13
+ export declare const detectTypesProvider: (config?: DetectTypesProviderConfig) => Promise<TypesProvider | undefined>;
14
+ //#endregion
15
+ //# sourceMappingURL=detectTypesProvider.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detectTypesProvider.d.mts","names":[],"sources":["../src/detectTypesProvider.ts"],"mappings":";;YAIY;EACX;;;;;;;;;qBAUY,sBAAmB,SACvB,8BACN,QAAQ"}
@@ -21,4 +21,4 @@ const detectTypesProvider = async (config = {}) => {
21
21
  //#endregion
22
22
  export { detectTypesProvider };
23
23
 
24
- //# sourceMappingURL=detectTypesProvider.js.map
24
+ //# sourceMappingURL=detectTypesProvider.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"detectTypesProvider.cjs","names":[],"sources":["../src/detectTypesProvider.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nimport type { TypesProvider } from \"./generateTypes\";\n\nexport type DetectTypesProviderConfig = {\n\tcwd?: string;\n};\n\n/**\n * Detects which types provider should be used for a project.\n *\n * @param config - Configures the detection.\n * @returns The types provider identifier to use, or `undefined` if on cannot be\n * determined.\n */\nexport const detectTypesProvider = async (\n\tconfig: DetectTypesProviderConfig = {},\n): Promise<TypesProvider | undefined> => {\n\tconst cwd = config.cwd || process.cwd();\n\n\tconst require = createRequire(cwd.endsWith(\"/\") ? cwd : cwd + \"/\");\n\n\ttry {\n\t\tif (Number.parseInt(require(\"@prismicio/client/package.json\").version.split(\".\")[0]) >= 7) {\n\t\t\treturn \"@prismicio/client\";\n\t\t}\n\t} catch {\n\t\t// noop\n\t}\n\n\ttry {\n\t\trequire.resolve(\"@prismicio/types\");\n\n\t\treturn \"@prismicio/types\";\n\t} catch {\n\t\t// noop\n\t}\n};\n"],"mappings":";;;;;;;;;;AAeA,MAAa,sBAAsB,OAClC,SAAoC,EAAE,KACE;CACxC,MAAM,MAAM,OAAO,OAAO,QAAQ,KAAK;CAEvC,MAAM,WAAA,GAAA,YAAA,eAAwB,IAAI,SAAS,IAAI,GAAG,MAAM,MAAM,IAAI;AAElE,KAAI;AACH,MAAI,OAAO,SAAS,QAAQ,iCAAiC,CAAC,QAAQ,MAAM,IAAI,CAAC,GAAG,IAAI,EACvF,QAAO;SAED;AAIR,KAAI;AACH,UAAQ,QAAQ,mBAAmB;AAEnC,SAAO;SACA"}
1
+ {"version":3,"file":"detectTypesProvider.mjs","names":[],"sources":["../src/detectTypesProvider.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nimport type { TypesProvider } from \"./generateTypes\";\n\nexport type DetectTypesProviderConfig = {\n\tcwd?: string;\n};\n\n/**\n * Detects which types provider should be used for a project.\n *\n * @param config - Configures the detection.\n * @returns The types provider identifier to use, or `undefined` if on cannot be\n * determined.\n */\nexport const detectTypesProvider = async (\n\tconfig: DetectTypesProviderConfig = {},\n): Promise<TypesProvider | undefined> => {\n\tconst cwd = config.cwd || process.cwd();\n\n\tconst require = createRequire(cwd.endsWith(\"/\") ? cwd : cwd + \"/\");\n\n\ttry {\n\t\tif (Number.parseInt(require(\"@prismicio/client/package.json\").version.split(\".\")[0]) >= 7) {\n\t\t\treturn \"@prismicio/client\";\n\t\t}\n\t} catch {\n\t\t// noop\n\t}\n\n\ttry {\n\t\trequire.resolve(\"@prismicio/types\");\n\n\t\treturn \"@prismicio/types\";\n\t} catch {\n\t\t// noop\n\t}\n};\n"],"mappings":";;;;;;;;;AAeA,MAAa,sBAAsB,OAClC,SAAoC,CAAC,MACG;CACxC,MAAM,MAAM,OAAO,OAAO,QAAQ,IAAI;CAEtC,MAAM,UAAU,cAAc,IAAI,SAAS,GAAG,IAAI,MAAM,MAAM,GAAG;CAEjE,IAAI;EACH,IAAI,OAAO,SAAS,QAAQ,gCAAgC,CAAC,CAAC,QAAQ,MAAM,GAAG,CAAC,CAAC,EAAE,KAAK,GACvF,OAAO;CAET,QAAQ,CAER;CAEA,IAAI;EACH,QAAQ,QAAQ,kBAAkB;EAElC,OAAO;CACR,QAAQ,CAER;AACD"}
@@ -1,9 +1,8 @@
1
- import { FieldConfigs } from "./types.js";
1
+ import { FieldConfigs } from "./types.mjs";
2
2
  import { CustomTypeModel, SharedSliceModel } from "@prismicio/client";
3
-
4
3
  //#region src/generateTypes.d.ts
5
- type TypesProvider = "@prismicio/client" | "@prismicio/types";
6
- type GenerateTypesConfig = {
4
+ export type TypesProvider = "@prismicio/client" | "@prismicio/types";
5
+ export type GenerateTypesConfig = {
7
6
  customTypeModels?: CustomTypeModel[];
8
7
  sharedSliceModels?: SharedSliceModel[];
9
8
  localeIDs?: string[];
@@ -15,7 +14,6 @@ type GenerateTypesConfig = {
15
14
  };
16
15
  cache?: boolean;
17
16
  };
18
- declare function generateTypes(config?: GenerateTypesConfig): string;
17
+ export declare function generateTypes(config?: GenerateTypesConfig): string;
19
18
  //#endregion
20
- export { GenerateTypesConfig, TypesProvider, generateTypes };
21
- //# sourceMappingURL=generateTypes.d.ts.map
19
+ //# sourceMappingURL=generateTypes.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateTypes.d.mts","names":[],"sources":["../src/generateTypes.ts"],"mappings":";;;YAWY;YAIA;EACX,mBAAmB;EACnB,oBAAoB;EACpB;EACA,eAAe;EACf,gBAAgB;EAChB;IACC;IACA;;EAED;;wBAGe,cAAc,SAAQ"}
@@ -1,9 +1,9 @@
1
- import { addLine } from "./lib/addLine.js";
2
- import { addSection } from "./lib/addSection.js";
3
- import { buildUnion } from "./lib/buildUnion.js";
4
- import { buildCustomTypeType } from "./lib/buildCustomTypeType.js";
5
- import { buildSharedSliceType } from "./lib/buildSharedSliceType.js";
6
- import { source } from "common-tags";
1
+ import { addLine } from "./lib/addLine.mjs";
2
+ import { addSection } from "./lib/addSection.mjs";
3
+ import { buildUnion } from "./lib/buildUnion.mjs";
4
+ import { dedent } from "./lib/dedent.mjs";
5
+ import { buildCustomTypeType } from "./lib/buildCustomTypeType.mjs";
6
+ import { buildSharedSliceType } from "./lib/buildSharedSliceType.mjs";
7
7
  import QuickLRU from "quick-lru";
8
8
  //#region src/generateTypes.ts
9
9
  const cache = new QuickLRU({ maxSize: 1e3 });
@@ -83,7 +83,8 @@ type ContentRelationshipFieldWithData<
83
83
  }
84
84
  if (config.customTypeModels.length > 0) {
85
85
  const allDocumentTypesUnionName = "AllDocumentTypes";
86
- code = addSection(`export type ${allDocumentTypesUnionName} = ${buildUnion(allDocumentTypesTypeNames)};`, code);
86
+ const allDocumentTypesUnion = buildUnion(allDocumentTypesTypeNames);
87
+ code = addSection(`export type ${allDocumentTypesUnionName} = ${allDocumentTypesUnion};`, code);
87
88
  contentTypeNames.push(allDocumentTypesUnionName);
88
89
  }
89
90
  }
@@ -100,35 +101,37 @@ type ContentRelationshipFieldWithData<
100
101
  }
101
102
  if (config.clientIntegration?.includeCreateClientInterface || config.clientIntegration?.includeContentNamespace) {
102
103
  let clientModuleCode = "";
103
- if (config.clientIntegration.includeCreateClientInterface) if ((config.customTypeModels?.length || 0) > 0) {
104
- clientModuleCode = addSection(`interface CreateClient {
104
+ if (config.clientIntegration.includeCreateClientInterface) {
105
+ if ((config.customTypeModels?.length || 0) > 0) {
106
+ clientModuleCode = addSection(`interface CreateClient {
105
107
  (repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client<AllDocumentTypes>;
106
108
  }`, clientModuleCode);
107
- clientModuleCode = addSection(`interface CreateWriteClient {
109
+ clientModuleCode = addSection(`interface CreateWriteClient {
108
110
  (repositoryNameOrEndpoint: string, options: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient<AllDocumentTypes>;
109
111
  }`, clientModuleCode);
110
- clientModuleCode = addSection(`interface CreateMigration {
112
+ clientModuleCode = addSection(`interface CreateMigration {
111
113
  (): ${clientImportName}.Migration<AllDocumentTypes>;
112
114
  }`, clientModuleCode);
113
- } else {
114
- clientModuleCode = addSection(`interface CreateClient {
115
+ } else {
116
+ clientModuleCode = addSection(`interface CreateClient {
115
117
  (repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client;
116
118
  }`, clientModuleCode);
117
- clientModuleCode = addSection(`interface CreateWriteClient {
119
+ clientModuleCode = addSection(`interface CreateWriteClient {
118
120
  (repositoryNameOrEndpoint: string, options?: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient;
119
121
  }`, clientModuleCode);
120
- clientModuleCode = addSection(`interface CreateMigration {
122
+ clientModuleCode = addSection(`interface CreateMigration {
121
123
  (): ${clientImportName}.Migration;
122
124
  }`, clientModuleCode);
125
+ }
123
126
  }
124
- if (config.clientIntegration.includeContentNamespace) clientModuleCode = addSection(source`
127
+ if (config.clientIntegration.includeContentNamespace) clientModuleCode = addSection(dedent`
125
128
  namespace Content {
126
129
  export type {
127
130
  ${contentTypeNames.join(",\n")}
128
131
  }
129
132
  }
130
133
  `, clientModuleCode);
131
- code = addSection(source`
134
+ code = addSection(dedent`
132
135
  declare module "@prismicio/client" {
133
136
  ${clientModuleCode}
134
137
  }
@@ -139,4 +142,4 @@ type ContentRelationshipFieldWithData<
139
142
  //#endregion
140
143
  export { generateTypes };
141
144
 
142
- //# sourceMappingURL=generateTypes.js.map
145
+ //# sourceMappingURL=generateTypes.mjs.map