prismic-ts-codegen 0.1.5 → 0.1.7

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 (175) hide show
  1. package/README.md +5 -5
  2. package/bin/prismic-ts-codegen.mjs +3 -0
  3. package/dist/cli/configSchema.cjs +38 -0
  4. package/dist/cli/configSchema.cjs.map +1 -0
  5. package/dist/cli/configSchema.d.ts +3 -0
  6. package/dist/cli/configSchema.js +38 -0
  7. package/dist/cli/configSchema.js.map +1 -0
  8. package/dist/cli/constants.cjs +5 -0
  9. package/dist/cli/constants.cjs.map +1 -0
  10. package/dist/cli/constants.d.ts +1 -0
  11. package/dist/cli/constants.js +5 -0
  12. package/dist/cli/constants.js.map +1 -0
  13. package/dist/cli/index.d.ts +1 -0
  14. package/dist/cli/loadConfig.cjs +32 -0
  15. package/dist/cli/loadConfig.cjs.map +1 -0
  16. package/dist/cli/loadConfig.d.ts +6 -0
  17. package/dist/cli/loadConfig.js +32 -0
  18. package/dist/cli/loadConfig.js.map +1 -0
  19. package/dist/cli/loadLocaleIDs.cjs +37 -0
  20. package/dist/cli/loadLocaleIDs.cjs.map +1 -0
  21. package/dist/cli/loadLocaleIDs.d.ts +10 -0
  22. package/dist/cli/loadLocaleIDs.js +20 -0
  23. package/dist/cli/loadLocaleIDs.js.map +1 -0
  24. package/dist/cli/loadModels.cjs +79 -0
  25. package/dist/cli/loadModels.cjs.map +1 -0
  26. package/dist/cli/loadModels.d.ts +15 -0
  27. package/dist/cli/loadModels.js +62 -0
  28. package/dist/cli/loadModels.js.map +1 -0
  29. package/dist/cli/types.d.ts +175 -0
  30. package/dist/cli.cjs +119 -0
  31. package/dist/cli.cjs.map +1 -0
  32. package/dist/cli.js +118 -0
  33. package/dist/cli.js.map +1 -0
  34. package/dist/constants.cjs +29 -0
  35. package/dist/constants.cjs.map +1 -0
  36. package/dist/constants.d.ts +5 -0
  37. package/dist/constants.js +29 -0
  38. package/dist/constants.js.map +1 -0
  39. package/dist/detectTypesProvider.cjs +16 -0
  40. package/dist/detectTypesProvider.cjs.map +1 -0
  41. package/dist/detectTypesProvider.d.ts +13 -0
  42. package/dist/detectTypesProvider.js +16 -0
  43. package/dist/detectTypesProvider.js.map +1 -0
  44. package/dist/generateTypes.cjs +109 -0
  45. package/dist/generateTypes.cjs.map +1 -0
  46. package/dist/generateTypes.d.ts +15 -0
  47. package/dist/generateTypes.js +109 -0
  48. package/dist/generateTypes.js.map +1 -0
  49. package/dist/index.cjs +6 -1086
  50. package/dist/index.cjs.map +1 -1
  51. package/dist/index.d.ts +5 -192
  52. package/dist/index.js +5 -1081
  53. package/dist/index.js.map +1 -1
  54. package/dist/lib/addInterfacePropertiesForFields.cjs +490 -0
  55. package/dist/lib/addInterfacePropertiesForFields.cjs.map +1 -0
  56. package/dist/lib/addInterfacePropertiesForFields.d.ts +21 -0
  57. package/dist/lib/addInterfacePropertiesForFields.js +490 -0
  58. package/dist/lib/addInterfacePropertiesForFields.js.map +1 -0
  59. package/dist/lib/addTypeAliasForCustomType.cjs +81 -0
  60. package/dist/lib/addTypeAliasForCustomType.cjs.map +1 -0
  61. package/dist/lib/addTypeAliasForCustomType.d.ts +11 -0
  62. package/dist/lib/addTypeAliasForCustomType.js +81 -0
  63. package/dist/lib/addTypeAliasForCustomType.js.map +1 -0
  64. package/dist/lib/addTypeAliasForSharedSlice.cjs +149 -0
  65. package/dist/lib/addTypeAliasForSharedSlice.cjs.map +1 -0
  66. package/dist/lib/addTypeAliasForSharedSlice.d.ts +10 -0
  67. package/dist/lib/addTypeAliasForSharedSlice.js +149 -0
  68. package/dist/lib/addTypeAliasForSharedSlice.js.map +1 -0
  69. package/dist/lib/buildFieldDocs.cjs +43 -0
  70. package/dist/lib/buildFieldDocs.cjs.map +1 -0
  71. package/dist/lib/buildFieldDocs.d.ts +14 -0
  72. package/dist/lib/buildFieldDocs.js +43 -0
  73. package/dist/lib/buildFieldDocs.js.map +1 -0
  74. package/dist/lib/buildSharedSliceInterfaceNamePart.cjs +8 -0
  75. package/dist/lib/buildSharedSliceInterfaceNamePart.cjs.map +1 -0
  76. package/dist/lib/buildSharedSliceInterfaceNamePart.d.ts +5 -0
  77. package/dist/lib/buildSharedSliceInterfaceNamePart.js +8 -0
  78. package/dist/lib/buildSharedSliceInterfaceNamePart.js.map +1 -0
  79. package/dist/lib/buildTypeName.cjs +12 -0
  80. package/dist/lib/buildTypeName.cjs.map +1 -0
  81. package/dist/lib/buildTypeName.d.ts +1 -0
  82. package/dist/lib/buildTypeName.js +12 -0
  83. package/dist/lib/buildTypeName.js.map +1 -0
  84. package/dist/lib/getAPIIDPath.cjs +23 -0
  85. package/dist/lib/getAPIIDPath.cjs.map +1 -0
  86. package/dist/lib/getAPIIDPath.d.ts +10 -0
  87. package/dist/lib/getAPIIDPath.js +23 -0
  88. package/dist/lib/getAPIIDPath.js.map +1 -0
  89. package/dist/lib/getFieldDocumentationURL.cjs +8 -0
  90. package/dist/lib/getFieldDocumentationURL.cjs.map +1 -0
  91. package/dist/lib/getFieldDocumentationURL.d.ts +6 -0
  92. package/dist/lib/getFieldDocumentationURL.js +8 -0
  93. package/dist/lib/getFieldDocumentationURL.js.map +1 -0
  94. package/dist/lib/getHumanReadableFieldPath.cjs +19 -0
  95. package/dist/lib/getHumanReadableFieldPath.cjs.map +1 -0
  96. package/dist/lib/getHumanReadableFieldPath.d.ts +10 -0
  97. package/dist/lib/getHumanReadableFieldPath.js +19 -0
  98. package/dist/lib/getHumanReadableFieldPath.js.map +1 -0
  99. package/dist/lib/getHumanReadableFieldType.cjs +37 -0
  100. package/dist/lib/getHumanReadableFieldType.cjs.map +1 -0
  101. package/dist/lib/getHumanReadableFieldType.d.ts +6 -0
  102. package/dist/lib/getHumanReadableFieldType.js +37 -0
  103. package/dist/lib/getHumanReadableFieldType.js.map +1 -0
  104. package/dist/lib/getHumanReadableModelName.cjs +24 -0
  105. package/dist/lib/getHumanReadableModelName.cjs.map +1 -0
  106. package/dist/lib/getHumanReadableModelName.d.ts +7 -0
  107. package/dist/lib/getHumanReadableModelName.js +24 -0
  108. package/dist/lib/getHumanReadableModelName.js.map +1 -0
  109. package/dist/lib/getSourceFileText.cjs +9 -0
  110. package/dist/lib/getSourceFileText.cjs.map +1 -0
  111. package/dist/lib/getSourceFileText.d.ts +2 -0
  112. package/dist/lib/getSourceFileText.js +9 -0
  113. package/dist/lib/getSourceFileText.js.map +1 -0
  114. package/dist/lib/hasOwnProperty.cjs +7 -0
  115. package/dist/lib/hasOwnProperty.cjs.map +1 -0
  116. package/dist/lib/hasOwnProperty.d.ts +10 -0
  117. package/dist/lib/hasOwnProperty.js +7 -0
  118. package/dist/lib/hasOwnProperty.js.map +1 -0
  119. package/dist/lib/isCustomTypeModel.cjs +7 -0
  120. package/dist/lib/isCustomTypeModel.cjs.map +1 -0
  121. package/dist/lib/isCustomTypeModel.d.ts +2 -0
  122. package/dist/lib/isCustomTypeModel.js +7 -0
  123. package/dist/lib/isCustomTypeModel.js.map +1 -0
  124. package/dist/lib/isCustomTypeModelField.cjs +7 -0
  125. package/dist/lib/isCustomTypeModelField.cjs.map +1 -0
  126. package/dist/lib/isCustomTypeModelField.d.ts +2 -0
  127. package/dist/lib/isCustomTypeModelField.js +7 -0
  128. package/dist/lib/isCustomTypeModelField.js.map +1 -0
  129. package/dist/lib/isCustomTypeModelSlice.cjs +9 -0
  130. package/dist/lib/isCustomTypeModelSlice.cjs.map +1 -0
  131. package/dist/lib/isCustomTypeModelSlice.d.ts +2 -0
  132. package/dist/lib/isCustomTypeModelSlice.js +9 -0
  133. package/dist/lib/isCustomTypeModelSlice.js.map +1 -0
  134. package/dist/lib/isSharedSliceModel.cjs +9 -0
  135. package/dist/lib/isSharedSliceModel.cjs.map +1 -0
  136. package/dist/lib/isSharedSliceModel.d.ts +2 -0
  137. package/dist/lib/isSharedSliceModel.js +9 -0
  138. package/dist/lib/isSharedSliceModel.js.map +1 -0
  139. package/dist/lib/pascalCase.cjs +8 -0
  140. package/dist/lib/pascalCase.cjs.map +1 -0
  141. package/dist/lib/pascalCase.d.ts +1 -0
  142. package/dist/lib/pascalCase.js +8 -0
  143. package/dist/lib/pascalCase.js.map +1 -0
  144. package/dist/lib/writeFieldDocsDescription.cjs +29 -0
  145. package/dist/lib/writeFieldDocsDescription.cjs.map +1 -0
  146. package/dist/lib/writeFieldDocsDescription.d.ts +13 -0
  147. package/dist/lib/writeFieldDocsDescription.js +29 -0
  148. package/dist/lib/writeFieldDocsDescription.js.map +1 -0
  149. package/dist/types.d.ts +14 -0
  150. package/package.json +45 -36
  151. package/src/cli/configSchema.ts +2 -0
  152. package/src/cli/index.ts +9 -5
  153. package/src/cli/loadConfig.ts +4 -2
  154. package/src/cli/loadModels.ts +3 -3
  155. package/src/cli/types.ts +10 -0
  156. package/src/constants.ts +6 -3
  157. package/src/detectTypesProvider.ts +32 -0
  158. package/src/generateTypes.ts +11 -6
  159. package/src/index.ts +4 -1
  160. package/src/lib/addInterfacePropertiesForFields.ts +31 -28
  161. package/src/lib/addTypeAliasForCustomType.ts +7 -5
  162. package/src/lib/addTypeAliasForSharedSlice.ts +5 -4
  163. package/src/lib/buildFieldDocs.ts +2 -1
  164. package/src/lib/getAPIIDPath.ts +3 -2
  165. package/src/lib/getFieldDocumentationURL.ts +1 -1
  166. package/src/lib/getHumanReadableFieldPath.ts +2 -1
  167. package/src/lib/getHumanReadableFieldType.ts +2 -2
  168. package/src/lib/getHumanReadableModelName.ts +1 -1
  169. package/src/lib/getSourceFileText.ts +1 -1
  170. package/src/lib/isCustomTypeModel.ts +1 -1
  171. package/src/lib/isCustomTypeModelField.ts +1 -1
  172. package/src/lib/isCustomTypeModelSlice.ts +1 -1
  173. package/src/lib/isSharedSliceModel.ts +1 -1
  174. package/src/types.ts +1 -1
  175. package/bin/cli.mjs +0 -1342
