prismic-ts-codegen 0.1.29 → 0.1.30-pr.82.96148f3
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/bin/prismic-ts-codegen.js +1 -1
- package/dist/cli/{configSchema.d.ts → configSchema.d.mts} +3 -5
- package/dist/cli/configSchema.d.mts.map +1 -0
- package/dist/cli/configSchema.mjs +154 -0
- package/dist/cli/configSchema.mjs.map +1 -0
- package/dist/cli/constants.d.mts +4 -0
- package/dist/cli/constants.d.mts.map +1 -0
- package/dist/cli/{constants.js → constants.mjs} +1 -1
- package/dist/cli/{constants.cjs.map → constants.mjs.map} +1 -1
- package/dist/cli/loadConfig.mjs +20 -0
- package/dist/cli/loadConfig.mjs.map +1 -0
- package/dist/cli/{loadLocaleIDs.js → loadLocaleIDs.mjs} +1 -2
- package/dist/cli/loadLocaleIDs.mjs.map +1 -0
- package/dist/cli/{loadModels.js → loadModels.mjs} +14 -11
- package/dist/cli/loadModels.mjs.map +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/{cli.js → cli.mjs} +51 -25
- package/dist/cli.mjs.map +1 -0
- package/dist/{constants.js → constants.mjs} +1 -1
- package/dist/{constants.cjs.map → constants.mjs.map} +1 -1
- package/dist/detectTypesProvider.d.mts +15 -0
- package/dist/detectTypesProvider.d.mts.map +1 -0
- package/dist/{detectTypesProvider.js → detectTypesProvider.mjs} +1 -1
- package/dist/{detectTypesProvider.cjs.map → detectTypesProvider.mjs.map} +1 -1
- package/dist/{generateTypes.d.ts → generateTypes.d.mts} +5 -7
- package/dist/generateTypes.d.mts.map +1 -0
- package/dist/{generateTypes.js → generateTypes.mjs} +21 -18
- package/dist/generateTypes.mjs.map +1 -0
- package/dist/{index.d.cts → index.d.mts} +4 -4
- package/dist/index.mjs +4 -0
- package/dist/lib/{addBlankLine.js → addBlankLine.mjs} +2 -2
- package/dist/lib/addBlankLine.mjs.map +1 -0
- package/dist/lib/{addLine.js → addLine.mjs} +2 -2
- package/dist/lib/addLine.mjs.map +1 -0
- package/dist/lib/{addSection.js → addSection.mjs} +2 -2
- package/dist/lib/addSection.mjs.map +1 -0
- package/dist/lib/{addTrailingNewLine.js → addTrailingNewLine.mjs} +1 -1
- package/dist/lib/{addTrailingNewLine.cjs.map → addTrailingNewLine.mjs.map} +1 -1
- package/dist/lib/{buildCustomTypeDataType.js → buildCustomTypeDataType.mjs} +6 -6
- package/dist/lib/buildCustomTypeDataType.mjs.map +1 -0
- package/dist/lib/{buildCustomTypeType.js → buildCustomTypeType.mjs} +11 -11
- package/dist/lib/buildCustomTypeType.mjs.map +1 -0
- package/dist/lib/{buildFieldDocs.js → buildFieldDocs.mjs} +15 -10
- package/dist/lib/buildFieldDocs.mjs.map +1 -0
- package/dist/lib/{buildFieldProperties.js → buildFieldProperties.mjs} +25 -21
- package/dist/lib/buildFieldProperties.mjs.map +1 -0
- package/dist/lib/{buildSharedSliceType.js → buildSharedSliceType.mjs} +19 -19
- package/dist/lib/buildSharedSliceType.mjs.map +1 -0
- package/dist/lib/buildTypeName.mjs +11 -0
- package/dist/lib/buildTypeName.mjs.map +1 -0
- package/dist/lib/{buildUnion.js → buildUnion.mjs} +1 -1
- package/dist/lib/{buildUnion.cjs.map → buildUnion.mjs.map} +1 -1
- package/dist/lib/{checkHasUIDFIeld.js → checkHasUIDFIeld.mjs} +1 -1
- package/dist/lib/{checkHasUIDFIeld.cjs.map → checkHasUIDFIeld.mjs.map} +1 -1
- package/dist/lib/dedent.mjs +12 -0
- package/dist/lib/dedent.mjs.map +1 -0
- package/dist/lib/{getAPIIDPath.js → getAPIIDPath.mjs} +1 -1
- package/dist/lib/{getAPIIDPath.cjs.map → getAPIIDPath.mjs.map} +1 -1
- package/dist/lib/{getCacheKey.js → getCacheKey.mjs} +1 -1
- package/dist/lib/getCacheKey.mjs.map +1 -0
- package/dist/lib/{getHumanReadableModelName.js → getHumanReadableModelName.mjs} +1 -1
- package/dist/lib/{getHumanReadableModelName.cjs.map → getHumanReadableModelName.mjs.map} +1 -1
- package/dist/lib/{getHumanReadablePath.js → getHumanReadablePath.mjs} +2 -2
- package/dist/lib/getHumanReadablePath.mjs.map +1 -0
- package/dist/package.mjs +7 -0
- package/dist/package.mjs.map +1 -0
- package/dist/{types.d.ts → types.d.mts} +2 -4
- package/dist/types.d.mts.map +1 -0
- package/package.json +19 -29
- package/src/cli/index.ts +38 -22
- package/src/cli/loadConfig.ts +7 -9
- package/src/cli/loadLocaleIDs.ts +0 -1
- package/src/cli/loadModels.ts +30 -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 +14 -0
- package/dist/_virtual/_rolldown/runtime.cjs +0 -23
- package/dist/cli/configSchema.cjs +0 -31
- package/dist/cli/configSchema.cjs.map +0 -1
- package/dist/cli/configSchema.d.cts +0 -39
- package/dist/cli/configSchema.d.cts.map +0 -1
- package/dist/cli/configSchema.d.ts.map +0 -1
- package/dist/cli/configSchema.js +0 -30
- package/dist/cli/configSchema.js.map +0 -1
- package/dist/cli/constants.cjs +0 -6
- package/dist/cli/constants.d.cts +0 -5
- package/dist/cli/constants.d.cts.map +0 -1
- package/dist/cli/constants.d.ts +0 -5
- package/dist/cli/constants.d.ts.map +0 -1
- package/dist/cli/constants.js.map +0 -1
- package/dist/cli/loadConfig.cjs +0 -22
- package/dist/cli/loadConfig.cjs.map +0 -1
- package/dist/cli/loadConfig.js +0 -20
- package/dist/cli/loadConfig.js.map +0 -1
- package/dist/cli/loadLocaleIDs.cjs +0 -21
- package/dist/cli/loadLocaleIDs.cjs.map +0 -1
- package/dist/cli/loadLocaleIDs.js.map +0 -1
- package/dist/cli/loadModels.cjs +0 -54
- package/dist/cli/loadModels.cjs.map +0 -1
- package/dist/cli/loadModels.js.map +0 -1
- package/dist/cli.cjs +0 -110
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.d.cts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/constants.cjs +0 -33
- package/dist/constants.js.map +0 -1
- package/dist/detectTypesProvider.cjs +0 -25
- package/dist/detectTypesProvider.d.cts +0 -17
- package/dist/detectTypesProvider.d.cts.map +0 -1
- package/dist/detectTypesProvider.d.ts +0 -17
- package/dist/detectTypesProvider.d.ts.map +0 -1
- package/dist/detectTypesProvider.js.map +0 -1
- package/dist/generateTypes.cjs +0 -144
- package/dist/generateTypes.cjs.map +0 -1
- package/dist/generateTypes.d.cts +0 -21
- package/dist/generateTypes.d.cts.map +0 -1
- package/dist/generateTypes.d.ts.map +0 -1
- package/dist/generateTypes.js.map +0 -1
- package/dist/index.cjs +0 -7
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -4
- package/dist/lib/addBlankLine.cjs +0 -10
- package/dist/lib/addBlankLine.cjs.map +0 -1
- package/dist/lib/addBlankLine.js.map +0 -1
- package/dist/lib/addLine.cjs +0 -9
- package/dist/lib/addLine.cjs.map +0 -1
- package/dist/lib/addLine.js.map +0 -1
- package/dist/lib/addSection.cjs +0 -9
- package/dist/lib/addSection.cjs.map +0 -1
- package/dist/lib/addSection.js.map +0 -1
- package/dist/lib/addTrailingNewLine.cjs +0 -9
- package/dist/lib/addTrailingNewLine.js.map +0 -1
- package/dist/lib/buildCustomTypeDataType.cjs +0 -51
- package/dist/lib/buildCustomTypeDataType.cjs.map +0 -1
- package/dist/lib/buildCustomTypeDataType.js.map +0 -1
- package/dist/lib/buildCustomTypeType.cjs +0 -63
- package/dist/lib/buildCustomTypeType.cjs.map +0 -1
- package/dist/lib/buildCustomTypeType.js.map +0 -1
- package/dist/lib/buildFieldDocs.cjs +0 -66
- package/dist/lib/buildFieldDocs.cjs.map +0 -1
- package/dist/lib/buildFieldDocs.js.map +0 -1
- package/dist/lib/buildFieldProperties.cjs +0 -285
- package/dist/lib/buildFieldProperties.cjs.map +0 -1
- package/dist/lib/buildFieldProperties.js.map +0 -1
- package/dist/lib/buildSharedSliceType.cjs +0 -152
- package/dist/lib/buildSharedSliceType.cjs.map +0 -1
- package/dist/lib/buildSharedSliceType.js.map +0 -1
- package/dist/lib/buildTypeName.cjs +0 -12
- package/dist/lib/buildTypeName.cjs.map +0 -1
- package/dist/lib/buildTypeName.js +0 -11
- package/dist/lib/buildTypeName.js.map +0 -1
- package/dist/lib/buildUnion.cjs +0 -8
- package/dist/lib/buildUnion.js.map +0 -1
- package/dist/lib/checkHasUIDFIeld.cjs +0 -8
- package/dist/lib/checkHasUIDFIeld.js.map +0 -1
- package/dist/lib/getAPIIDPath.cjs +0 -24
- package/dist/lib/getAPIIDPath.js.map +0 -1
- package/dist/lib/getCacheKey.cjs +0 -17
- package/dist/lib/getCacheKey.cjs.map +0 -1
- package/dist/lib/getCacheKey.js.map +0 -1
- package/dist/lib/getHumanReadableModelName.cjs +0 -15
- package/dist/lib/getHumanReadableModelName.js.map +0 -1
- package/dist/lib/getHumanReadablePath.cjs +0 -16
- package/dist/lib/getHumanReadablePath.cjs.map +0 -1
- package/dist/lib/getHumanReadablePath.js.map +0 -1
- package/dist/types.d.cts +0 -14
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.ts.map +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { SharedSliceModel } from "@prismicio/client";
|
|
2
|
-
import { source, stripIndent } from "common-tags";
|
|
3
2
|
import type QuickLRU from "quick-lru";
|
|
4
3
|
|
|
5
4
|
import { SHARED_SLICES_DOCUMENTATION_URL } from "../constants";
|
|
@@ -8,6 +7,7 @@ import { addSection } from "./addSection";
|
|
|
8
7
|
import { buildFieldProperties } from "./buildFieldProperties";
|
|
9
8
|
import { buildTypeName } from "./buildTypeName";
|
|
10
9
|
import { buildUnion } from "./buildUnion";
|
|
10
|
+
import { dedent } from "./dedent";
|
|
11
11
|
import { getCacheKey } from "./getCacheKey";
|
|
12
12
|
import { getHumanReadableModelName } from "./getHumanReadableModelName";
|
|
13
13
|
import { getHumanReadablePath } from "./getHumanReadablePath";
|
|
@@ -27,7 +27,7 @@ type BuildSharedSliceTypeReturnValue = {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
export function buildSharedSliceType(
|
|
30
|
-
args: BuildSharedSliceTypeArgs
|
|
30
|
+
args: BuildSharedSliceTypeArgs,
|
|
31
31
|
): BuildSharedSliceTypeReturnValue {
|
|
32
32
|
if (args.cache) {
|
|
33
33
|
const key = getCacheKey([args.model, args.fieldConfigs]);
|
|
@@ -54,10 +54,7 @@ export function buildSharedSliceType(
|
|
|
54
54
|
const variationName = buildTypeName(name, variationModel.id);
|
|
55
55
|
|
|
56
56
|
let primaryInterfaceName: string | undefined;
|
|
57
|
-
if (
|
|
58
|
-
variationModel.primary &&
|
|
59
|
-
Object.keys(variationModel.primary).length > 0
|
|
60
|
-
) {
|
|
57
|
+
if (variationModel.primary && Object.keys(variationModel.primary).length > 0) {
|
|
61
58
|
primaryInterfaceName = buildTypeName(variationName, "Primary");
|
|
62
59
|
|
|
63
60
|
const path: FieldPath = [
|
|
@@ -86,7 +83,7 @@ export function buildSharedSliceType(
|
|
|
86
83
|
|
|
87
84
|
contentTypeNames.push(primaryInterfaceName);
|
|
88
85
|
|
|
89
|
-
const docs =
|
|
86
|
+
const docs = dedent`
|
|
90
87
|
/**
|
|
91
88
|
* Primary content in *${humanReadablePath}*
|
|
92
89
|
*/
|
|
@@ -94,17 +91,17 @@ export function buildSharedSliceType(
|
|
|
94
91
|
|
|
95
92
|
code = addSection(
|
|
96
93
|
primaryFieldProperties.code
|
|
97
|
-
?
|
|
94
|
+
? dedent`
|
|
98
95
|
${docs}
|
|
99
96
|
export interface ${primaryInterfaceName} {
|
|
100
97
|
${primaryFieldProperties.code}
|
|
101
98
|
}
|
|
102
99
|
`
|
|
103
|
-
:
|
|
100
|
+
: dedent`
|
|
104
101
|
${docs}
|
|
105
102
|
export interface ${primaryInterfaceName} {}
|
|
106
103
|
`,
|
|
107
|
-
code
|
|
104
|
+
code,
|
|
108
105
|
);
|
|
109
106
|
}
|
|
110
107
|
|
|
@@ -134,7 +131,7 @@ export function buildSharedSliceType(
|
|
|
134
131
|
|
|
135
132
|
contentTypeNames.push(itemInterfaceName);
|
|
136
133
|
|
|
137
|
-
const docs =
|
|
134
|
+
const docs = dedent`
|
|
138
135
|
/**
|
|
139
136
|
* Primary content in *${humanReadablePath}*
|
|
140
137
|
*/
|
|
@@ -142,22 +139,22 @@ export function buildSharedSliceType(
|
|
|
142
139
|
|
|
143
140
|
code = addSection(
|
|
144
141
|
itemFieldProperties.code
|
|
145
|
-
?
|
|
142
|
+
? dedent`
|
|
146
143
|
${docs}
|
|
147
144
|
export interface ${itemInterfaceName} {
|
|
148
145
|
${itemFieldProperties.code}
|
|
149
146
|
}
|
|
150
147
|
`
|
|
151
|
-
:
|
|
148
|
+
: dedent`
|
|
152
149
|
${docs}
|
|
153
150
|
export interface ${itemInterfaceName} {}
|
|
154
151
|
`,
|
|
155
|
-
code
|
|
152
|
+
code,
|
|
156
153
|
);
|
|
157
154
|
}
|
|
158
155
|
|
|
159
156
|
code = addSection(
|
|
160
|
-
|
|
157
|
+
dedent`
|
|
161
158
|
/**
|
|
162
159
|
* ${variationModel.name} variation for ${humanReadableName} Slice
|
|
163
160
|
*
|
|
@@ -165,15 +162,11 @@ export function buildSharedSliceType(
|
|
|
165
162
|
* - **Description**: ${variationModel.description || "*None*"}
|
|
166
163
|
* - **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}
|
|
167
164
|
*/
|
|
168
|
-
export type ${variationName} = prismic.SharedSliceVariation<"${
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
primaryInterfaceName
|
|
172
|
-
? `Simplify<${primaryInterfaceName}>`
|
|
173
|
-
: `Record<string, never>`
|
|
174
|
-
}, ${itemInterfaceName ? `Simplify<${itemInterfaceName}>` : `never`}>;
|
|
165
|
+
export type ${variationName} = prismic.SharedSliceVariation<"${variationModel.id}", ${
|
|
166
|
+
primaryInterfaceName ? `Simplify<${primaryInterfaceName}>` : `Record<string, never>`
|
|
167
|
+
}, ${itemInterfaceName ? `Simplify<${itemInterfaceName}>` : `never`}>;
|
|
175
168
|
`,
|
|
176
|
-
code
|
|
169
|
+
code,
|
|
177
170
|
);
|
|
178
171
|
|
|
179
172
|
variationNames.push(variationName);
|
|
@@ -186,19 +179,17 @@ export function buildSharedSliceType(
|
|
|
186
179
|
contentTypeNames.push(...variationNames);
|
|
187
180
|
|
|
188
181
|
code = addSection(
|
|
189
|
-
|
|
182
|
+
dedent`
|
|
190
183
|
/**
|
|
191
184
|
* Slice variation for *${humanReadableName}*
|
|
192
185
|
*/
|
|
193
|
-
type ${variationUnionName} = ${
|
|
194
|
-
variationNames.length > 0 ? variationsUnion : "never"
|
|
195
|
-
}
|
|
186
|
+
type ${variationUnionName} = ${variationNames.length > 0 ? variationsUnion : "never"}
|
|
196
187
|
`,
|
|
197
|
-
code
|
|
188
|
+
code,
|
|
198
189
|
);
|
|
199
190
|
|
|
200
191
|
code = addSection(
|
|
201
|
-
|
|
192
|
+
dedent`
|
|
202
193
|
/**
|
|
203
194
|
* ${humanReadableName} Shared Slice
|
|
204
195
|
*
|
|
@@ -206,11 +197,9 @@ export function buildSharedSliceType(
|
|
|
206
197
|
* - **Description**: ${args.model.description || "*None*"}
|
|
207
198
|
* - **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}
|
|
208
199
|
*/
|
|
209
|
-
export type ${name} = prismic.SharedSlice<"${
|
|
210
|
-
args.model.id
|
|
211
|
-
}", ${variationUnionName}>;
|
|
200
|
+
export type ${name} = prismic.SharedSlice<"${args.model.id}", ${variationUnionName}>;
|
|
212
201
|
`,
|
|
213
|
-
code
|
|
202
|
+
code,
|
|
214
203
|
);
|
|
215
204
|
|
|
216
205
|
const result = {
|
package/src/lib/buildTypeName.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { pascalCase
|
|
1
|
+
import { pascalCase } from "change-case";
|
|
2
2
|
|
|
3
3
|
export const buildTypeName = (...parts: string[]): string => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
// Non-ASCII characters are separators, as they were with the previous `pascal-case` package.
|
|
5
|
+
let name = pascalCase(
|
|
6
|
+
parts
|
|
7
|
+
.filter(Boolean)
|
|
8
|
+
.join(" ")
|
|
9
|
+
.replace(/[^A-Z0-9]+/gi, " "),
|
|
10
|
+
{ mergeAmbiguousCharacters: true },
|
|
11
|
+
);
|
|
7
12
|
|
|
8
13
|
if (/^[0-9]/.test(name) ? "_" : "") {
|
|
9
14
|
name = `_${name}`;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import baseDedent from "dedent";
|
|
2
|
+
|
|
3
|
+
const baseDedentWithOptions = baseDedent.withOptions({ alignValues: true });
|
|
4
|
+
|
|
5
|
+
export function dedent(strings: TemplateStringsArray | string, ...values: unknown[]): string {
|
|
6
|
+
if (typeof strings === "string") {
|
|
7
|
+
return baseDedentWithOptions(strings);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// dedent reads `strings.raw` by default, which keeps escapes in string literals. Point `raw` at
|
|
11
|
+
// the regular string segments instead, where escapes are already resolved.
|
|
12
|
+
const resolved = Array.from(strings);
|
|
13
|
+
return baseDedentWithOptions(Object.assign(resolved, { raw: resolved }), ...values);
|
|
14
|
+
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
//#endregion
|
|
23
|
-
exports.__toESM = __toESM;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
let zod = require("zod");
|
|
3
|
-
//#region src/cli/configSchema.ts
|
|
4
|
-
/** Configuration to control the generated types. */
|
|
5
|
-
const configSchema = zod.z.object({
|
|
6
|
-
repositoryName: zod.z.string().optional(),
|
|
7
|
-
accessToken: zod.z.string().optional(),
|
|
8
|
-
customTypesAPIToken: zod.z.string().optional(),
|
|
9
|
-
output: zod.z.string().optional(),
|
|
10
|
-
typesProvider: zod.z.enum(["@prismicio/client", "@prismicio/types"]).optional(),
|
|
11
|
-
clientIntegration: zod.z.object({
|
|
12
|
-
includeCreateClientInterface: zod.z.boolean().optional(),
|
|
13
|
-
includeContentNamespace: zod.z.boolean().optional()
|
|
14
|
-
}).optional(),
|
|
15
|
-
locales: zod.z.union([zod.z.array(zod.z.string()), zod.z.object({
|
|
16
|
-
ids: zod.z.array(zod.z.string()).optional(),
|
|
17
|
-
fetchFromRepository: zod.z.boolean().optional()
|
|
18
|
-
})]).optional(),
|
|
19
|
-
models: zod.z.union([zod.z.array(zod.z.string()), zod.z.object({
|
|
20
|
-
files: zod.z.array(zod.z.string()).optional(),
|
|
21
|
-
fetchFromRepository: zod.z.boolean().optional()
|
|
22
|
-
})]).optional(),
|
|
23
|
-
fields: zod.z.object({
|
|
24
|
-
embed: zod.z.object({ providerTypes: zod.z.record(zod.z.string(), zod.z.string()).optional() }).optional(),
|
|
25
|
-
integrationFields: zod.z.object({ catalogTypes: zod.z.record(zod.z.string(), zod.z.string()).optional() }).optional()
|
|
26
|
-
}).optional()
|
|
27
|
-
});
|
|
28
|
-
//#endregion
|
|
29
|
-
exports.configSchema = configSchema;
|
|
30
|
-
|
|
31
|
-
//# sourceMappingURL=configSchema.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"configSchema.cjs","names":["z"],"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,eAAeA,IAAAA,EAAE,OAAO;CAEpC,gBAAgBA,IAAAA,EAAE,QAAQ,CAAC,UAAU;CAMrC,aAAaA,IAAAA,EAAE,QAAQ,CAAC,UAAU;CAMlC,qBAAqBA,IAAAA,EAAE,QAAQ,CAAC,UAAU;CAM1C,QAAQA,IAAAA,EAAE,QAAQ,CAAC,UAAU;CAQ7B,eAAeA,IAAAA,EAAE,KAAK,CAAC,qBAAqB,mBAAmB,CAAC,CAAC,UAAU;CAG3E,mBAAmBA,IAAAA,EACjB,OAAO;EAgBP,8BAA8BA,IAAAA,EAAE,SAAS,CAAC,UAAU;EAgBpD,yBAAyBA,IAAAA,EAAE,SAAS,CAAC,UAAU;EAC/C,CAAC,CACD,UAAU;CAqBZ,SAASA,IAAAA,EACP,MAAM,CACNA,IAAAA,EAAE,MAAMA,IAAAA,EAAE,QAAQ,CAAC,EACnBA,IAAAA,EAAE,OAAO;EAUR,KAAKA,IAAAA,EAAE,MAAMA,IAAAA,EAAE,QAAQ,CAAC,CAAC,UAAU;EAMnC,qBAAqBA,IAAAA,EAAE,SAAS,CAAC,UAAU;EAC3C,CAAC,CACF,CAAC,CACD,UAAU;CAQZ,QAAQA,IAAAA,EACN,MAAM,CACNA,IAAAA,EAAE,MAAMA,IAAAA,EAAE,QAAQ,CAAC,EACnBA,IAAAA,EAAE,OAAO;EAER,OAAOA,IAAAA,EAAE,MAAMA,IAAAA,EAAE,QAAQ,CAAC,CAAC,UAAU;EAQrC,qBAAqBA,IAAAA,EAAE,SAAS,CAAC,UAAU;EAC3C,CAAC,CACF,CAAC,CACD,UAAU;CAGZ,QAAQA,IAAAA,EACN,OAAO;EAEP,OAAOA,IAAAA,EACL,OAAO,EAcP,eAAeA,IAAAA,EAAE,OAAOA,IAAAA,EAAE,QAAQ,EAAEA,IAAAA,EAAE,QAAQ,CAAC,CAAC,UAAU,EAC1D,CAAC,CACD,UAAU;EAGZ,mBAAmBA,IAAAA,EACjB,OAAO,EAaP,cAAcA,IAAAA,EAAE,OAAOA,IAAAA,EAAE,QAAQ,EAAEA,IAAAA,EAAE,QAAQ,CAAC,CAAC,UAAU,EACzD,CAAC,CACD,UAAU;EACZ,CAAC,CACD,UAAU;CACZ,CAAC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
//#region src/cli/configSchema.d.ts
|
|
4
|
-
/** Configuration to control the generated types. */
|
|
5
|
-
declare const configSchema: z.ZodObject<{
|
|
6
|
-
repositoryName: z.ZodOptional<z.ZodString>;
|
|
7
|
-
accessToken: z.ZodOptional<z.ZodString>;
|
|
8
|
-
customTypesAPIToken: z.ZodOptional<z.ZodString>;
|
|
9
|
-
output: z.ZodOptional<z.ZodString>;
|
|
10
|
-
typesProvider: z.ZodOptional<z.ZodEnum<{
|
|
11
|
-
"@prismicio/client": "@prismicio/client";
|
|
12
|
-
"@prismicio/types": "@prismicio/types";
|
|
13
|
-
}>>;
|
|
14
|
-
clientIntegration: z.ZodOptional<z.ZodObject<{
|
|
15
|
-
includeCreateClientInterface: z.ZodOptional<z.ZodBoolean>;
|
|
16
|
-
includeContentNamespace: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
-
}, z.core.$strip>>;
|
|
18
|
-
locales: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodObject<{
|
|
19
|
-
ids: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
20
|
-
fetchFromRepository: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
-
}, z.core.$strip>]>>;
|
|
22
|
-
models: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodObject<{
|
|
23
|
-
files: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
24
|
-
fetchFromRepository: z.ZodOptional<z.ZodBoolean>;
|
|
25
|
-
}, z.core.$strip>]>>;
|
|
26
|
-
fields: z.ZodOptional<z.ZodObject<{
|
|
27
|
-
embed: z.ZodOptional<z.ZodObject<{
|
|
28
|
-
providerTypes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
29
|
-
}, z.core.$strip>>;
|
|
30
|
-
integrationFields: z.ZodOptional<z.ZodObject<{
|
|
31
|
-
catalogTypes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
32
|
-
}, z.core.$strip>>;
|
|
33
|
-
}, z.core.$strip>>;
|
|
34
|
-
}, z.core.$strip>;
|
|
35
|
-
/** Configuration to control the generated types. */
|
|
36
|
-
type Config = z.infer<typeof configSchema>;
|
|
37
|
-
//#endregion
|
|
38
|
-
export { Config };
|
|
39
|
-
//# sourceMappingURL=configSchema.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"configSchema.d.cts","names":[],"sources":["../../src/cli/configSchema.ts"],"mappings":";;;;cAGa,YAAA,EAAY,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAqLb,MAAA,GAAS,CAAA,CAAE,KAAA,QAAa,YAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"configSchema.d.ts","names":[],"sources":["../../src/cli/configSchema.ts"],"mappings":";;;;cAGa,YAAA,EAAY,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAqLb,MAAA,GAAS,CAAA,CAAE,KAAA,QAAa,YAAA"}
|
package/dist/cli/configSchema.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
//#region src/cli/configSchema.ts
|
|
3
|
-
/** Configuration to control the generated types. */
|
|
4
|
-
const configSchema = z.object({
|
|
5
|
-
repositoryName: z.string().optional(),
|
|
6
|
-
accessToken: z.string().optional(),
|
|
7
|
-
customTypesAPIToken: z.string().optional(),
|
|
8
|
-
output: z.string().optional(),
|
|
9
|
-
typesProvider: z.enum(["@prismicio/client", "@prismicio/types"]).optional(),
|
|
10
|
-
clientIntegration: z.object({
|
|
11
|
-
includeCreateClientInterface: z.boolean().optional(),
|
|
12
|
-
includeContentNamespace: z.boolean().optional()
|
|
13
|
-
}).optional(),
|
|
14
|
-
locales: z.union([z.array(z.string()), z.object({
|
|
15
|
-
ids: z.array(z.string()).optional(),
|
|
16
|
-
fetchFromRepository: z.boolean().optional()
|
|
17
|
-
})]).optional(),
|
|
18
|
-
models: z.union([z.array(z.string()), z.object({
|
|
19
|
-
files: z.array(z.string()).optional(),
|
|
20
|
-
fetchFromRepository: z.boolean().optional()
|
|
21
|
-
})]).optional(),
|
|
22
|
-
fields: z.object({
|
|
23
|
-
embed: z.object({ providerTypes: z.record(z.string(), z.string()).optional() }).optional(),
|
|
24
|
-
integrationFields: z.object({ catalogTypes: z.record(z.string(), z.string()).optional() }).optional()
|
|
25
|
-
}).optional()
|
|
26
|
-
});
|
|
27
|
-
//#endregion
|
|
28
|
-
export { configSchema };
|
|
29
|
-
|
|
30
|
-
//# sourceMappingURL=configSchema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"configSchema.js","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,QAAQ,CAAC,UAAU;CAMrC,aAAa,EAAE,QAAQ,CAAC,UAAU;CAMlC,qBAAqB,EAAE,QAAQ,CAAC,UAAU;CAM1C,QAAQ,EAAE,QAAQ,CAAC,UAAU;CAQ7B,eAAe,EAAE,KAAK,CAAC,qBAAqB,mBAAmB,CAAC,CAAC,UAAU;CAG3E,mBAAmB,EACjB,OAAO;EAgBP,8BAA8B,EAAE,SAAS,CAAC,UAAU;EAgBpD,yBAAyB,EAAE,SAAS,CAAC,UAAU;EAC/C,CAAC,CACD,UAAU;CAqBZ,SAAS,EACP,MAAM,CACN,EAAE,MAAM,EAAE,QAAQ,CAAC,EACnB,EAAE,OAAO;EAUR,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;EAMnC,qBAAqB,EAAE,SAAS,CAAC,UAAU;EAC3C,CAAC,CACF,CAAC,CACD,UAAU;CAQZ,QAAQ,EACN,MAAM,CACN,EAAE,MAAM,EAAE,QAAQ,CAAC,EACnB,EAAE,OAAO;EAER,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;EAQrC,qBAAqB,EAAE,SAAS,CAAC,UAAU;EAC3C,CAAC,CACF,CAAC,CACD,UAAU;CAGZ,QAAQ,EACN,OAAO;EAEP,OAAO,EACL,OAAO,EAcP,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAC,UAAU,EAC1D,CAAC,CACD,UAAU;EAGZ,mBAAmB,EACjB,OAAO,EAaP,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAC,UAAU,EACzD,CAAC,CACD,UAAU;EACZ,CAAC,CACD,UAAU;CACZ,CAAC"}
|
package/dist/cli/constants.cjs
DELETED
package/dist/cli/constants.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.cts","names":[],"sources":["../../src/cli/constants.ts"],"mappings":";cAAa,wBAAA"}
|
package/dist/cli/constants.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","names":[],"sources":["../../src/cli/constants.ts"],"mappings":";cAAa,wBAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":[],"sources":["../../src/cli/constants.ts"],"sourcesContent":["export const NON_EDITABLE_FILE_HEADER = \"// Code generated by prismic-ts-codegen. DO NOT EDIT.\";\n"],"mappings":";AAAA,MAAa,2BAA2B"}
|
package/dist/cli/loadConfig.cjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
let fs = require("fs");
|
|
3
|
-
let path = require("path");
|
|
4
|
-
let jiti = require("jiti");
|
|
5
|
-
jiti = require_runtime.__toESM(jiti);
|
|
6
|
-
//#region src/cli/loadConfig.ts
|
|
7
|
-
const jiti$1 = (0, jiti.default)(process.cwd());
|
|
8
|
-
const loadModuleWithJiti = (id) => {
|
|
9
|
-
const mod = jiti$1(id);
|
|
10
|
-
return typeof mod === "object" && mod !== null && "default" in mod ? mod.default : mod;
|
|
11
|
-
};
|
|
12
|
-
const DEFAULT_CONFIG_PATHS = ["prismicCodegen.config.ts", "prismicCodegen.config.js"];
|
|
13
|
-
const loadConfig = (config) => {
|
|
14
|
-
if (config.path) if ((0, fs.existsSync)(config.path)) return loadModuleWithJiti((0, path.resolve)(config.path));
|
|
15
|
-
else throw new Error(`Config file does not exist: ${config.path}`);
|
|
16
|
-
else for (const configPath of DEFAULT_CONFIG_PATHS) if ((0, fs.existsSync)(configPath)) return loadModuleWithJiti((0, path.resolve)(configPath));
|
|
17
|
-
return {};
|
|
18
|
-
};
|
|
19
|
-
//#endregion
|
|
20
|
-
exports.loadConfig = loadConfig;
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=loadConfig.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loadConfig.cjs","names":["jiti"],"sources":["../../src/cli/loadConfig.ts"],"sourcesContent":["import { existsSync } from \"fs\";\nimport { resolve as resolvePath } from \"path\";\n\nimport _jiti from \"jiti\";\n\nimport type { Config } from \"./configSchema\";\n\nconst jiti = _jiti(process.cwd());\n\nconst loadModuleWithJiti = <TModule>(id: string): TModule => {\n\tconst mod = jiti(id) as TModule | { default: TModule };\n\n\treturn typeof mod === \"object\" && mod !== null && \"default\" in mod ? mod.default : mod;\n};\n\nconst DEFAULT_CONFIG_PATHS = [\"prismicCodegen.config.ts\", \"prismicCodegen.config.js\"];\n\ntype LoadConfigConfig = {\n\tpath?: string;\n};\n\nexport const loadConfig = (config: LoadConfigConfig): Config => {\n\tif (config.path) {\n\t\tif (existsSync(config.path)) {\n\t\t\treturn loadModuleWithJiti(resolvePath(config.path));\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 loadModuleWithJiti(resolvePath(configPath));\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,MAAMA,UAAAA,GAAAA,KAAAA,SAAa,QAAQ,KAAK,CAAC;AAEjC,MAAM,sBAA+B,OAAwB;CAC5D,MAAM,MAAMA,OAAK,GAAG;AAEpB,QAAO,OAAO,QAAQ,YAAY,QAAQ,QAAQ,aAAa,MAAM,IAAI,UAAU;;AAGpF,MAAM,uBAAuB,CAAC,4BAA4B,2BAA2B;AAMrF,MAAa,cAAc,WAAqC;AAC/D,KAAI,OAAO,KACV,MAAA,GAAA,GAAA,YAAe,OAAO,KAAK,CAC1B,QAAO,oBAAA,GAAA,KAAA,SAA+B,OAAO,KAAK,CAAC;KAEnD,OAAM,IAAI,MAAM,+BAA+B,OAAO,OAAO;KAG9D,MAAK,MAAM,cAAc,qBACxB,MAAA,GAAA,GAAA,YAAe,WAAW,CACzB,QAAO,oBAAA,GAAA,KAAA,SAA+B,WAAW,CAAC;AAMrD,QAAO,EAAE"}
|
package/dist/cli/loadConfig.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "fs";
|
|
2
|
-
import { resolve } from "path";
|
|
3
|
-
import _jiti from "jiti";
|
|
4
|
-
//#region src/cli/loadConfig.ts
|
|
5
|
-
const jiti = _jiti(process.cwd());
|
|
6
|
-
const loadModuleWithJiti = (id) => {
|
|
7
|
-
const mod = jiti(id);
|
|
8
|
-
return typeof mod === "object" && mod !== null && "default" in mod ? mod.default : mod;
|
|
9
|
-
};
|
|
10
|
-
const DEFAULT_CONFIG_PATHS = ["prismicCodegen.config.ts", "prismicCodegen.config.js"];
|
|
11
|
-
const loadConfig = (config) => {
|
|
12
|
-
if (config.path) if (existsSync(config.path)) return loadModuleWithJiti(resolve(config.path));
|
|
13
|
-
else throw new Error(`Config file does not exist: ${config.path}`);
|
|
14
|
-
else for (const configPath of DEFAULT_CONFIG_PATHS) if (existsSync(configPath)) return loadModuleWithJiti(resolve(configPath));
|
|
15
|
-
return {};
|
|
16
|
-
};
|
|
17
|
-
//#endregion
|
|
18
|
-
export { loadConfig };
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=loadConfig.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loadConfig.js","names":["resolvePath"],"sources":["../../src/cli/loadConfig.ts"],"sourcesContent":["import { existsSync } from \"fs\";\nimport { resolve as resolvePath } from \"path\";\n\nimport _jiti from \"jiti\";\n\nimport type { Config } from \"./configSchema\";\n\nconst jiti = _jiti(process.cwd());\n\nconst loadModuleWithJiti = <TModule>(id: string): TModule => {\n\tconst mod = jiti(id) as TModule | { default: TModule };\n\n\treturn typeof mod === \"object\" && mod !== null && \"default\" in mod ? mod.default : mod;\n};\n\nconst DEFAULT_CONFIG_PATHS = [\"prismicCodegen.config.ts\", \"prismicCodegen.config.js\"];\n\ntype LoadConfigConfig = {\n\tpath?: string;\n};\n\nexport const loadConfig = (config: LoadConfigConfig): Config => {\n\tif (config.path) {\n\t\tif (existsSync(config.path)) {\n\t\t\treturn loadModuleWithJiti(resolvePath(config.path));\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 loadModuleWithJiti(resolvePath(configPath));\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,MAAM,QAAQ,KAAK,CAAC;AAEjC,MAAM,sBAA+B,OAAwB;CAC5D,MAAM,MAAM,KAAK,GAAG;AAEpB,QAAO,OAAO,QAAQ,YAAY,QAAQ,QAAQ,aAAa,MAAM,IAAI,UAAU;;AAGpF,MAAM,uBAAuB,CAAC,4BAA4B,2BAA2B;AAMrF,MAAa,cAAc,WAAqC;AAC/D,KAAI,OAAO,KACV,KAAI,WAAW,OAAO,KAAK,CAC1B,QAAO,mBAAmBA,QAAY,OAAO,KAAK,CAAC;KAEnD,OAAM,IAAI,MAAM,+BAA+B,OAAO,OAAO;KAG9D,MAAK,MAAM,cAAc,qBACxB,KAAI,WAAW,WAAW,CACzB,QAAO,mBAAmBA,QAAY,WAAW,CAAC;AAMrD,QAAO,EAAE"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
let _prismicio_client = require("@prismicio/client");
|
|
3
|
-
_prismicio_client = require_runtime.__toESM(_prismicio_client);
|
|
4
|
-
let node_fetch = require("node-fetch");
|
|
5
|
-
node_fetch = require_runtime.__toESM(node_fetch);
|
|
6
|
-
//#region src/cli/loadLocaleIDs.ts
|
|
7
|
-
const loadLocaleIDs = async (config) => {
|
|
8
|
-
const localeIDs = new Set(config.localeIDs || []);
|
|
9
|
-
if ("repositoryName" in config && config.fetchFromRepository) {
|
|
10
|
-
const repository = await _prismicio_client.createClient(config.repositoryName, {
|
|
11
|
-
accessToken: config.accessToken,
|
|
12
|
-
fetch: node_fetch.default
|
|
13
|
-
}).getRepository();
|
|
14
|
-
for (const language of repository.languages) localeIDs.add(language.id);
|
|
15
|
-
}
|
|
16
|
-
return [...localeIDs];
|
|
17
|
-
};
|
|
18
|
-
//#endregion
|
|
19
|
-
exports.loadLocaleIDs = loadLocaleIDs;
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=loadLocaleIDs.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loadLocaleIDs.cjs","names":["prismic"],"sources":["../../src/cli/loadLocaleIDs.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport fetch from \"node-fetch\";\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":";;;;;;AAcA,MAAa,gBAAgB,OAAO,WAAiD;CACpF,MAAM,YAAY,IAAI,IAAY,OAAO,aAAa,EAAE,CAAC;AAEzD,KAAI,oBAAoB,UAAU,OAAO,qBAAqB;EAM7D,MAAM,aAAa,MALJA,kBAAQ,aAAa,OAAO,gBAAgB;GAC1D,aAAa,OAAO;GACpB,OAAA,WAAA;GACA,CAAC,CAE8B,eAAe;AAE/C,OAAK,MAAM,YAAY,WAAW,UACjC,WAAU,IAAI,SAAS,GAAG;;AAI5B,QAAO,CAAC,GAAG,UAAU"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loadLocaleIDs.js","names":[],"sources":["../../src/cli/loadLocaleIDs.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport fetch from \"node-fetch\";\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":";;;AAcA,MAAa,gBAAgB,OAAO,WAAiD;CACpF,MAAM,YAAY,IAAI,IAAY,OAAO,aAAa,EAAE,CAAC;AAEzD,KAAI,oBAAoB,UAAU,OAAO,qBAAqB;EAM7D,MAAM,aAAa,MALJ,QAAQ,aAAa,OAAO,gBAAgB;GAC1D,aAAa,OAAO;GACpB;GACA,CAAC,CAE8B,eAAe;AAE/C,OAAK,MAAM,YAAY,WAAW,UACjC,WAAU,IAAI,SAAS,GAAG;;AAI5B,QAAO,CAAC,GAAG,UAAU"}
|
package/dist/cli/loadModels.cjs
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
let fs = require("fs");
|
|
3
|
-
let node_fetch = require("node-fetch");
|
|
4
|
-
node_fetch = require_runtime.__toESM(node_fetch);
|
|
5
|
-
let _prismicio_custom_types_client = require("@prismicio/custom-types-client");
|
|
6
|
-
_prismicio_custom_types_client = require_runtime.__toESM(_prismicio_custom_types_client);
|
|
7
|
-
let fast_glob = require("fast-glob");
|
|
8
|
-
fast_glob = require_runtime.__toESM(fast_glob);
|
|
9
|
-
//#region src/cli/loadModels.ts
|
|
10
|
-
const isCustomTypeModel = (input) => {
|
|
11
|
-
return typeof input === "object" && input !== null && "json" in input;
|
|
12
|
-
};
|
|
13
|
-
const isSharedSliceModel = (input) => {
|
|
14
|
-
return typeof input === "object" && input !== null && "variations" in input;
|
|
15
|
-
};
|
|
16
|
-
const readJSONFromGlob = async (globs) => {
|
|
17
|
-
return (await (0, fast_glob.default)(globs.split(",").map((path) => path.trim()))).map((path) => {
|
|
18
|
-
const raw = (0, fs.readFileSync)(path, "utf8");
|
|
19
|
-
return JSON.parse(raw);
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
const loadModels = async (config) => {
|
|
23
|
-
const customTypeModels = {};
|
|
24
|
-
const sharedSliceModels = {};
|
|
25
|
-
if ("customTypesAPIToken" in config) {
|
|
26
|
-
const customTypesClient = _prismicio_custom_types_client.createClient({
|
|
27
|
-
repositoryName: config.repositoryName,
|
|
28
|
-
token: config.customTypesAPIToken,
|
|
29
|
-
fetch: node_fetch.default
|
|
30
|
-
});
|
|
31
|
-
if (config.fetchFromRepository) {
|
|
32
|
-
const [remoteCustomTypeModels, remoteSharedSliceModels] = await Promise.all([customTypesClient.getAllCustomTypes(), customTypesClient.getAllSharedSlices()]);
|
|
33
|
-
for (const customTypeModel of remoteCustomTypeModels) customTypeModels[customTypeModel.id] = customTypeModel;
|
|
34
|
-
for (const sharedSliceModel of remoteSharedSliceModels) sharedSliceModels[sharedSliceModel.id] = sharedSliceModel;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (config.localPaths) {
|
|
38
|
-
const models = (await Promise.all(config.localPaths.map((glob) => readJSONFromGlob(glob)))).flat();
|
|
39
|
-
for (const model of models) if (isCustomTypeModel(model)) customTypeModels[model.id] = model;
|
|
40
|
-
else if (isSharedSliceModel(model)) sharedSliceModels[model.id] = model;
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
customTypeModels: Object.values(customTypeModels).sort((a, b) => {
|
|
44
|
-
return a.id.localeCompare(b.id);
|
|
45
|
-
}),
|
|
46
|
-
sharedSliceModels: Object.values(sharedSliceModels).sort((a, b) => {
|
|
47
|
-
return a.id.localeCompare(b.id);
|
|
48
|
-
})
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
//#endregion
|
|
52
|
-
exports.loadModels = loadModels;
|
|
53
|
-
|
|
54
|
-
//# sourceMappingURL=loadModels.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loadModels.cjs","names":["prismicCT"],"sources":["../../src/cli/loadModels.ts"],"sourcesContent":["import { readFileSync } from \"fs\";\n\nimport type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport * as prismicCT from \"@prismicio/custom-types-client\";\nimport fg from \"fast-glob\";\nimport fetch from \"node-fetch\";\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 fg(globs.split(\",\").map((path) => path.trim()));\n\n\treturn paths.map((path) => {\n\t\tconst raw = readFileSync(path, \"utf8\");\n\n\t\treturn JSON.parse(raw);\n\t});\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\tconst customTypesClient = prismicCT.createClient({\n\t\t\trepositoryName: config.repositoryName,\n\t\t\ttoken: config.customTypesAPIToken,\n\t\t\tfetch,\n\t\t});\n\n\t\tif (config.fetchFromRepository) {\n\t\t\tconst [remoteCustomTypeModels, remoteSharedSliceModels] = await Promise.all([\n\t\t\t\tcustomTypesClient.getAllCustomTypes(),\n\t\t\t\tcustomTypesClient.getAllSharedSlices(),\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":";;;;;;;;;AAOA,MAAM,qBAAqB,UAA6C;AACvE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU;;AAGjE,MAAM,sBAAsB,UAA8C;AACzE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,gBAAgB;;AAGvE,MAAM,mBAAmB,OAAU,UAAgC;AAGlE,SAFc,OAAA,GAAA,UAAA,SAAS,MAAM,MAAM,IAAI,CAAC,KAAK,SAAS,KAAK,MAAM,CAAC,CAAC,EAEtD,KAAK,SAAS;EAC1B,MAAM,OAAA,GAAA,GAAA,cAAmB,MAAM,OAAO;AAEtC,SAAO,KAAK,MAAM,IAAI;GACrB;;AAmBH,MAAa,aAAa,OAAO,WAA4D;CAC5F,MAAM,mBAAoD,EAAE;CAC5D,MAAM,oBAAsD,EAAE;AAE9D,KAAI,yBAAyB,QAAQ;EACpC,MAAM,oBAAoBA,+BAAU,aAAa;GAChD,gBAAgB,OAAO;GACvB,OAAO,OAAO;GACd,OAAA,WAAA;GACA,CAAC;AAEF,MAAI,OAAO,qBAAqB;GAC/B,MAAM,CAAC,wBAAwB,2BAA2B,MAAM,QAAQ,IAAI,CAC3E,kBAAkB,mBAAmB,EACrC,kBAAkB,oBAAoB,CACtC,CAAC;AAEF,QAAK,MAAM,mBAAmB,uBAC7B,kBAAiB,gBAAgB,MAAM;AAExC,QAAK,MAAM,oBAAoB,wBAC9B,mBAAkB,iBAAiB,MAAM;;;AAK5C,KAAI,OAAO,YAAY;EACtB,MAAM,UACL,MAAM,QAAQ,IAAI,OAAO,WAAW,KAAK,SAAS,iBAAiB,KAAK,CAAC,CAAC,EACzE,MAAM;AAER,OAAK,MAAM,SAAS,OACnB,KAAI,kBAAkB,MAAM,CAC3B,kBAAiB,MAAM,MAAM;WACnB,mBAAmB,MAAM,CACnC,mBAAkB,MAAM,MAAM;;AAKjC,QAAO;EACN,kBAAkB,OAAO,OAAO,iBAAiB,CAAC,MAAM,GAAG,MAAM;AAChE,UAAO,EAAE,GAAG,cAAc,EAAE,GAAG;IAC9B;EACF,mBAAmB,OAAO,OAAO,kBAAkB,CAAC,MAAM,GAAG,MAAM;AAClE,UAAO,EAAE,GAAG,cAAc,EAAE,GAAG;IAC9B;EACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loadModels.js","names":[],"sources":["../../src/cli/loadModels.ts"],"sourcesContent":["import { readFileSync } from \"fs\";\n\nimport type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport * as prismicCT from \"@prismicio/custom-types-client\";\nimport fg from \"fast-glob\";\nimport fetch from \"node-fetch\";\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 fg(globs.split(\",\").map((path) => path.trim()));\n\n\treturn paths.map((path) => {\n\t\tconst raw = readFileSync(path, \"utf8\");\n\n\t\treturn JSON.parse(raw);\n\t});\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\tconst customTypesClient = prismicCT.createClient({\n\t\t\trepositoryName: config.repositoryName,\n\t\t\ttoken: config.customTypesAPIToken,\n\t\t\tfetch,\n\t\t});\n\n\t\tif (config.fetchFromRepository) {\n\t\t\tconst [remoteCustomTypeModels, remoteSharedSliceModels] = await Promise.all([\n\t\t\t\tcustomTypesClient.getAllCustomTypes(),\n\t\t\t\tcustomTypesClient.getAllSharedSlices(),\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":";;;;;AAOA,MAAM,qBAAqB,UAA6C;AACvE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU;;AAGjE,MAAM,sBAAsB,UAA8C;AACzE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,gBAAgB;;AAGvE,MAAM,mBAAmB,OAAU,UAAgC;AAGlE,SAFc,MAAM,GAAG,MAAM,MAAM,IAAI,CAAC,KAAK,SAAS,KAAK,MAAM,CAAC,CAAC,EAEtD,KAAK,SAAS;EAC1B,MAAM,MAAM,aAAa,MAAM,OAAO;AAEtC,SAAO,KAAK,MAAM,IAAI;GACrB;;AAmBH,MAAa,aAAa,OAAO,WAA4D;CAC5F,MAAM,mBAAoD,EAAE;CAC5D,MAAM,oBAAsD,EAAE;AAE9D,KAAI,yBAAyB,QAAQ;EACpC,MAAM,oBAAoB,UAAU,aAAa;GAChD,gBAAgB,OAAO;GACvB,OAAO,OAAO;GACd;GACA,CAAC;AAEF,MAAI,OAAO,qBAAqB;GAC/B,MAAM,CAAC,wBAAwB,2BAA2B,MAAM,QAAQ,IAAI,CAC3E,kBAAkB,mBAAmB,EACrC,kBAAkB,oBAAoB,CACtC,CAAC;AAEF,QAAK,MAAM,mBAAmB,uBAC7B,kBAAiB,gBAAgB,MAAM;AAExC,QAAK,MAAM,oBAAoB,wBAC9B,mBAAkB,iBAAiB,MAAM;;;AAK5C,KAAI,OAAO,YAAY;EACtB,MAAM,UACL,MAAM,QAAQ,IAAI,OAAO,WAAW,KAAK,SAAS,iBAAiB,KAAK,CAAC,CAAC,EACzE,MAAM;AAER,OAAK,MAAM,SAAS,OACnB,KAAI,kBAAkB,MAAM,CAC3B,kBAAiB,MAAM,MAAM;WACnB,mBAAmB,MAAM,CACnC,mBAAkB,MAAM,MAAM;;AAKjC,QAAO;EACN,kBAAkB,OAAO,OAAO,iBAAiB,CAAC,MAAM,GAAG,MAAM;AAChE,UAAO,EAAE,GAAG,cAAc,EAAE,GAAG;IAC9B;EACF,mBAAmB,OAAO,OAAO,kBAAkB,CAAC,MAAM,GAAG,MAAM;AAClE,UAAO,EAAE,GAAG,cAAc,EAAE,GAAG;IAC9B;EACF"}
|