prismic-ts-codegen 0.1.30 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/configSchema.d.mts +2 -4
- package/dist/cli/configSchema.d.mts.map +1 -1
- package/dist/cli/configSchema.mjs +126 -2
- package/dist/cli/configSchema.mjs.map +1 -1
- package/dist/cli/constants.d.mts +1 -2
- package/dist/cli/constants.d.mts.map +1 -1
- package/dist/cli/loadConfig.mjs +7 -10
- package/dist/cli/loadConfig.mjs.map +1 -1
- package/dist/cli/loadLocaleIDs.mjs +0 -1
- package/dist/cli/loadLocaleIDs.mjs.map +1 -1
- package/dist/cli/loadModels.mjs +11 -10
- package/dist/cli/loadModels.mjs.map +1 -1
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +41 -16
- package/dist/cli.mjs.map +1 -1
- package/dist/constants.mjs.map +1 -1
- package/dist/detectTypesProvider.d.mts +2 -4
- package/dist/detectTypesProvider.d.mts.map +1 -1
- package/dist/detectTypesProvider.mjs.map +1 -1
- package/dist/generateTypes.d.mts +3 -5
- package/dist/generateTypes.d.mts.map +1 -1
- package/dist/generateTypes.mjs +15 -12
- package/dist/generateTypes.mjs.map +1 -1
- package/dist/lib/addBlankLine.mjs.map +1 -1
- package/dist/lib/addLine.mjs.map +1 -1
- package/dist/lib/addSection.mjs.map +1 -1
- package/dist/lib/addTrailingNewLine.mjs.map +1 -1
- package/dist/lib/buildCustomTypeDataType.mjs +2 -2
- package/dist/lib/buildCustomTypeDataType.mjs.map +1 -1
- package/dist/lib/buildCustomTypeType.mjs +2 -2
- package/dist/lib/buildCustomTypeType.mjs.map +1 -1
- package/dist/lib/buildFieldDocs.mjs +9 -4
- package/dist/lib/buildFieldDocs.mjs.map +1 -1
- package/dist/lib/buildFieldProperties.mjs +18 -14
- package/dist/lib/buildFieldProperties.mjs.map +1 -1
- package/dist/lib/buildSharedSliceType.mjs +10 -10
- package/dist/lib/buildSharedSliceType.mjs.map +1 -1
- package/dist/lib/buildTypeName.mjs +2 -2
- package/dist/lib/buildTypeName.mjs.map +1 -1
- package/dist/lib/buildUnion.mjs.map +1 -1
- package/dist/lib/checkHasUIDFIeld.mjs.map +1 -1
- package/dist/lib/dedent.mjs +11 -0
- package/dist/lib/dedent.mjs.map +1 -0
- package/dist/lib/getAPIIDPath.mjs.map +1 -1
- package/dist/lib/getCacheKey.mjs.map +1 -1
- package/dist/lib/getHumanReadableModelName.mjs.map +1 -1
- package/dist/lib/getHumanReadablePath.mjs.map +1 -1
- package/dist/package.mjs +7 -0
- package/dist/package.mjs.map +1 -0
- package/dist/types.d.mts +1 -3
- package/dist/types.d.mts.map +1 -1
- package/package.json +18 -25
- package/src/cli/index.ts +38 -22
- package/src/cli/loadConfig.ts +5 -11
- package/src/cli/loadLocaleIDs.ts +0 -1
- package/src/cli/loadModels.ts +27 -12
- package/src/generateTypes.ts +3 -3
- package/src/lib/buildCustomTypeDataType.ts +2 -2
- package/src/lib/buildCustomTypeType.ts +6 -6
- package/src/lib/buildFieldProperties.ts +7 -7
- package/src/lib/buildSharedSliceType.ts +22 -33
- package/src/lib/buildTypeName.ts +9 -4
- package/src/lib/dedent.ts +10 -0
|
@@ -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
37
|
//# sourceMappingURL=configSchema.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configSchema.d.mts","names":[],"sources":["../../src/cli/configSchema.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"configSchema.d.mts","names":[],"sources":["../../src/cli/configSchema.ts"],"mappings":";;;qBAGa,cAAY,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkLvB,EAAA,KAAA;;YAGU,SAAS,EAAE,aAAa"}
|
|
@@ -2,26 +2,150 @@ import { z } from "zod";
|
|
|
2
2
|
//#region src/cli/configSchema.ts
|
|
3
3
|
/** Configuration to control the generated types. */
|
|
4
4
|
const configSchema = z.object({
|
|
5
|
+
/** The name of the Prismic repository. */
|
|
5
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
|
+
*/
|
|
6
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
|
+
*/
|
|
7
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
|
+
*/
|
|
8
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
|
+
*/
|
|
9
28
|
typesProvider: z.enum(["@prismicio/client", "@prismicio/types"]).optional(),
|
|
29
|
+
/** Configuration for automatic `@prismicio/client` integration. */
|
|
10
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
|
+
*/
|
|
11
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
|
+
*/
|
|
12
61
|
includeContentNamespace: z.boolean().optional()
|
|
13
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
|
+
*/
|
|
14
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
|
+
*/
|
|
15
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
|
+
*/
|
|
16
97
|
fetchFromRepository: z.boolean().optional()
|
|
17
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
|
+
*/
|
|
18
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. */
|
|
19
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
|
+
*/
|
|
20
114
|
fetchFromRepository: z.boolean().optional()
|
|
21
115
|
})]).optional(),
|
|
116
|
+
/** Configuration for types generated for fields. */
|
|
22
117
|
fields: z.object({
|
|
23
|
-
|
|
24
|
-
|
|
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()
|
|
25
149
|
}).optional()
|
|
26
150
|
});
|
|
27
151
|
//#endregion
|
|
@@ -1 +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
|
|
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"}
|
package/dist/cli/constants.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
//#region src/cli/constants.d.ts
|
|
2
|
-
declare const NON_EDITABLE_FILE_HEADER = "// Code generated by prismic-ts-codegen. DO NOT EDIT.";
|
|
2
|
+
export declare const NON_EDITABLE_FILE_HEADER = "// Code generated by prismic-ts-codegen. DO NOT EDIT.";
|
|
3
3
|
//#endregion
|
|
4
|
-
export { NON_EDITABLE_FILE_HEADER };
|
|
5
4
|
//# sourceMappingURL=constants.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.mts","names":[],"sources":["../../src/cli/constants.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"constants.d.mts","names":[],"sources":["../../src/cli/constants.ts"],"mappings":";qBAAa"}
|
package/dist/cli/loadConfig.mjs
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { existsSync } from "fs";
|
|
2
2
|
import { resolve } from "path";
|
|
3
|
-
import
|
|
3
|
+
import { createJiti } from "jiti";
|
|
4
4
|
//#region src/cli/loadConfig.ts
|
|
5
|
-
const jiti =
|
|
6
|
-
const loadModuleWithJiti = (id) => {
|
|
7
|
-
const mod = jiti(id);
|
|
8
|
-
return typeof mod === "object" && mod !== null && "default" in mod ? mod.default : mod;
|
|
9
|
-
};
|
|
5
|
+
const jiti = createJiti(process.cwd());
|
|
10
6
|
const DEFAULT_CONFIG_PATHS = ["prismicCodegen.config.ts", "prismicCodegen.config.js"];
|
|
11
|
-
const loadConfig = (config) => {
|
|
12
|
-
if (config.path)
|
|
13
|
-
|
|
14
|
-
|
|
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 });
|
|
15
12
|
return {};
|
|
16
13
|
};
|
|
17
14
|
//#endregion
|
|
@@ -1 +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
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadLocaleIDs.mjs","names":[],"sources":["../../src/cli/loadLocaleIDs.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\
|
|
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"}
|
package/dist/cli/loadModels.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { readFileSync } from "fs";
|
|
2
|
-
import
|
|
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
|
|
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([
|
|
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
|
}
|
|
@@ -1 +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
|
|
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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {}
|
package/dist/cli.mjs
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
import { dedent } from "./lib/dedent.mjs";
|
|
1
2
|
import { generateTypes } from "./generateTypes.mjs";
|
|
2
3
|
import { detectTypesProvider } from "./detectTypesProvider.mjs";
|
|
3
4
|
import { NON_EDITABLE_FILE_HEADER } from "./cli/constants.mjs";
|
|
4
5
|
import "./index.mjs";
|
|
6
|
+
import { description, version } from "./package.mjs";
|
|
5
7
|
import { configSchema } from "./cli/configSchema.mjs";
|
|
6
8
|
import { loadConfig } from "./cli/loadConfig.mjs";
|
|
7
9
|
import { loadLocaleIDs } from "./cli/loadLocaleIDs.mjs";
|
|
8
10
|
import { loadModels } from "./cli/loadModels.mjs";
|
|
9
|
-
import { stripIndent } from "common-tags";
|
|
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
|
|
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
|
-
|
|
26
|
-
|
|
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
|
-
|
|
34
|
-
|
|
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 =
|
|
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 =
|
|
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:
|
|
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;
|
package/dist/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","names":["resolvePath"],"sources":["../src/cli/index.ts"],"sourcesContent":["import { existsSync, writeFileSync } from \"fs\";\nimport { resolve as resolvePath } from \"path\";\n\nimport
|
|
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"}
|
package/dist/constants.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { TypesProvider } from "./generateTypes.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/detectTypesProvider.d.ts
|
|
4
|
-
type DetectTypesProviderConfig = {
|
|
3
|
+
export type DetectTypesProviderConfig = {
|
|
5
4
|
cwd?: string;
|
|
6
5
|
};
|
|
7
6
|
/**
|
|
@@ -11,7 +10,6 @@ type DetectTypesProviderConfig = {
|
|
|
11
10
|
* @returns The types provider identifier to use, or `undefined` if on cannot be
|
|
12
11
|
* determined.
|
|
13
12
|
*/
|
|
14
|
-
declare const detectTypesProvider: (config?: DetectTypesProviderConfig) => Promise<TypesProvider | undefined>;
|
|
13
|
+
export declare const detectTypesProvider: (config?: DetectTypesProviderConfig) => Promise<TypesProvider | undefined>;
|
|
15
14
|
//#endregion
|
|
16
|
-
export { DetectTypesProviderConfig, detectTypesProvider };
|
|
17
15
|
//# sourceMappingURL=detectTypesProvider.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectTypesProvider.d.mts","names":[],"sources":["../src/detectTypesProvider.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"detectTypesProvider.d.mts","names":[],"sources":["../src/detectTypesProvider.ts"],"mappings":";;YAIY;EACX;;;;;;;;;qBAUY,sBAAmB,SACvB,8BACN,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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"}
|
package/dist/generateTypes.d.mts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
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
19
|
//# sourceMappingURL=generateTypes.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypes.d.mts","names":[],"sources":["../src/generateTypes.ts"],"mappings":"
|
|
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"}
|