@@ -0,0 +1,175 @@
1
+ import { TypesProvider } from "../generateTypes";
2
+ /**
3
+ * Configuration to control the generated types.
4
+ */
5
+ export type Config = {
6
+ /**
7
+ * The name of the Prismic repository.
8
+ */
9
+ repositoryName?: string;
10
+ /**
11
+ * The access token for the Prismic repository. If the repository is private
12
+ * and `locales.fetchFromRepository` is `true`, providing a token is
13
+ * required.
14
+ */
15
+ accessToken?: string;
16
+ /**
17
+ * The Custom Types API token for the Prismic repository. If
18
+ * `models.fetchFromRepository` is `true`, providing a token is required.
19
+ */
20
+ customTypesAPIToken?: string;
21
+ /**
22
+ * The file path where the generated types will be saved. This path is
23
+ * relative to where the command is called.
24
+ */
25
+ output?: string;
26
+ /**
27
+ * The package that provides TypeScript types for Prismic data. Most projects
28
+ * will not need to configure this option.
29
+ *
30
+ * @defaultValue Automatically detected using the project's `package.json`.
31
+ */
32
+ typesProvider?: TypesProvider;
33
+ /**
34
+ * Configuration for automatic `@prismicio/client` integration.
35
+ */
36
+ clientIntegration?: {
37
+ /**
38
+ * Determines if a `@prismicio/client` integration with automatic typing
39
+ * should be included in the output.
40
+ *
41
+ * If set to `true`, Prismic clients will automatically be typed with the
42
+ * generated Custom Types and Slices.
43
+ *
44
+ * **Note**: If your project queries content from multiple Prismic
45
+ * repositories, set `includeCreateClientInterface` to `true` for the
46
+ * primary repository and `false` or any other repository. The generated
47
+ * `AllDocumentTypes` type for non-primary repositories can be provided to
48
+ * `@prismicio/client`'s `creatClient()` function as its only type parameter
49
+ * to type the client.
50
+ *
51
+ * @defaultValue `true`
52
+ */
53
+ includeCreateClientInterface?: boolean;
54
+ /**
55
+ * Determines if a `@prismicio/client` namespace named `Content` containing
56
+ * all Document and Slice types should be included in the output.
57
+ *
58
+ * If set to `true`, a `Content` namespace from `@prismicio/client` will be
59
+ * available to import to easily access types for your Prismic repository
60
+ * content.
61
+ *
62
+ * **Note**: If your project queries content from multiple Prismic
63
+ * repositories, set `includeContentNamespace` to `true` for the primary
64
+ * repository and `false` or any other repository. Types for non-primary
65
+ * repositories should be imported directly from the generated file rather
66
+ * than via the `Content` namespace.
67
+ *
68
+ * @defaultValue `true`
69
+ */
70
+ includeContentNamespace?: boolean;
71
+ };
72
+ /**
73
+ * Configuration for languages for the Prismic repository.
74
+ *
75
+ * It can be configured by providing an array of locale IDs configured for the
76
+ * repository or an object with finer control.
77
+ *
78
+ * @example
79
+ *
80
+ * ```ts
81
+ * ["en-us", "fr-fr"];
82
+ * ```
83
+ *
84
+ * @example
85
+ *
86
+ * ```ts
87
+ * {
88
+ * "ids": ["en-us", "fr-fr"],
89
+ * "fetchFromRepository": true
90
+ * }
91
+ * ```
92
+ */
93
+ locales?: string[] | {
94
+ /**
95
+ * A list of locales configured for the Prismic repository. This is used
96
+ * to type a document's `lang` property.
97
+ *
98
+ * @example
99
+ *
100
+ * ```ts
101
+ * ["en-us", "fr-fr"];
102
+ * ```
103
+ */
104
+ ids?: string[];
105
+ /**
106
+ * Determines if the Prismic repository's locales should be fetched from
107
+ * the repository's API.
108
+ */
109
+ fetchFromRepository?: boolean;
110
+ };
111
+ /**
112
+ * Configuration for Custom Type and Slice models for the Prismic repository.
113
+ *
114
+ * It can be configured by providing an array of file paths to Custom Type and
115
+ * Slice JSON models or an object with finer control.
116
+ */
117
+ models?: string[] | {
118
+ /**
119
+ * A list of file paths to Custom Type and Slice models. Globs are
120
+ * supported.
121
+ */
122
+ files?: string[];
123
+ /**
124
+ * Determines if the Prismic repository's Custom Type and Slice models
125
+ * should be fetched from the repository's API.
126
+ *
127
+ * `customTypesAPIToken` must be provided if set to `true`.
128
+ */
129
+ fetchFromRepository?: boolean;
130
+ };
131
+ /**
132
+ * Configuration for types generated for fields.
133
+ */
134
+ fields?: {
135
+ /**
136
+ * Configuration for Embed fields.
137
+ */
138
+ embed?: {
139
+ /**
140
+ * An object mapping oEmbed providers to their type. The type should be
141
+ * provided as a string and is added directly into the generated types.
142
+ *
143
+ * @example
144
+ *
145
+ * ```ts
146
+ * {
147
+ * "YouTube": "import('./types').OEmbedYouTube"
148
+ * "Twitter": "import('./types').OEmbedTwitter"
149
+ * "Vimeo": "import('./types').OEmbedVimeo"
150
+ * }
151
+ * ```
152
+ */
153
+ providerTypes?: Record<string, string>;
154
+ };
155
+ /**
156
+ * Configuration for Integration Fields.
157
+ */
158
+ integrationFields?: {
159
+ /**
160
+ * An object mapping catalog IDs to their type. The type should be
161
+ * provided as a string and is added directly into the generated types.
162
+ *
163
+ * @example
164
+ *
165
+ * ```ts
166
+ * {
167
+ * "shopify_products": "import('./types').IntegrationFieldShopifyProduct"
168
+ * "mux_videos": "import('./types').IntegrationFieldMuxVideo"
169
+ * }
170
+ * ```
171
+ */
172
+ catalogTypes?: Record<string, string>;
173
+ };
174
+ };
175
+ };
package/dist/cli.cjs ADDED
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ const commonTags = require("common-tags");
3
+ const fs = require("fs");
4
+ const meow = require("meow");
5
+ const path = require("path");
6
+ const generateTypes = require("./generateTypes.cjs");
7
+ const detectTypesProvider = require("./detectTypesProvider.cjs");
8
+ const configSchema = require("./cli/configSchema.cjs");
9
+ const constants = require("./cli/constants.cjs");
10
+ const loadConfig = require("./cli/loadConfig.cjs");
11
+ const loadLocaleIDs = require("./cli/loadLocaleIDs.cjs");
12
+ const loadModels = require("./cli/loadModels.cjs");
13
+ const cli = meow(`
14
+ Usage:
15
+ prismic-ts-codegen [options...]
16
+ prismic-ts-codegen init [options...]
17
+
18
+ Commands:
19
+ init [options]
20
+
21
+ Options:
22
+ -c, --config <path> Path to a prismic-ts-codegen configuration file.
23
+ `, {
24
+ importMeta: { url: typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : document.currentScript && document.currentScript.src || new URL("cli.cjs", document.baseURI).href },
25
+ flags: {
26
+ config: {
27
+ type: "string",
28
+ alias: "c",
29
+ isRequired: false
30
+ }
31
+ }
32
+ });
33
+ const main = async () => {
34
+ var _a, _b, _c, _d, _e;
35
+ if (cli.input[0] === "init") {
36
+ const configPath = cli.flags.config || "prismicCodegen.config.ts";
37
+ if (fs.existsSync(configPath)) {
38
+ console.info(`
39
+ ${configPath} already exists.`);
40
+ } else {
41
+ let contents = "";
42
+ if (fs.existsSync("sm.json")) {
43
+ contents = commonTags.stripIndent`
44
+ import type { Config } from "prismic-ts-codegen";
45
+
46
+ const config: Config = {
47
+ output: "./types.generated.ts",
48
+ models: ["./customtypes/**/index.json", "./slices/**/model.json"],
49
+ };
50
+
51
+ export default config;
52
+ `;
53
+ } else {
54
+ contents = commonTags.stripIndent`
55
+ import type { Config } from "prismic-ts-codegen";
56
+
57
+ const config: Config = {
58
+ output: "./types.generated.ts",
59
+ };
60
+
61
+ export default config;
62
+ `;
63
+ }
64
+ fs.writeFileSync(configPath, contents);
65
+ console.info(`
66
+ Created prismic-ts-codegen config file: ${configPath}`);
67
+ }
68
+ } else {
69
+ const unvalidatedConfig = loadConfig.loadConfig({ path: cli.flags.config });
70
+ const { value: config, error } = configSchema.configSchema.validate(unvalidatedConfig);
71
+ if (config && !error) {
72
+ const { customTypeModels, sharedSliceModels } = await loadModels.loadModels({
73
+ localPaths: Array.isArray(config.models) ? config.models : (_a = config.models) == null ? void 0 : _a.files,
74
+ repositoryName: config.repositoryName,
75
+ customTypesAPIToken: config.customTypesAPIToken,
76
+ fetchFromRepository: config.models && "fetchFromRepository" in config.models && config.models.fetchFromRepository
77
+ });
78
+ const localeIDs = await loadLocaleIDs.loadLocaleIDs({
79
+ localeIDs: Array.isArray(config.locales) ? config.locales : (_b = config.locales) == null ? void 0 : _b.ids,
80
+ repositoryName: config.repositoryName,
81
+ accessToken: config.accessToken,
82
+ fetchFromRepository: config.locales && "fetchFromRepository" in config.locales && config.locales.fetchFromRepository
83
+ });
84
+ const typesProvider = config.typesProvider || await detectTypesProvider.detectTypesProvider();
85
+ const hasCustomTypeModels = customTypeModels.length > 0;
86
+ if (((_c = config.clientIntegration) == null ? void 0 : _c.includeCreateClientInterface) && !hasCustomTypeModels) {
87
+ console.info("[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.");
88
+ }
89
+ const types = generateTypes.generateTypes({
90
+ customTypeModels,
91
+ sharedSliceModels,
92
+ localeIDs,
93
+ fieldConfigs: config.fields,
94
+ clientIntegration: {
95
+ includeCreateClientInterface: hasCustomTypeModels ? ((_d = config.clientIntegration) == null ? void 0 : _d.includeCreateClientInterface) ?? true : false,
96
+ includeContentNamespace: ((_e = config.clientIntegration) == null ? void 0 : _e.includeContentNamespace) ?? true
97
+ },
98
+ typesProvider
99
+ });
100
+ const fileContents = `${constants.NON_EDITABLE_FILE_HEADER}
101
+
102
+ ${types}`;
103
+ if (config.output) {
104
+ fs.writeFileSync(path.resolve(config.output), fileContents);
105
+ console.info(`
106
+ Generated types in: ${config.output}`);
107
+ } else {
108
+ process.stdout.write(types + "\n");
109
+ }
110
+ } else {
111
+ if (error) {
112
+ console.error(error.message);
113
+ return;
114
+ }
115
+ }
116
+ }
117
+ };
118
+ main().catch((error) => console.error(error));
119
+ //# sourceMappingURL=cli.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.cjs","sources":["../../src/cli/index.ts"],"sourcesContent":["import { stripIndent } from \"common-tags\";\nimport { existsSync, writeFileSync } from \"fs\";\nimport meow from \"meow\";\nimport { resolve as resolvePath } from \"path\";\n\nimport { detectTypesProvider, generateTypes } from \"../index\";\n\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 cli = meow(\n\t`\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`,\n\t{\n\t\timportMeta: import.meta,\n\t\tflags: {\n\t\t\tconfig: {\n\t\t\t\ttype: \"string\",\n\t\t\t\talias: \"c\",\n\t\t\t\tisRequired: false,\n\t\t\t},\n\t\t},\n\t},\n);\n\nconst main = async () => {\n\tif (cli.input[0] === \"init\") {\n\t\tconst configPath = cli.flags.config || \"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(\"sm.json\")) {\n\t\t\t\tcontents = stripIndent`\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 = stripIndent`\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 = loadConfig({ path: cli.flags.config });\n\n\t\tconst { value: config, error } = configSchema.validate(unvalidatedConfig);\n\n\t\tif (config && !error) {\n\t\t\tconst { customTypeModels, sharedSliceModels } = await loadModels({\n\t\t\t\tlocalPaths: Array.isArray(config.models)\n\t\t\t\t\t? config.models\n\t\t\t\t\t: 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)\n\t\t\t\t\t? config.locales\n\t\t\t\t\t: 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 =\n\t\t\t\tconfig.typesProvider || (await detectTypesProvider());\n\n\t\t\tconst hasCustomTypeModels = customTypeModels.length > 0;\n\n\t\t\tif (\n\t\t\t\tconfig.clientIntegration?.includeCreateClientInterface &&\n\t\t\t\t!hasCustomTypeModels\n\t\t\t) {\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:\n\t\t\t\t\t\tconfig.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\tif (error) {\n\t\t\t\tconsole.error(error.message);\n\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n};\n\nmain().catch((error) => console.error(error));\n"],"names":["existsSync","stripIndent","writeFileSync","loadConfig","configSchema","loadModels","loadLocaleIDs","detectTypesProvider","generateTypes","NON_EDITABLE_FILE_HEADER","resolvePath"],"mappings":"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"}
package/dist/cli.js ADDED
@@ -0,0 +1,118 @@
1
+ import { stripIndent } from "common-tags";
2
+ import { existsSync, writeFileSync } from "fs";
3
+ import meow from "meow";
4
+ import { resolve } from "path";
5
+ import { generateTypes } from "./generateTypes.js";
6
+ import { detectTypesProvider } from "./detectTypesProvider.js";
7
+ import { configSchema } from "./cli/configSchema.js";
8
+ import { NON_EDITABLE_FILE_HEADER } from "./cli/constants.js";
9
+ import { loadConfig } from "./cli/loadConfig.js";
10
+ import { loadLocaleIDs } from "./cli/loadLocaleIDs.js";
11
+ import { loadModels } from "./cli/loadModels.js";
12
+ const cli = meow(`
13
+ Usage:
14
+ prismic-ts-codegen [options...]
15
+ prismic-ts-codegen init [options...]
16
+
17
+ Commands:
18
+ init [options]
19
+
20
+ Options:
21
+ -c, --config <path> Path to a prismic-ts-codegen configuration file.
22
+ `, {
23
+ importMeta: import.meta,
24
+ flags: {
25
+ config: {
26
+ type: "string",
27
+ alias: "c",
28
+ isRequired: false
29
+ }
30
+ }
31
+ });
32
+ const main = async () => {
33
+ var _a, _b, _c, _d, _e;
34
+ if (cli.input[0] === "init") {
35
+ const configPath = cli.flags.config || "prismicCodegen.config.ts";
36
+ if (existsSync(configPath)) {
37
+ console.info(`
38
+ ${configPath} already exists.`);
39
+ } else {
40
+ let contents = "";
41
+ if (existsSync("sm.json")) {
42
+ contents = stripIndent`
43
+ import type { Config } from "prismic-ts-codegen";
44
+
45
+ const config: Config = {
46
+ output: "./types.generated.ts",
47
+ models: ["./customtypes/**/index.json", "./slices/**/model.json"],
48
+ };
49
+
50
+ export default config;
51
+ `;
52
+ } else {
53
+ contents = stripIndent`
54
+ import type { Config } from "prismic-ts-codegen";
55
+
56
+ const config: Config = {
57
+ output: "./types.generated.ts",
58
+ };
59
+
60
+ export default config;
61
+ `;
62
+ }
63
+ writeFileSync(configPath, contents);
64
+ console.info(`
65
+ Created prismic-ts-codegen config file: ${configPath}`);
66
+ }
67
+ } else {
68
+ const unvalidatedConfig = loadConfig({ path: cli.flags.config });
69
+ const { value: config, error } = configSchema.validate(unvalidatedConfig);
70
+ if (config && !error) {
71
+ const { customTypeModels, sharedSliceModels } = await loadModels({
72
+ localPaths: Array.isArray(config.models) ? config.models : (_a = config.models) == null ? void 0 : _a.files,
73
+ repositoryName: config.repositoryName,
74
+ customTypesAPIToken: config.customTypesAPIToken,
75
+ fetchFromRepository: config.models && "fetchFromRepository" in config.models && config.models.fetchFromRepository
76
+ });
77
+ const localeIDs = await loadLocaleIDs({
78
+ localeIDs: Array.isArray(config.locales) ? config.locales : (_b = config.locales) == null ? void 0 : _b.ids,
79
+ repositoryName: config.repositoryName,
80
+ accessToken: config.accessToken,
81
+ fetchFromRepository: config.locales && "fetchFromRepository" in config.locales && config.locales.fetchFromRepository
82
+ });
83
+ const typesProvider = config.typesProvider || await detectTypesProvider();
84
+ const hasCustomTypeModels = customTypeModels.length > 0;
85
+ if (((_c = config.clientIntegration) == null ? void 0 : _c.includeCreateClientInterface) && !hasCustomTypeModels) {
86
+ console.info("[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.");
87
+ }
88
+ const types = generateTypes({
89
+ customTypeModels,
90
+ sharedSliceModels,
91
+ localeIDs,
92
+ fieldConfigs: config.fields,
93
+ clientIntegration: {
94
+ includeCreateClientInterface: hasCustomTypeModels ? ((_d = config.clientIntegration) == null ? void 0 : _d.includeCreateClientInterface) ?? true : false,
95
+ includeContentNamespace: ((_e = config.clientIntegration) == null ? void 0 : _e.includeContentNamespace) ?? true
96
+ },
97
+ typesProvider
98
+ });
99
+ const fileContents = `${NON_EDITABLE_FILE_HEADER}
100
+
101
+ ${types}`;
102
+ if (config.output) {
103
+ writeFileSync(resolve(config.output), fileContents);
104
+ console.info(`
105
+ Generated types in: ${config.output}`);
106
+ } else {
107
+ process.stdout.write(types + "\n");
108
+ }
109
+ } else {
110
+ if (error) {
111
+ console.error(error.message);
112
+ return;
113
+ }
114
+ }
115
+ }
116
+ };
117
+ main().catch((error) => console.error(error));
118
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sources":["../../src/cli/index.ts"],"sourcesContent":["import { stripIndent } from \"common-tags\";\nimport { existsSync, writeFileSync } from \"fs\";\nimport meow from \"meow\";\nimport { resolve as resolvePath } from \"path\";\n\nimport { detectTypesProvider, generateTypes } from \"../index\";\n\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 cli = meow(\n\t`\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`,\n\t{\n\t\timportMeta: import.meta,\n\t\tflags: {\n\t\t\tconfig: {\n\t\t\t\ttype: \"string\",\n\t\t\t\talias: \"c\",\n\t\t\t\tisRequired: false,\n\t\t\t},\n\t\t},\n\t},\n);\n\nconst main = async () => {\n\tif (cli.input[0] === \"init\") {\n\t\tconst configPath = cli.flags.config || \"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(\"sm.json\")) {\n\t\t\t\tcontents = stripIndent`\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 = stripIndent`\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 = loadConfig({ path: cli.flags.config });\n\n\t\tconst { value: config, error } = configSchema.validate(unvalidatedConfig);\n\n\t\tif (config && !error) {\n\t\t\tconst { customTypeModels, sharedSliceModels } = await loadModels({\n\t\t\t\tlocalPaths: Array.isArray(config.models)\n\t\t\t\t\t? config.models\n\t\t\t\t\t: 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)\n\t\t\t\t\t? config.locales\n\t\t\t\t\t: 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 =\n\t\t\t\tconfig.typesProvider || (await detectTypesProvider());\n\n\t\t\tconst hasCustomTypeModels = customTypeModels.length > 0;\n\n\t\t\tif (\n\t\t\t\tconfig.clientIntegration?.includeCreateClientInterface &&\n\t\t\t\t!hasCustomTypeModels\n\t\t\t) {\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:\n\t\t\t\t\t\tconfig.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\tif (error) {\n\t\t\t\tconsole.error(error.message);\n\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n};\n\nmain().catch((error) => console.error(error));\n"],"names":["resolvePath"],"mappings":";;;;;;;;;;;AAaA,MAAM,MAAM,KACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWA;AAAA,EACC,YAAY;AAAA,EACZ,OAAO;AAAA,IACN,QAAQ;AAAA,MACP,MAAM;AAAA,MACN,OAAO;AAAA,MACP,YAAY;AAAA,IACZ;AAAA,EACD;AACD,CAAA;AAGF,MAAM,OAAO,YAAW;;AACvB,MAAI,IAAI,MAAM,CAAC,MAAM,QAAQ;AACtB,UAAA,aAAa,IAAI,MAAM,UAAU;AAEnC,QAAA,WAAW,UAAU,GAAG;AAC3B,cAAQ,KAAK;AAAA,EAAK,4BAA4B;AAAA,IAAA,OACxC;AACN,UAAI,WAAW;AAEX,UAAA,WAAW,SAAS,GAAG;AACf,mBAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAA,OAUL;AACK,mBAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MASX;AAED,oBAAc,YAAY,QAAQ;AAElC,cAAQ,KAAK;AAAA,0CAA6C,YAAY;AAAA,IACtE;AAAA,EAAA,OACK;AACN,UAAM,oBAAoB,WAAW,EAAE,MAAM,IAAI,MAAM,QAAQ;AAE/D,UAAM,EAAE,OAAO,QAAQ,MAAU,IAAA,aAAa,SAAS,iBAAiB;AAEpE,QAAA,UAAU,CAAC,OAAO;AACrB,YAAM,EAAE,kBAAkB,sBAAsB,MAAM,WAAW;AAAA,QAChE,YAAY,MAAM,QAAQ,OAAO,MAAM,IACpC,OAAO,UACP,YAAO,WAAP,mBAAe;AAAA,QAClB,gBAAgB,OAAO;AAAA,QACvB,qBAAqB,OAAO;AAAA,QAC5B,qBACC,OAAO,UACP,yBAAyB,OAAO,UAChC,OAAO,OAAO;AAAA,MAAA,CACf;AAEK,YAAA,YAAY,MAAM,cAAc;AAAA,QACrC,WAAW,MAAM,QAAQ,OAAO,OAAO,IACpC,OAAO,WACP,YAAO,YAAP,mBAAgB;AAAA,QACnB,gBAAgB,OAAO;AAAA,QACvB,aAAa,OAAO;AAAA,QACpB,qBACC,OAAO,WACP,yBAAyB,OAAO,WAChC,OAAO,QAAQ;AAAA,MAAA,CAChB;AAED,YAAM,gBACL,OAAO,iBAAkB,MAAM,oBAAqB;AAE/C,YAAA,sBAAsB,iBAAiB,SAAS;AAEtD,YACC,YAAO,sBAAP,mBAA0B,iCAC1B,CAAC,qBACA;AACD,gBAAQ,KACP,+OAA+O;AAAA,MAEhP;AAED,YAAM,QAAQ,cAAc;AAAA,QAC3B;AAAA,QACA;AAAA,QACA;AAAA,QACA,cAAc,OAAO;AAAA,QACrB,mBAAmB;AAAA,UAClB,8BAA8B,wBAC3B,YAAO,sBAAP,mBAA0B,iCAAgC,OAC1D;AAAA,UACH,2BACC,YAAO,sBAAP,mBAA0B,4BAA2B;AAAA,QACtD;AAAA,QACD;AAAA,MAAA,CACA;AAED,YAAM,eAAe,GAAG;AAAA;AAAA,EAA+B;AAEvD,UAAI,OAAO,QAAQ;AAClB,sBAAcA,QAAY,OAAO,MAAM,GAAG,YAAY;AAEtD,gBAAQ,KAAK;AAAA,sBAAyB,OAAO,QAAQ;AAAA,MAAA,OAC/C;AACE,gBAAA,OAAO,MAAM,QAAQ,IAAI;AAAA,MACjC;AAAA,IAAA,OACK;AACN,UAAI,OAAO;AACF,gBAAA,MAAM,MAAM,OAAO;AAE3B;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACF;AAEA,OAAO,MAAM,CAAC,UAAU,QAAQ,MAAM,KAAK,CAAC;"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const BLANK_LINE_IDENTIFIER = "// ___BLANK_LINE_TO_BE_REPLACED___";
4
+ const CUSTOM_TYPES_DOCUMENTATION_URL = "https://prismic.io/docs/core-concepts/custom-types";
5
+ const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/core-concepts/reusing-slices";
6
+ const FIELD_DOCUMENTATION_URLS = {
7
+ UID: "https://prismic.io/docs/core-concepts/uid",
8
+ Boolean: "https://prismic.io/docs/core-concepts/boolean",
9
+ Color: "https://prismic.io/docs/core-concepts/color",
10
+ Date: "https://prismic.io/docs/core-concepts/date",
11
+ Timestamp: "https://prismic.io/docs/core-concepts/timestamp",
12
+ Number: "https://prismic.io/docs/core-concepts/number",
13
+ Text: "https://prismic.io/docs/core-concepts/key-text",
14
+ Select: "https://prismic.io/docs/core-concepts/select",
15
+ StructuredText: "https://prismic.io/docs/core-concepts/rich-text-title",
16
+ Image: "https://prismic.io/docs/core-concepts/image",
17
+ Link: "https://prismic.io/docs/core-concepts/link-content-relationship",
18
+ Embed: "https://prismic.io/docs/core-concepts/embed",
19
+ GeoPoint: "https://prismic.io/docs/core-concepts/geopoint",
20
+ Group: "https://prismic.io/docs/core-concepts/group",
21
+ IntegrationFields: "https://prismic.io/docs/core-concepts/integration-fields",
22
+ Slices: "https://prismic.io/docs/core-concepts/slices",
23
+ Choice: "https://prismic.io/docs/core-concepts/slices"
24
+ };
25
+ exports.BLANK_LINE_IDENTIFIER = BLANK_LINE_IDENTIFIER;
26
+ exports.CUSTOM_TYPES_DOCUMENTATION_URL = CUSTOM_TYPES_DOCUMENTATION_URL;
27
+ exports.FIELD_DOCUMENTATION_URLS = FIELD_DOCUMENTATION_URLS;
28
+ exports.SHARED_SLICES_DOCUMENTATION_URL = SHARED_SLICES_DOCUMENTATION_URL;
29
+ //# sourceMappingURL=constants.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.cjs","sources":["../../src/constants.ts"],"sourcesContent":["import type { CustomTypeModelFieldType } from \"@prismicio/client\";\n\nexport const BLANK_LINE_IDENTIFIER = \"// ___BLANK_LINE_TO_BE_REPLACED___\";\n\nexport const CUSTOM_TYPES_DOCUMENTATION_URL =\n\t\"https://prismic.io/docs/core-concepts/custom-types\";\n\nexport const SHARED_SLICES_DOCUMENTATION_URL =\n\t\"https://prismic.io/docs/core-concepts/reusing-slices\";\n\nexport const FIELD_DOCUMENTATION_URLS: Record<\n\tExclude<\n\t\t(typeof CustomTypeModelFieldType)[keyof typeof CustomTypeModelFieldType],\n\t\t\"Range\" | \"Separator\"\n\t>,\n\tstring\n> = {\n\tUID: \"https://prismic.io/docs/core-concepts/uid\",\n\tBoolean: \"https://prismic.io/docs/core-concepts/boolean\",\n\tColor: \"https://prismic.io/docs/core-concepts/color\",\n\tDate: \"https://prismic.io/docs/core-concepts/date\",\n\tTimestamp: \"https://prismic.io/docs/core-concepts/timestamp\",\n\tNumber: \"https://prismic.io/docs/core-concepts/number\",\n\tText: \"https://prismic.io/docs/core-concepts/key-text\",\n\tSelect: \"https://prismic.io/docs/core-concepts/select\",\n\tStructuredText: \"https://prismic.io/docs/core-concepts/rich-text-title\",\n\tImage: \"https://prismic.io/docs/core-concepts/image\",\n\tLink: \"https://prismic.io/docs/core-concepts/link-content-relationship\",\n\tEmbed: \"https://prismic.io/docs/core-concepts/embed\",\n\tGeoPoint: \"https://prismic.io/docs/core-concepts/geopoint\",\n\tGroup: \"https://prismic.io/docs/core-concepts/group\",\n\tIntegrationFields: \"https://prismic.io/docs/core-concepts/integration-fields\",\n\tSlices: \"https://prismic.io/docs/core-concepts/slices\",\n\tChoice: \"https://prismic.io/docs/core-concepts/slices\",\n};\n"],"names":[],"mappings":";;AAEO,MAAM,wBAAwB;AAE9B,MAAM,iCACZ;AAEM,MAAM,kCACZ;AAEM,MAAM,2BAMT;AAAA,EACH,KAAK;AAAA,EACL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,gBAAgB;AAAA,EAChB,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,EACV,OAAO;AAAA,EACP,mBAAmB;AAAA,EACnB,QAAQ;AAAA,EACR,QAAQ;;;;;;"}
@@ -0,0 +1,5 @@
1
+ import type { CustomTypeModelFieldType } from "@prismicio/client";
2
+ export declare const BLANK_LINE_IDENTIFIER = "// ___BLANK_LINE_TO_BE_REPLACED___";
3
+ export declare const CUSTOM_TYPES_DOCUMENTATION_URL = "https://prismic.io/docs/core-concepts/custom-types";
4
+ export declare const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/core-concepts/reusing-slices";
5
+ export declare const FIELD_DOCUMENTATION_URLS: Record<Exclude<(typeof CustomTypeModelFieldType)[keyof typeof CustomTypeModelFieldType], "Range" | "Separator">, string>;
@@ -0,0 +1,29 @@
1
+ const BLANK_LINE_IDENTIFIER = "// ___BLANK_LINE_TO_BE_REPLACED___";
2
+ const CUSTOM_TYPES_DOCUMENTATION_URL = "https://prismic.io/docs/core-concepts/custom-types";
3
+ const SHARED_SLICES_DOCUMENTATION_URL = "https://prismic.io/docs/core-concepts/reusing-slices";
4
+ const FIELD_DOCUMENTATION_URLS = {
5
+ UID: "https://prismic.io/docs/core-concepts/uid",
6
+ Boolean: "https://prismic.io/docs/core-concepts/boolean",
7
+ Color: "https://prismic.io/docs/core-concepts/color",
8
+ Date: "https://prismic.io/docs/core-concepts/date",
9
+ Timestamp: "https://prismic.io/docs/core-concepts/timestamp",
10
+ Number: "https://prismic.io/docs/core-concepts/number",
11
+ Text: "https://prismic.io/docs/core-concepts/key-text",
12
+ Select: "https://prismic.io/docs/core-concepts/select",
13
+ StructuredText: "https://prismic.io/docs/core-concepts/rich-text-title",
14
+ Image: "https://prismic.io/docs/core-concepts/image",
15
+ Link: "https://prismic.io/docs/core-concepts/link-content-relationship",
16
+ Embed: "https://prismic.io/docs/core-concepts/embed",
17
+ GeoPoint: "https://prismic.io/docs/core-concepts/geopoint",
18
+ Group: "https://prismic.io/docs/core-concepts/group",
19
+ IntegrationFields: "https://prismic.io/docs/core-concepts/integration-fields",
20
+ Slices: "https://prismic.io/docs/core-concepts/slices",
21
+ Choice: "https://prismic.io/docs/core-concepts/slices"
22
+ };
23
+ export {
24
+ BLANK_LINE_IDENTIFIER,
25
+ CUSTOM_TYPES_DOCUMENTATION_URL,
26
+ FIELD_DOCUMENTATION_URLS,
27
+ SHARED_SLICES_DOCUMENTATION_URL
28
+ };
29
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["import type { CustomTypeModelFieldType } from \"@prismicio/client\";\n\nexport const BLANK_LINE_IDENTIFIER = \"// ___BLANK_LINE_TO_BE_REPLACED___\";\n\nexport const CUSTOM_TYPES_DOCUMENTATION_URL =\n\t\"https://prismic.io/docs/core-concepts/custom-types\";\n\nexport const SHARED_SLICES_DOCUMENTATION_URL =\n\t\"https://prismic.io/docs/core-concepts/reusing-slices\";\n\nexport const FIELD_DOCUMENTATION_URLS: Record<\n\tExclude<\n\t\t(typeof CustomTypeModelFieldType)[keyof typeof CustomTypeModelFieldType],\n\t\t\"Range\" | \"Separator\"\n\t>,\n\tstring\n> = {\n\tUID: \"https://prismic.io/docs/core-concepts/uid\",\n\tBoolean: \"https://prismic.io/docs/core-concepts/boolean\",\n\tColor: \"https://prismic.io/docs/core-concepts/color\",\n\tDate: \"https://prismic.io/docs/core-concepts/date\",\n\tTimestamp: \"https://prismic.io/docs/core-concepts/timestamp\",\n\tNumber: \"https://prismic.io/docs/core-concepts/number\",\n\tText: \"https://prismic.io/docs/core-concepts/key-text\",\n\tSelect: \"https://prismic.io/docs/core-concepts/select\",\n\tStructuredText: \"https://prismic.io/docs/core-concepts/rich-text-title\",\n\tImage: \"https://prismic.io/docs/core-concepts/image\",\n\tLink: \"https://prismic.io/docs/core-concepts/link-content-relationship\",\n\tEmbed: \"https://prismic.io/docs/core-concepts/embed\",\n\tGeoPoint: \"https://prismic.io/docs/core-concepts/geopoint\",\n\tGroup: \"https://prismic.io/docs/core-concepts/group\",\n\tIntegrationFields: \"https://prismic.io/docs/core-concepts/integration-fields\",\n\tSlices: \"https://prismic.io/docs/core-concepts/slices\",\n\tChoice: \"https://prismic.io/docs/core-concepts/slices\",\n};\n"],"names":[],"mappings":"AAEO,MAAM,wBAAwB;AAE9B,MAAM,iCACZ;AAEM,MAAM,kCACZ;AAEM,MAAM,2BAMT;AAAA,EACH,KAAK;AAAA,EACL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,gBAAgB;AAAA,EAChB,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,EACV,OAAO;AAAA,EACP,mBAAmB;AAAA,EACnB,QAAQ;AAAA,EACR,QAAQ;;"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const node_module = require("node:module");
4
+ const detectTypesProvider = async (config = {}) => {
5
+ const require2 = node_module.createRequire(config.cwd || process.cwd());
6
+ if (
7
+ // Only @prismicio/client >= v7 exports types.
8
+ Number.parseInt(require2("@prismicio/client/package.json").version.split(".")[0]) >= 7
9
+ ) {
10
+ return "@prismicio/client";
11
+ } else if (require2.resolve("@prismicio/types")) {
12
+ return "@prismicio/types";
13
+ }
14
+ };
15
+ exports.detectTypesProvider = detectTypesProvider;
16
+ //# sourceMappingURL=detectTypesProvider.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detectTypesProvider.cjs","sources":["../../src/detectTypesProvider.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nimport { 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 *\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 require = createRequire(config.cwd || process.cwd());\n\n\tif (\n\t\t// Only @prismicio/client >= v7 exports types.\n\t\tNumber.parseInt(\n\t\t\trequire(\"@prismicio/client/package.json\").version.split(\".\")[0],\n\t\t) >= 7\n\t) {\n\t\treturn \"@prismicio/client\";\n\t} else if (require.resolve(\"@prismicio/types\")) {\n\t\treturn \"@prismicio/types\";\n\t}\n};\n"],"names":["require","createRequire"],"mappings":";;;AAgBO,MAAM,sBAAsB,OAClC,SAAoC,OACG;AACvC,QAAMA,WAAUC,YAAAA,cAAc,OAAO,OAAO,QAAQ,KAAK;AAEzD;AAAA;AAAA,IAEC,OAAO,SACND,SAAQ,gCAAgC,EAAE,QAAQ,MAAM,GAAG,EAAE,CAAC,CAAC,KAC3D;AAAA,IACJ;AACM,WAAA;AAAA,EACG,WAAAA,SAAQ,QAAQ,kBAAkB,GAAG;AACxC,WAAA;AAAA,EACP;AACF;;"}
@@ -0,0 +1,13 @@
1
+ import { TypesProvider } from "./generateTypes";
2
+ export type DetectTypesProviderConfig = {
3
+ cwd?: string;
4
+ };
5
+ /**
6
+ * Detects which types provider should be used for a project.
7
+ *
8
+ * @param config - Configures the detection.
9
+ *
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>;
@@ -0,0 +1,16 @@
1
+ import { createRequire } from "node:module";
2
+ const detectTypesProvider = async (config = {}) => {
3
+ const require2 = createRequire(config.cwd || process.cwd());
4
+ if (
5
+ // Only @prismicio/client >= v7 exports types.
6
+ Number.parseInt(require2("@prismicio/client/package.json").version.split(".")[0]) >= 7
7
+ ) {
8
+ return "@prismicio/client";
9
+ } else if (require2.resolve("@prismicio/types")) {
10
+ return "@prismicio/types";
11
+ }
12
+ };
13
+ export {
14
+ detectTypesProvider
15
+ };
16
+ //# sourceMappingURL=detectTypesProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detectTypesProvider.js","sources":["../../src/detectTypesProvider.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nimport { 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 *\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 require = createRequire(config.cwd || process.cwd());\n\n\tif (\n\t\t// Only @prismicio/client >= v7 exports types.\n\t\tNumber.parseInt(\n\t\t\trequire(\"@prismicio/client/package.json\").version.split(\".\")[0],\n\t\t) >= 7\n\t) {\n\t\treturn \"@prismicio/client\";\n\t} else if (require.resolve(\"@prismicio/types\")) {\n\t\treturn \"@prismicio/types\";\n\t}\n};\n"],"names":["require"],"mappings":";AAgBO,MAAM,sBAAsB,OAClC,SAAoC,OACG;AACvC,QAAMA,WAAU,cAAc,OAAO,OAAO,QAAQ,KAAK;AAEzD;AAAA;AAAA,IAEC,OAAO,SACNA,SAAQ,gCAAgC,EAAE,QAAQ,MAAM,GAAG,EAAE,CAAC,CAAC,KAC3D;AAAA,IACJ;AACM,WAAA;AAAA,EACG,WAAAA,SAAQ,QAAQ,kBAAkB,GAAG;AACxC,WAAA;AAAA,EACP;AACF;"}