prismic-ts-codegen 0.1.2 → 0.1.3-alpha.0
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/cli.mjs +45 -24
- package/dist/index.cjs +40 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -0
- package/dist/index.js +40 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/configSchema.ts +1 -0
- package/src/cli/index.ts +3 -1
- package/src/cli/types.ts +15 -0
- package/src/generateTypes.ts +55 -24
package/src/generateTypes.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type GenerateTypesConfig = {
|
|
|
15
15
|
fieldConfigs?: FieldConfigs;
|
|
16
16
|
clientIntegration?: {
|
|
17
17
|
includeCreateClientInterface?: boolean;
|
|
18
|
+
includeContentNamespace?: boolean;
|
|
18
19
|
};
|
|
19
20
|
};
|
|
20
21
|
|
|
@@ -34,7 +35,7 @@ export const generateTypes = (config: GenerateTypesConfig = {}) => {
|
|
|
34
35
|
|
|
35
36
|
sourceFile.addStatements(BLANK_LINE_IDENTIFIER);
|
|
36
37
|
|
|
37
|
-
sourceFile.addTypeAlias({
|
|
38
|
+
const simplifyTypeAlias = sourceFile.addTypeAlias({
|
|
38
39
|
name: "Simplify",
|
|
39
40
|
typeParameters: [
|
|
40
41
|
{
|
|
@@ -77,7 +78,10 @@ export const generateTypes = (config: GenerateTypesConfig = {}) => {
|
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
if (
|
|
81
|
+
if (
|
|
82
|
+
config.clientIntegration?.includeCreateClientInterface ||
|
|
83
|
+
config.clientIntegration?.includeContentNamespace
|
|
84
|
+
) {
|
|
81
85
|
sourceFile.addImportDeclaration({
|
|
82
86
|
moduleSpecifier: "@prismicio/client",
|
|
83
87
|
namespaceImport: "prismic",
|
|
@@ -90,28 +94,55 @@ export const generateTypes = (config: GenerateTypesConfig = {}) => {
|
|
|
90
94
|
declarationKind: ModuleDeclarationKind.Module,
|
|
91
95
|
});
|
|
92
96
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
97
|
+
if (config.clientIntegration.includeCreateClientInterface) {
|
|
98
|
+
clientModuleDeclaration.addInterface({
|
|
99
|
+
name: "CreateClient",
|
|
100
|
+
callSignatures: [
|
|
101
|
+
{
|
|
102
|
+
parameters: [
|
|
103
|
+
{
|
|
104
|
+
name: "repositoryNameOrEndpoint",
|
|
105
|
+
type: "string",
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: "options",
|
|
109
|
+
type: "prismic.ClientConfig",
|
|
110
|
+
hasQuestionToken: true,
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
returnType:
|
|
114
|
+
(config.customTypeModels?.length || 0) > 0
|
|
115
|
+
? "prismic.Client<AllDocumentTypes>"
|
|
116
|
+
: "prismic.Client",
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (config.clientIntegration.includeContentNamespace) {
|
|
123
|
+
const contentNamespaceDeclaration = clientModuleDeclaration.addModule({
|
|
124
|
+
name: "Content",
|
|
125
|
+
declarationKind: ModuleDeclarationKind.Namespace,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const exportSymbols = sourceFile
|
|
129
|
+
.getExportSymbols()
|
|
130
|
+
.filter((exportSymbol) => {
|
|
131
|
+
// The Simplify utility type should not
|
|
132
|
+
// be exported, but it is included in
|
|
133
|
+
// `getExportSymbols()`'s result.
|
|
134
|
+
return exportSymbol.getName() !== simplifyTypeAlias.getName();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
contentNamespaceDeclaration.addExportDeclaration({
|
|
138
|
+
isTypeOnly: true,
|
|
139
|
+
namedExports: exportSymbols.map((exportSymbol) => {
|
|
140
|
+
return {
|
|
141
|
+
name: exportSymbol.getName(),
|
|
142
|
+
};
|
|
143
|
+
}),
|
|
144
|
+
});
|
|
145
|
+
}
|
|
115
146
|
}
|
|
116
147
|
|
|
117
148
|
return getSourceFileText(sourceFile);
|