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.
- package/README.md +5 -5
- package/bin/prismic-ts-codegen.mjs +3 -0
- package/dist/cli/configSchema.cjs +38 -0
- package/dist/cli/configSchema.cjs.map +1 -0
- package/dist/cli/configSchema.d.ts +3 -0
- package/dist/cli/configSchema.js +38 -0
- package/dist/cli/configSchema.js.map +1 -0
- package/dist/cli/constants.cjs +5 -0
- package/dist/cli/constants.cjs.map +1 -0
- package/dist/cli/constants.d.ts +1 -0
- package/dist/cli/constants.js +5 -0
- package/dist/cli/constants.js.map +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/loadConfig.cjs +32 -0
- package/dist/cli/loadConfig.cjs.map +1 -0
- package/dist/cli/loadConfig.d.ts +6 -0
- package/dist/cli/loadConfig.js +32 -0
- package/dist/cli/loadConfig.js.map +1 -0
- package/dist/cli/loadLocaleIDs.cjs +37 -0
- package/dist/cli/loadLocaleIDs.cjs.map +1 -0
- package/dist/cli/loadLocaleIDs.d.ts +10 -0
- package/dist/cli/loadLocaleIDs.js +20 -0
- package/dist/cli/loadLocaleIDs.js.map +1 -0
- package/dist/cli/loadModels.cjs +79 -0
- package/dist/cli/loadModels.cjs.map +1 -0
- package/dist/cli/loadModels.d.ts +15 -0
- package/dist/cli/loadModels.js +62 -0
- package/dist/cli/loadModels.js.map +1 -0
- package/dist/cli/types.d.ts +175 -0
- package/dist/cli.cjs +119 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +118 -0
- package/dist/cli.js.map +1 -0
- package/dist/constants.cjs +29 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.js +29 -0
- package/dist/constants.js.map +1 -0
- package/dist/detectTypesProvider.cjs +16 -0
- package/dist/detectTypesProvider.cjs.map +1 -0
- package/dist/detectTypesProvider.d.ts +13 -0
- package/dist/detectTypesProvider.js +16 -0
- package/dist/detectTypesProvider.js.map +1 -0
- package/dist/generateTypes.cjs +109 -0
- package/dist/generateTypes.cjs.map +1 -0
- package/dist/generateTypes.d.ts +15 -0
- package/dist/generateTypes.js +109 -0
- package/dist/generateTypes.js.map +1 -0
- package/dist/index.cjs +6 -1086
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -192
- package/dist/index.js +5 -1081
- package/dist/index.js.map +1 -1
- package/dist/lib/addInterfacePropertiesForFields.cjs +490 -0
- package/dist/lib/addInterfacePropertiesForFields.cjs.map +1 -0
- package/dist/lib/addInterfacePropertiesForFields.d.ts +21 -0
- package/dist/lib/addInterfacePropertiesForFields.js +490 -0
- package/dist/lib/addInterfacePropertiesForFields.js.map +1 -0
- package/dist/lib/addTypeAliasForCustomType.cjs +81 -0
- package/dist/lib/addTypeAliasForCustomType.cjs.map +1 -0
- package/dist/lib/addTypeAliasForCustomType.d.ts +11 -0
- package/dist/lib/addTypeAliasForCustomType.js +81 -0
- package/dist/lib/addTypeAliasForCustomType.js.map +1 -0
- package/dist/lib/addTypeAliasForSharedSlice.cjs +149 -0
- package/dist/lib/addTypeAliasForSharedSlice.cjs.map +1 -0
- package/dist/lib/addTypeAliasForSharedSlice.d.ts +10 -0
- package/dist/lib/addTypeAliasForSharedSlice.js +149 -0
- package/dist/lib/addTypeAliasForSharedSlice.js.map +1 -0
- package/dist/lib/buildFieldDocs.cjs +43 -0
- package/dist/lib/buildFieldDocs.cjs.map +1 -0
- package/dist/lib/buildFieldDocs.d.ts +14 -0
- package/dist/lib/buildFieldDocs.js +43 -0
- package/dist/lib/buildFieldDocs.js.map +1 -0
- package/dist/lib/buildSharedSliceInterfaceNamePart.cjs +8 -0
- package/dist/lib/buildSharedSliceInterfaceNamePart.cjs.map +1 -0
- package/dist/lib/buildSharedSliceInterfaceNamePart.d.ts +5 -0
- package/dist/lib/buildSharedSliceInterfaceNamePart.js +8 -0
- package/dist/lib/buildSharedSliceInterfaceNamePart.js.map +1 -0
- package/dist/lib/buildTypeName.cjs +12 -0
- package/dist/lib/buildTypeName.cjs.map +1 -0
- package/dist/lib/buildTypeName.d.ts +1 -0
- package/dist/lib/buildTypeName.js +12 -0
- package/dist/lib/buildTypeName.js.map +1 -0
- package/dist/lib/getAPIIDPath.cjs +23 -0
- package/dist/lib/getAPIIDPath.cjs.map +1 -0
- package/dist/lib/getAPIIDPath.d.ts +10 -0
- package/dist/lib/getAPIIDPath.js +23 -0
- package/dist/lib/getAPIIDPath.js.map +1 -0
- package/dist/lib/getFieldDocumentationURL.cjs +8 -0
- package/dist/lib/getFieldDocumentationURL.cjs.map +1 -0
- package/dist/lib/getFieldDocumentationURL.d.ts +6 -0
- package/dist/lib/getFieldDocumentationURL.js +8 -0
- package/dist/lib/getFieldDocumentationURL.js.map +1 -0
- package/dist/lib/getHumanReadableFieldPath.cjs +19 -0
- package/dist/lib/getHumanReadableFieldPath.cjs.map +1 -0
- package/dist/lib/getHumanReadableFieldPath.d.ts +10 -0
- package/dist/lib/getHumanReadableFieldPath.js +19 -0
- package/dist/lib/getHumanReadableFieldPath.js.map +1 -0
- package/dist/lib/getHumanReadableFieldType.cjs +37 -0
- package/dist/lib/getHumanReadableFieldType.cjs.map +1 -0
- package/dist/lib/getHumanReadableFieldType.d.ts +6 -0
- package/dist/lib/getHumanReadableFieldType.js +37 -0
- package/dist/lib/getHumanReadableFieldType.js.map +1 -0
- package/dist/lib/getHumanReadableModelName.cjs +24 -0
- package/dist/lib/getHumanReadableModelName.cjs.map +1 -0
- package/dist/lib/getHumanReadableModelName.d.ts +7 -0
- package/dist/lib/getHumanReadableModelName.js +24 -0
- package/dist/lib/getHumanReadableModelName.js.map +1 -0
- package/dist/lib/getSourceFileText.cjs +9 -0
- package/dist/lib/getSourceFileText.cjs.map +1 -0
- package/dist/lib/getSourceFileText.d.ts +2 -0
- package/dist/lib/getSourceFileText.js +9 -0
- package/dist/lib/getSourceFileText.js.map +1 -0
- package/dist/lib/hasOwnProperty.cjs +7 -0
- package/dist/lib/hasOwnProperty.cjs.map +1 -0
- package/dist/lib/hasOwnProperty.d.ts +10 -0
- package/dist/lib/hasOwnProperty.js +7 -0
- package/dist/lib/hasOwnProperty.js.map +1 -0
- package/dist/lib/isCustomTypeModel.cjs +7 -0
- package/dist/lib/isCustomTypeModel.cjs.map +1 -0
- package/dist/lib/isCustomTypeModel.d.ts +2 -0
- package/dist/lib/isCustomTypeModel.js +7 -0
- package/dist/lib/isCustomTypeModel.js.map +1 -0
- package/dist/lib/isCustomTypeModelField.cjs +7 -0
- package/dist/lib/isCustomTypeModelField.cjs.map +1 -0
- package/dist/lib/isCustomTypeModelField.d.ts +2 -0
- package/dist/lib/isCustomTypeModelField.js +7 -0
- package/dist/lib/isCustomTypeModelField.js.map +1 -0
- package/dist/lib/isCustomTypeModelSlice.cjs +9 -0
- package/dist/lib/isCustomTypeModelSlice.cjs.map +1 -0
- package/dist/lib/isCustomTypeModelSlice.d.ts +2 -0
- package/dist/lib/isCustomTypeModelSlice.js +9 -0
- package/dist/lib/isCustomTypeModelSlice.js.map +1 -0
- package/dist/lib/isSharedSliceModel.cjs +9 -0
- package/dist/lib/isSharedSliceModel.cjs.map +1 -0
- package/dist/lib/isSharedSliceModel.d.ts +2 -0
- package/dist/lib/isSharedSliceModel.js +9 -0
- package/dist/lib/isSharedSliceModel.js.map +1 -0
- package/dist/lib/pascalCase.cjs +8 -0
- package/dist/lib/pascalCase.cjs.map +1 -0
- package/dist/lib/pascalCase.d.ts +1 -0
- package/dist/lib/pascalCase.js +8 -0
- package/dist/lib/pascalCase.js.map +1 -0
- package/dist/lib/writeFieldDocsDescription.cjs +29 -0
- package/dist/lib/writeFieldDocsDescription.cjs.map +1 -0
- package/dist/lib/writeFieldDocsDescription.d.ts +13 -0
- package/dist/lib/writeFieldDocsDescription.js +29 -0
- package/dist/lib/writeFieldDocsDescription.js.map +1 -0
- package/dist/types.d.ts +14 -0
- package/package.json +45 -36
- package/src/cli/configSchema.ts +2 -0
- package/src/cli/index.ts +9 -5
- package/src/cli/loadConfig.ts +4 -2
- package/src/cli/loadModels.ts +3 -3
- package/src/cli/types.ts +10 -0
- package/src/constants.ts +6 -3
- package/src/detectTypesProvider.ts +32 -0
- package/src/generateTypes.ts +11 -6
- package/src/index.ts +4 -1
- package/src/lib/addInterfacePropertiesForFields.ts +31 -28
- package/src/lib/addTypeAliasForCustomType.ts +7 -5
- package/src/lib/addTypeAliasForSharedSlice.ts +5 -4
- package/src/lib/buildFieldDocs.ts +2 -1
- package/src/lib/getAPIIDPath.ts +3 -2
- package/src/lib/getFieldDocumentationURL.ts +1 -1
- package/src/lib/getHumanReadableFieldPath.ts +2 -1
- package/src/lib/getHumanReadableFieldType.ts +2 -2
- package/src/lib/getHumanReadableModelName.ts +1 -1
- package/src/lib/getSourceFileText.ts +1 -1
- package/src/lib/isCustomTypeModel.ts +1 -1
- package/src/lib/isCustomTypeModelField.ts +1 -1
- package/src/lib/isCustomTypeModelSlice.ts +1 -1
- package/src/lib/isSharedSliceModel.ts +1 -1
- package/src/types.ts +1 -1
- package/bin/cli.mjs +0 -1342
package/README.md
CHANGED
|
@@ -11,14 +11,15 @@
|
|
|
11
11
|
|
|
12
12
|
A Prismic model-to-TypeScript-type generator.
|
|
13
13
|
|
|
14
|
-
- Converts
|
|
14
|
+
- Converts custom type and shared Slice models to TypeScript types
|
|
15
15
|
- Integrates with other Prismic TypeScript libraries
|
|
16
|
-
- Built
|
|
16
|
+
- Built upon the [`@prismicio/client`][prismic-client] library
|
|
17
17
|
|
|
18
18
|
## Install
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
npm install
|
|
21
|
+
npm install @prismicio/client
|
|
22
|
+
npm install --save-dev prismic-ts-codegen
|
|
22
23
|
```
|
|
23
24
|
|
|
24
25
|
## Usage
|
|
@@ -72,7 +73,6 @@ See the [`Config` TypeScript interface](./src/cli/types.ts) for a complete refer
|
|
|
72
73
|
|
|
73
74
|
```typescript
|
|
74
75
|
// prismicCodegen.config.ts
|
|
75
|
-
|
|
76
76
|
import type { Config } from "prismic-ts-codegen";
|
|
77
77
|
|
|
78
78
|
const config: Config = {
|
|
@@ -150,7 +150,7 @@ limitations under the License.
|
|
|
150
150
|
<!-- Links -->
|
|
151
151
|
|
|
152
152
|
[prismic]: https://prismic.io
|
|
153
|
-
[prismic-
|
|
153
|
+
[prismic-client]: https://github.com/prismicio/prismic-client
|
|
154
154
|
|
|
155
155
|
<!-- TODO: Replace link with a more useful one if available -->
|
|
156
156
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const Joi = require("joi");
|
|
4
|
+
const configSchema = Joi.object({
|
|
5
|
+
repositoryName: Joi.string().when("locales.fetchFromRepository", {
|
|
6
|
+
is: true,
|
|
7
|
+
then: Joi.required()
|
|
8
|
+
}).when("models.fetchFromRepository", {
|
|
9
|
+
is: true,
|
|
10
|
+
then: Joi.required()
|
|
11
|
+
}),
|
|
12
|
+
accessToken: Joi.string(),
|
|
13
|
+
customTypesAPIToken: Joi.string(),
|
|
14
|
+
output: Joi.string(),
|
|
15
|
+
typesProvider: Joi.string().allow("@prismicio/client", "@prismicio/client"),
|
|
16
|
+
clientIntegration: Joi.object({
|
|
17
|
+
includeCreateClientInterface: Joi.boolean(),
|
|
18
|
+
includeContentNamespace: Joi.boolean()
|
|
19
|
+
}),
|
|
20
|
+
locales: Joi.alternatives(Joi.array().items(Joi.string().required()), Joi.object({
|
|
21
|
+
ids: Joi.array().items(Joi.string().required()),
|
|
22
|
+
fetchFromRepository: Joi.boolean()
|
|
23
|
+
})),
|
|
24
|
+
models: Joi.alternatives(Joi.array().items(Joi.string()), Joi.object({
|
|
25
|
+
files: Joi.array().items(Joi.string()),
|
|
26
|
+
fetchFromRepository: Joi.boolean()
|
|
27
|
+
})),
|
|
28
|
+
fields: Joi.object({
|
|
29
|
+
embed: Joi.object({
|
|
30
|
+
providerTypes: Joi.object().pattern(Joi.string(), Joi.string().required())
|
|
31
|
+
}),
|
|
32
|
+
integrationFields: Joi.object({
|
|
33
|
+
catalogTypes: Joi.object().pattern(Joi.string(), Joi.string().required())
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
exports.configSchema = configSchema;
|
|
38
|
+
//# sourceMappingURL=configSchema.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configSchema.cjs","sources":["../../../src/cli/configSchema.ts"],"sourcesContent":["import Joi from \"joi\";\n\nimport { Config } from \"./types\";\n\nexport const configSchema = Joi.object<Config>({\n\trepositoryName: Joi.string()\n\t\t.when(\"locales.fetchFromRepository\", {\n\t\t\tis: true,\n\t\t\tthen: Joi.required(),\n\t\t})\n\t\t.when(\"models.fetchFromRepository\", {\n\t\t\tis: true,\n\t\t\tthen: Joi.required(),\n\t\t}),\n\taccessToken: Joi.string(),\n\tcustomTypesAPIToken: Joi.string(),\n\n\toutput: Joi.string(),\n\n\ttypesProvider: Joi.string().allow(\"@prismicio/client\", \"@prismicio/client\"),\n\n\tclientIntegration: Joi.object({\n\t\tincludeCreateClientInterface: Joi.boolean(),\n\t\tincludeContentNamespace: Joi.boolean(),\n\t}),\n\n\tlocales: Joi.alternatives(\n\t\tJoi.array().items(Joi.string().required()),\n\t\tJoi.object({\n\t\t\tids: Joi.array().items(Joi.string().required()),\n\t\t\tfetchFromRepository: Joi.boolean(),\n\t\t}),\n\t),\n\n\tmodels: Joi.alternatives(\n\t\tJoi.array().items(Joi.string()),\n\t\tJoi.object({\n\t\t\tfiles: Joi.array().items(Joi.string()),\n\t\t\tfetchFromRepository: Joi.boolean(),\n\t\t}),\n\t),\n\n\tfields: Joi.object({\n\t\tembed: Joi.object({\n\t\t\tproviderTypes: Joi.object().pattern(\n\t\t\t\tJoi.string(),\n\t\t\t\tJoi.string().required(),\n\t\t\t),\n\t\t}),\n\t\tintegrationFields: Joi.object({\n\t\t\tcatalogTypes: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IAAI,OAAQ,GAAE,IAAI,OAAS,EAAA,SAAA,CAAU;AAAA,IAAA,CACxE;AAAA,EAAA,CACD;AACD,CAAA;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import Joi from "joi";
|
|
2
|
+
const configSchema = Joi.object({
|
|
3
|
+
repositoryName: Joi.string().when("locales.fetchFromRepository", {
|
|
4
|
+
is: true,
|
|
5
|
+
then: Joi.required()
|
|
6
|
+
}).when("models.fetchFromRepository", {
|
|
7
|
+
is: true,
|
|
8
|
+
then: Joi.required()
|
|
9
|
+
}),
|
|
10
|
+
accessToken: Joi.string(),
|
|
11
|
+
customTypesAPIToken: Joi.string(),
|
|
12
|
+
output: Joi.string(),
|
|
13
|
+
typesProvider: Joi.string().allow("@prismicio/client", "@prismicio/client"),
|
|
14
|
+
clientIntegration: Joi.object({
|
|
15
|
+
includeCreateClientInterface: Joi.boolean(),
|
|
16
|
+
includeContentNamespace: Joi.boolean()
|
|
17
|
+
}),
|
|
18
|
+
locales: Joi.alternatives(Joi.array().items(Joi.string().required()), Joi.object({
|
|
19
|
+
ids: Joi.array().items(Joi.string().required()),
|
|
20
|
+
fetchFromRepository: Joi.boolean()
|
|
21
|
+
})),
|
|
22
|
+
models: Joi.alternatives(Joi.array().items(Joi.string()), Joi.object({
|
|
23
|
+
files: Joi.array().items(Joi.string()),
|
|
24
|
+
fetchFromRepository: Joi.boolean()
|
|
25
|
+
})),
|
|
26
|
+
fields: Joi.object({
|
|
27
|
+
embed: Joi.object({
|
|
28
|
+
providerTypes: Joi.object().pattern(Joi.string(), Joi.string().required())
|
|
29
|
+
}),
|
|
30
|
+
integrationFields: Joi.object({
|
|
31
|
+
catalogTypes: Joi.object().pattern(Joi.string(), Joi.string().required())
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
export {
|
|
36
|
+
configSchema
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=configSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configSchema.js","sources":["../../../src/cli/configSchema.ts"],"sourcesContent":["import Joi from \"joi\";\n\nimport { Config } from \"./types\";\n\nexport const configSchema = Joi.object<Config>({\n\trepositoryName: Joi.string()\n\t\t.when(\"locales.fetchFromRepository\", {\n\t\t\tis: true,\n\t\t\tthen: Joi.required(),\n\t\t})\n\t\t.when(\"models.fetchFromRepository\", {\n\t\t\tis: true,\n\t\t\tthen: Joi.required(),\n\t\t}),\n\taccessToken: Joi.string(),\n\tcustomTypesAPIToken: Joi.string(),\n\n\toutput: Joi.string(),\n\n\ttypesProvider: Joi.string().allow(\"@prismicio/client\", \"@prismicio/client\"),\n\n\tclientIntegration: Joi.object({\n\t\tincludeCreateClientInterface: Joi.boolean(),\n\t\tincludeContentNamespace: Joi.boolean(),\n\t}),\n\n\tlocales: Joi.alternatives(\n\t\tJoi.array().items(Joi.string().required()),\n\t\tJoi.object({\n\t\t\tids: Joi.array().items(Joi.string().required()),\n\t\t\tfetchFromRepository: Joi.boolean(),\n\t\t}),\n\t),\n\n\tmodels: Joi.alternatives(\n\t\tJoi.array().items(Joi.string()),\n\t\tJoi.object({\n\t\t\tfiles: Joi.array().items(Joi.string()),\n\t\t\tfetchFromRepository: Joi.boolean(),\n\t\t}),\n\t),\n\n\tfields: Joi.object({\n\t\tembed: Joi.object({\n\t\t\tproviderTypes: Joi.object().pattern(\n\t\t\t\tJoi.string(),\n\t\t\t\tJoi.string().required(),\n\t\t\t),\n\t\t}),\n\t\tintegrationFields: Joi.object({\n\t\t\tcatalogTypes: Joi.object().pattern(Joi.string(), Joi.string().required()),\n\t\t}),\n\t}),\n});\n"],"names":[],"mappings":";AAIa,MAAA,eAAe,IAAI,OAAe;AAAA,EAC9C,gBAAgB,IAAI,SAClB,KAAK,+BAA+B;AAAA,IACpC,IAAI;AAAA,IACJ,MAAM,IAAI,SAAU;AAAA,EAAA,CACpB,EACA,KAAK,8BAA8B;AAAA,IACnC,IAAI;AAAA,IACJ,MA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
|
4
|
+
exports.NON_EDITABLE_FILE_HEADER = NON_EDITABLE_FILE_HEADER;
|
|
5
|
+
//# sourceMappingURL=constants.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.cjs","sources":["../../../src/cli/constants.ts"],"sourcesContent":["export const NON_EDITABLE_FILE_HEADER =\n\t\"// Code generated by prismic-ts-codegen. DO NOT EDIT.\";\n"],"names":[],"mappings":";;AAAO,MAAM,2BACZ;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const NON_EDITABLE_FILE_HEADER = "// Code generated by prismic-ts-codegen. DO NOT EDIT.";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../src/cli/constants.ts"],"sourcesContent":["export const NON_EDITABLE_FILE_HEADER =\n\t\"// Code generated by prismic-ts-codegen. DO NOT EDIT.\";\n"],"names":[],"mappings":"AAAO,MAAM,2BACZ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const _jiti = require("jiti");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const jiti = _jiti(process.cwd());
|
|
7
|
+
const loadModuleWithJiti = (id) => {
|
|
8
|
+
const mod = jiti(id);
|
|
9
|
+
return typeof mod === "object" && mod !== null && "default" in mod ? mod.default : mod;
|
|
10
|
+
};
|
|
11
|
+
const DEFAULT_CONFIG_PATHS = [
|
|
12
|
+
"prismicCodegen.config.ts",
|
|
13
|
+
"prismicCodegen.config.js"
|
|
14
|
+
];
|
|
15
|
+
const loadConfig = (config) => {
|
|
16
|
+
if (config.path) {
|
|
17
|
+
if (fs.existsSync(config.path)) {
|
|
18
|
+
return loadModuleWithJiti(path.resolve(config.path));
|
|
19
|
+
} else {
|
|
20
|
+
throw new Error(`Config file does not exist: ${config.path}`);
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
for (const configPath of DEFAULT_CONFIG_PATHS) {
|
|
24
|
+
if (fs.existsSync(configPath)) {
|
|
25
|
+
return loadModuleWithJiti(path.resolve(configPath));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return {};
|
|
30
|
+
};
|
|
31
|
+
exports.loadConfig = loadConfig;
|
|
32
|
+
//# sourceMappingURL=loadConfig.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadConfig.cjs","sources":["../../../src/cli/loadConfig.ts"],"sourcesContent":["import { existsSync } from \"fs\";\nimport _jiti from \"jiti\";\nimport { resolve as resolvePath } from \"path\";\n\nimport type { Config } from \"./types\";\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\n\t\t? mod.default\n\t\t: mod;\n};\n\nconst DEFAULT_CONFIG_PATHS = [\n\t\"prismicCodegen.config.ts\",\n\t\"prismicCodegen.config.js\",\n];\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"],"names":["existsSync","resolvePath"],"mappings":";;;;;AAMA,MAAM,OAAO,MAAM,QAAQ,IAAK,CAAA;AAEhC,MAAM,qBAAqB,CAAU,OAAuB;AACrD,QAAA,MAAM,KAAK,EAAE;AAEZ,SAAA,OAAO,QAAQ,YAAY,QAAQ,QAAQ,aAAa,MAC5D,IAAI,UACJ;AACJ;AAEA,MAAM,uBAAuB;AAAA,EAC5B;AAAA,EACA;;AAOY,MAAA,aAAa,CAAC,WAAoC;AAC9D,MAAI,OAAO,MAAM;AACZ,QAAAA,GAAA,WAAW,OAAO,IAAI,GAAG;AAC5B,aAAO,mBAAmBC,KAAA,QAAY,OAAO,IAAI,CAAC;AAAA,IAAA,OAC5C;AACN,YAAM,IAAI,MAAM,+BAA+B,OAAO,MAAM;AAAA,IAC5D;AAAA,EAAA,OACK;AACN,eAAW,cAAc,sBAAsB;AAC1C,UAAAD,GAAAA,WAAW,UAAU,GAAG;AACpB,eAAA,mBAAmBC,KAAAA,QAAY,UAAU,CAAC;AAAA,MACjD;AAAA,IACD;AAAA,EACD;AAGD,SAAO;AACR;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { existsSync } from "fs";
|
|
2
|
+
import _jiti from "jiti";
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
const jiti = _jiti(process.cwd());
|
|
5
|
+
const loadModuleWithJiti = (id) => {
|
|
6
|
+
const mod = jiti(id);
|
|
7
|
+
return typeof mod === "object" && mod !== null && "default" in mod ? mod.default : mod;
|
|
8
|
+
};
|
|
9
|
+
const DEFAULT_CONFIG_PATHS = [
|
|
10
|
+
"prismicCodegen.config.ts",
|
|
11
|
+
"prismicCodegen.config.js"
|
|
12
|
+
];
|
|
13
|
+
const loadConfig = (config) => {
|
|
14
|
+
if (config.path) {
|
|
15
|
+
if (existsSync(config.path)) {
|
|
16
|
+
return loadModuleWithJiti(resolve(config.path));
|
|
17
|
+
} else {
|
|
18
|
+
throw new Error(`Config file does not exist: ${config.path}`);
|
|
19
|
+
}
|
|
20
|
+
} else {
|
|
21
|
+
for (const configPath of DEFAULT_CONFIG_PATHS) {
|
|
22
|
+
if (existsSync(configPath)) {
|
|
23
|
+
return loadModuleWithJiti(resolve(configPath));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return {};
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
loadConfig
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=loadConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadConfig.js","sources":["../../../src/cli/loadConfig.ts"],"sourcesContent":["import { existsSync } from \"fs\";\nimport _jiti from \"jiti\";\nimport { resolve as resolvePath } from \"path\";\n\nimport type { Config } from \"./types\";\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\n\t\t? mod.default\n\t\t: mod;\n};\n\nconst DEFAULT_CONFIG_PATHS = [\n\t\"prismicCodegen.config.ts\",\n\t\"prismicCodegen.config.js\",\n];\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"],"names":["resolvePath"],"mappings":";;;AAMA,MAAM,OAAO,MAAM,QAAQ,IAAK,CAAA;AAEhC,MAAM,qBAAqB,CAAU,OAAuB;AACrD,QAAA,MAAM,KAAK,EAAE;AAEZ,SAAA,OAAO,QAAQ,YAAY,QAAQ,QAAQ,aAAa,MAC5D,IAAI,UACJ;AACJ;AAEA,MAAM,uBAAuB;AAAA,EAC5B;AAAA,EACA;;AAOY,MAAA,aAAa,CAAC,WAAoC;AAC9D,MAAI,OAAO,MAAM;AACZ,QAAA,WAAW,OAAO,IAAI,GAAG;AAC5B,aAAO,mBAAmBA,QAAY,OAAO,IAAI,CAAC;AAAA,IAAA,OAC5C;AACN,YAAM,IAAI,MAAM,+BAA+B,OAAO,MAAM;AAAA,IAC5D;AAAA,EAAA,OACK;AACN,eAAW,cAAc,sBAAsB;AAC1C,UAAA,WAAW,UAAU,GAAG;AACpB,eAAA,mBAAmBA,QAAY,UAAU,CAAC;AAAA,MACjD;AAAA,IACD;AAAA,EACD;AAGD,SAAO;AACR;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const prismic = require("@prismicio/client");
|
|
4
|
+
const fetch = require("node-fetch");
|
|
5
|
+
function _interopNamespaceDefault(e) {
|
|
6
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
7
|
+
if (e) {
|
|
8
|
+
for (const k in e) {
|
|
9
|
+
if (k !== "default") {
|
|
10
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: () => e[k]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
n.default = e;
|
|
19
|
+
return Object.freeze(n);
|
|
20
|
+
}
|
|
21
|
+
const prismic__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismic);
|
|
22
|
+
const loadLocaleIDs = async (config) => {
|
|
23
|
+
const localeIDs = new Set(config.localeIDs || []);
|
|
24
|
+
if ("repositoryName" in config && config.fetchFromRepository) {
|
|
25
|
+
const client = prismic__namespace.createClient(config.repositoryName, {
|
|
26
|
+
accessToken: config.accessToken,
|
|
27
|
+
fetch
|
|
28
|
+
});
|
|
29
|
+
const repository = await client.getRepository();
|
|
30
|
+
for (const language of repository.languages) {
|
|
31
|
+
localeIDs.add(language.id);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return [...localeIDs];
|
|
35
|
+
};
|
|
36
|
+
exports.loadLocaleIDs = loadLocaleIDs;
|
|
37
|
+
//# sourceMappingURL=loadLocaleIDs.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadLocaleIDs.cjs","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 (\n\tconfig: LoadLocalesConfig,\n): 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"],"names":["prismic"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAca,MAAA,gBAAgB,OAC5B,WACsB;AACtB,QAAM,YAAY,IAAI,IAAY,OAAO,aAAa,CAAE,CAAA;AAEpD,MAAA,oBAAoB,UAAU,OAAO,qBAAqB;AAC7D,UAAM,SAASA,mBAAQ,aAAa,OAAO,gBAAgB;AAAA,MAC1D,aAAa,OAAO;AAAA,MACpB;AAAA,IAAA,CACA;AAEK,UAAA,aAAa,MAAM,OAAO;AAErB,eAAA,YAAY,WAAW,WAAW;AAClC,gBAAA,IAAI,SAAS,EAAE;AAAA,IACzB;AAAA,EACD;AAEM,SAAA,CAAC,GAAG,SAAS;AACrB;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type LoadLocalesConfig = {
|
|
2
|
+
localeIDs?: string[];
|
|
3
|
+
} | {
|
|
4
|
+
localeIDs?: string[];
|
|
5
|
+
repositoryName: string;
|
|
6
|
+
accessToken: string;
|
|
7
|
+
fetchFromRepository?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const loadLocaleIDs: (config: LoadLocalesConfig) => Promise<string[]>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as prismic from "@prismicio/client";
|
|
2
|
+
import fetch from "node-fetch";
|
|
3
|
+
const loadLocaleIDs = async (config) => {
|
|
4
|
+
const localeIDs = new Set(config.localeIDs || []);
|
|
5
|
+
if ("repositoryName" in config && config.fetchFromRepository) {
|
|
6
|
+
const client = prismic.createClient(config.repositoryName, {
|
|
7
|
+
accessToken: config.accessToken,
|
|
8
|
+
fetch
|
|
9
|
+
});
|
|
10
|
+
const repository = await client.getRepository();
|
|
11
|
+
for (const language of repository.languages) {
|
|
12
|
+
localeIDs.add(language.id);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return [...localeIDs];
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
loadLocaleIDs
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=loadLocaleIDs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadLocaleIDs.js","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 (\n\tconfig: LoadLocalesConfig,\n): 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"],"names":[],"mappings":";;AAca,MAAA,gBAAgB,OAC5B,WACsB;AACtB,QAAM,YAAY,IAAI,IAAY,OAAO,aAAa,CAAE,CAAA;AAEpD,MAAA,oBAAoB,UAAU,OAAO,qBAAqB;AAC7D,UAAM,SAAS,QAAQ,aAAa,OAAO,gBAAgB;AAAA,MAC1D,aAAa,OAAO;AAAA,MACpB;AAAA,IAAA,CACA;AAEK,UAAA,aAAa,MAAM,OAAO;AAErB,eAAA,YAAY,WAAW,WAAW;AAClC,gBAAA,IAAI,SAAS,EAAE;AAAA,IACzB;AAAA,EACD;AAEM,SAAA,CAAC,GAAG,SAAS;AACrB;"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const prismicCT = require("@prismicio/custom-types-client");
|
|
4
|
+
const fg = require("fast-glob");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const fetch = require("node-fetch");
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
8
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
9
|
+
if (e) {
|
|
10
|
+
for (const k in e) {
|
|
11
|
+
if (k !== "default") {
|
|
12
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: () => e[k]
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
const prismicCT__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismicCT);
|
|
24
|
+
const isCustomTypeModel = (input) => {
|
|
25
|
+
return typeof input === "object" && input !== null && "json" in input;
|
|
26
|
+
};
|
|
27
|
+
const isSharedSliceModel = (input) => {
|
|
28
|
+
return typeof input === "object" && input !== null && "variations" in input;
|
|
29
|
+
};
|
|
30
|
+
const readJSONFromGlob = async (globs) => {
|
|
31
|
+
const paths = await fg(globs.split(",").map((path) => path.trim()));
|
|
32
|
+
return paths.map((path) => {
|
|
33
|
+
const raw = fs.readFileSync(path, "utf8");
|
|
34
|
+
return JSON.parse(raw);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const loadModels = async (config) => {
|
|
38
|
+
const customTypeModels = {};
|
|
39
|
+
const sharedSliceModels = {};
|
|
40
|
+
if ("customTypesAPIToken" in config) {
|
|
41
|
+
const customTypesClient = prismicCT__namespace.createClient({
|
|
42
|
+
repositoryName: config.repositoryName,
|
|
43
|
+
token: config.customTypesAPIToken,
|
|
44
|
+
fetch
|
|
45
|
+
});
|
|
46
|
+
if (config.fetchFromRepository) {
|
|
47
|
+
const [remoteCustomTypeModels, remoteSharedSliceModels] = await Promise.all([
|
|
48
|
+
customTypesClient.getAllCustomTypes(),
|
|
49
|
+
customTypesClient.getAllSharedSlices()
|
|
50
|
+
]);
|
|
51
|
+
for (const customTypeModel of remoteCustomTypeModels) {
|
|
52
|
+
customTypeModels[customTypeModel.id] = customTypeModel;
|
|
53
|
+
}
|
|
54
|
+
for (const sharedSliceModel of remoteSharedSliceModels) {
|
|
55
|
+
sharedSliceModels[sharedSliceModel.id] = sharedSliceModel;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (config.localPaths) {
|
|
60
|
+
const models = (await Promise.all(config.localPaths.map((glob) => readJSONFromGlob(glob)))).flat();
|
|
61
|
+
for (const model of models) {
|
|
62
|
+
if (isCustomTypeModel(model)) {
|
|
63
|
+
customTypeModels[model.id] = model;
|
|
64
|
+
} else if (isSharedSliceModel(model)) {
|
|
65
|
+
sharedSliceModels[model.id] = model;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
customTypeModels: Object.values(customTypeModels).sort((a, b) => {
|
|
71
|
+
return a.id.localeCompare(b.id);
|
|
72
|
+
}),
|
|
73
|
+
sharedSliceModels: Object.values(sharedSliceModels).sort((a, b) => {
|
|
74
|
+
return a.id.localeCompare(b.id);
|
|
75
|
+
})
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
exports.loadModels = loadModels;
|
|
79
|
+
//# sourceMappingURL=loadModels.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadModels.cjs","sources":["../../../src/cli/loadModels.ts"],"sourcesContent":["import * as prismicCT from \"@prismicio/custom-types-client\";\nimport type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport fg from \"fast-glob\";\nimport { readFileSync } from \"fs\";\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 (\n\tconfig: LoadModelsConfig,\n): 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] =\n\t\t\t\tawait Promise.all([\n\t\t\t\t\tcustomTypesClient.getAllCustomTypes(),\n\t\t\t\t\tcustomTypesClient.getAllSharedSlices(),\n\t\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"],"names":["readFileS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AG;AACZ,yBAAA,MAAM,EAAE,IAAI;AAAA,MAAA,WACnB,mBAAmB,KAAK,GAAG;AACnB,0BAAA,MAAM,EAAE,IAAI;AAAA,MAC9B;AAAA,IACD;AAAA,EACD;AAEM,SAAA;AAAA,IACN,kBAAkB,OAAO,OAAO,gBAAgB,EAAE,KAAK,CAAC,GAAG,MAAK;AAC/D,aAAO,EAAE,GAAG,cAAc,EAAE,EAAE;AAAA,IAAA,CAC9B;AAAA,IACD,mBAAmB,OAAO,OAAO,iBAAiB,EAAE,KAAK,CAAC,GAAG,MAAK;AACjE,aAAO,EAAE,GAAG,cAAc,EAAE,EAAE;AAAA,IAAA,CAC9B;AAAA,EAAA;AAEH;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CustomTypeModel, SharedSliceModel } from "@prismicio/client";
|
|
2
|
+
type LoadModelsConfig = {
|
|
3
|
+
localPaths?: string[];
|
|
4
|
+
} | {
|
|
5
|
+
localPaths?: string[];
|
|
6
|
+
repositoryName: string;
|
|
7
|
+
customTypesAPIToken: string;
|
|
8
|
+
fetchFromRepository?: boolean;
|
|
9
|
+
};
|
|
10
|
+
type LoadModelsReturnType = {
|
|
11
|
+
customTypeModels: CustomTypeModel[];
|
|
12
|
+
sharedSliceModels: SharedSliceModel[];
|
|
13
|
+
};
|
|
14
|
+
export declare const loadModels: (config: LoadModelsConfig) => Promise<LoadModelsReturnType>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as prismicCT from "@prismicio/custom-types-client";
|
|
2
|
+
import fg from "fast-glob";
|
|
3
|
+
import { readFileSync } from "fs";
|
|
4
|
+
import fetch from "node-fetch";
|
|
5
|
+
const isCustomTypeModel = (input) => {
|
|
6
|
+
return typeof input === "object" && input !== null && "json" in input;
|
|
7
|
+
};
|
|
8
|
+
const isSharedSliceModel = (input) => {
|
|
9
|
+
return typeof input === "object" && input !== null && "variations" in input;
|
|
10
|
+
};
|
|
11
|
+
const readJSONFromGlob = async (globs) => {
|
|
12
|
+
const paths = await fg(globs.split(",").map((path) => path.trim()));
|
|
13
|
+
return paths.map((path) => {
|
|
14
|
+
const raw = readFileSync(path, "utf8");
|
|
15
|
+
return JSON.parse(raw);
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
const loadModels = async (config) => {
|
|
19
|
+
const customTypeModels = {};
|
|
20
|
+
const sharedSliceModels = {};
|
|
21
|
+
if ("customTypesAPIToken" in config) {
|
|
22
|
+
const customTypesClient = prismicCT.createClient({
|
|
23
|
+
repositoryName: config.repositoryName,
|
|
24
|
+
token: config.customTypesAPIToken,
|
|
25
|
+
fetch
|
|
26
|
+
});
|
|
27
|
+
if (config.fetchFromRepository) {
|
|
28
|
+
const [remoteCustomTypeModels, remoteSharedSliceModels] = await Promise.all([
|
|
29
|
+
customTypesClient.getAllCustomTypes(),
|
|
30
|
+
customTypesClient.getAllSharedSlices()
|
|
31
|
+
]);
|
|
32
|
+
for (const customTypeModel of remoteCustomTypeModels) {
|
|
33
|
+
customTypeModels[customTypeModel.id] = customTypeModel;
|
|
34
|
+
}
|
|
35
|
+
for (const sharedSliceModel of remoteSharedSliceModels) {
|
|
36
|
+
sharedSliceModels[sharedSliceModel.id] = sharedSliceModel;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (config.localPaths) {
|
|
41
|
+
const models = (await Promise.all(config.localPaths.map((glob) => readJSONFromGlob(glob)))).flat();
|
|
42
|
+
for (const model of models) {
|
|
43
|
+
if (isCustomTypeModel(model)) {
|
|
44
|
+
customTypeModels[model.id] = model;
|
|
45
|
+
} else if (isSharedSliceModel(model)) {
|
|
46
|
+
sharedSliceModels[model.id] = model;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
customTypeModels: Object.values(customTypeModels).sort((a, b) => {
|
|
52
|
+
return a.id.localeCompare(b.id);
|
|
53
|
+
}),
|
|
54
|
+
sharedSliceModels: Object.values(sharedSliceModels).sort((a, b) => {
|
|
55
|
+
return a.id.localeCompare(b.id);
|
|
56
|
+
})
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export {
|
|
60
|
+
loadModels
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=loadModels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadModels.js","sources":["../../../src/cli/loadModels.ts"],"sourcesContent":["import * as prismicCT from \"@prismicio/custom-types-client\";\nimport type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport fg from \"fast-glob\";\nimport { readFileSync } from \"fs\";\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 (\n\tconfig: LoadModelsConfig,\n): 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] =\n\t\t\t\tawait Promise.all([\n\t\t\t\t\tcustomTypesClient.getAllCustomTypes(),\n\t\t\t\t\tcustomTypesClient.getAllSharedSlices(),\n\t\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"],"names":[],"mappings":";;;;AAMA,MAAM,oBAAoB,CAAC,UAA4C;AACtE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU;AACjE;AAEA,MAAM,qBAAqB,CAAC,UAA6C;AACxE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,gBAAgB;AACvE;AAEA,MAAM,mBAAmB,OAAU,UAA+B;AACjE,QAAM,QAAQ,MAAM,GAAG,MAAM,MAAM,GAAG,EAAE,IAAI,CAAC,SAAS,KAAK,KAAA,CAAM,CAAC;AAE3D,SAAA,M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