@autorest/typescript 6.0.0-beta.15 → 6.0.0-beta.16
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/CHANGELOG.md +5 -0
- package/README.md +37 -3
- package/dist/src/autorestSession.d.ts +8 -3
- package/dist/src/autorestSession.d.ts.map +1 -1
- package/dist/src/autorestSession.js +3 -9
- package/dist/src/autorestSession.js.map +1 -1
- package/dist/src/conflictResolver.d.ts.map +1 -1
- package/dist/src/conflictResolver.js.map +1 -1
- package/dist/src/generators/clientFileGenerator.d.ts.map +1 -1
- package/dist/src/generators/clientFileGenerator.js +181 -31
- package/dist/src/generators/clientFileGenerator.js.map +1 -1
- package/dist/src/generators/indexGenerator.d.ts.map +1 -1
- package/dist/src/generators/indexGenerator.js +70 -9
- package/dist/src/generators/indexGenerator.js.map +1 -1
- package/dist/src/generators/modelsGenerator.d.ts.map +1 -1
- package/dist/src/generators/modelsGenerator.js +20 -2
- package/dist/src/generators/modelsGenerator.js.map +1 -1
- package/dist/src/generators/operationGenerator.js +6 -6
- package/dist/src/generators/operationGenerator.js.map +1 -1
- package/dist/src/generators/samples/sampleEnv.hbs +4 -0
- package/dist/src/generators/samples/sampleEnvGenerator.d.ts +3 -0
- package/dist/src/generators/samples/sampleEnvGenerator.d.ts.map +1 -0
- package/dist/src/generators/samples/sampleEnvGenerator.js +17 -0
- package/dist/src/generators/samples/sampleEnvGenerator.js.map +1 -0
- package/dist/src/generators/samples/sampleGenerator.d.ts +13 -0
- package/dist/src/generators/samples/sampleGenerator.d.ts.map +1 -0
- package/dist/src/generators/samples/sampleGenerator.js +43 -0
- package/dist/src/generators/samples/sampleGenerator.js.map +1 -0
- package/dist/src/generators/static/README.md.hbs +19 -0
- package/dist/src/generators/static/karma.conf.js.hbs +141 -0
- package/dist/src/generators/static/karmaConfigFileGenerator.d.ts +3 -0
- package/dist/src/generators/static/karmaConfigFileGenerator.d.ts.map +1 -0
- package/dist/src/generators/static/karmaConfigFileGenerator.js +23 -0
- package/dist/src/generators/static/karmaConfigFileGenerator.js.map +1 -0
- package/dist/src/generators/static/packageFileGenerator.d.ts.map +1 -1
- package/dist/src/generators/static/packageFileGenerator.js +90 -14
- package/dist/src/generators/static/packageFileGenerator.js.map +1 -1
- package/dist/src/generators/static/rollupConfigFileGenerator.d.ts.map +1 -1
- package/dist/src/generators/static/rollupConfigFileGenerator.js +7 -70
- package/dist/src/generators/static/rollupConfigFileGenerator.js.map +1 -1
- package/dist/src/generators/static/samples.ts.hbs +49 -0
- package/dist/src/generators/static/tsConfigFileGenerator.d.ts.map +1 -1
- package/dist/src/generators/static/tsConfigFileGenerator.js +9 -10
- package/dist/src/generators/static/tsConfigFileGenerator.js.map +1 -1
- package/dist/src/generators/test/envBrowserFileGenerator.d.ts +3 -0
- package/dist/src/generators/test/envBrowserFileGenerator.d.ts.map +1 -0
- package/dist/src/generators/test/envBrowserFileGenerator.js +15 -0
- package/dist/src/generators/test/envBrowserFileGenerator.js.map +1 -0
- package/dist/src/generators/test/envFileGenerator.d.ts +3 -0
- package/dist/src/generators/test/envFileGenerator.d.ts.map +1 -0
- package/dist/src/generators/test/envFileGenerator.js +23 -0
- package/dist/src/generators/test/envFileGenerator.js.map +1 -0
- package/dist/src/generators/test/recordedClientFileGenerator.d.ts +3 -0
- package/dist/src/generators/test/recordedClientFileGenerator.d.ts.map +1 -0
- package/dist/src/generators/test/recordedClientFileGenerator.js +23 -0
- package/dist/src/generators/test/recordedClientFileGenerator.js.map +1 -0
- package/dist/src/generators/test/rlcEnv.ts.hbs +3 -0
- package/dist/src/generators/test/rlcRecordedClient.ts.hbs +35 -0
- package/dist/src/generators/test/rlcSampleTest.spec.ts.hbs +19 -0
- package/dist/src/generators/{static → test}/sampleTest.ts.hbs +0 -0
- package/dist/src/generators/test/sampleTestGenerator.d.ts.map +1 -1
- package/dist/src/generators/test/sampleTestGenerator.js +23 -7
- package/dist/src/generators/test/sampleTestGenerator.js.map +1 -1
- package/dist/src/generators/utils/pagingOperations.d.ts +5 -0
- package/dist/src/generators/utils/pagingOperations.d.ts.map +1 -1
- package/dist/src/generators/utils/pagingOperations.js +2 -1
- package/dist/src/generators/utils/pagingOperations.js.map +1 -1
- package/dist/src/main.d.ts +2 -2
- package/dist/src/main.d.ts.map +1 -1
- package/dist/src/main.js +3 -3
- package/dist/src/main.js.map +1 -1
- package/dist/src/models/clientDetails.d.ts +3 -0
- package/dist/src/models/clientDetails.d.ts.map +1 -1
- package/dist/src/models/modelDetails.d.ts +2 -2
- package/dist/src/models/modelDetails.d.ts.map +1 -1
- package/dist/src/models/operationDetails.d.ts +1 -0
- package/dist/src/models/operationDetails.d.ts.map +1 -1
- package/dist/src/models/sampleDetails.d.ts +22 -0
- package/dist/src/models/sampleDetails.d.ts.map +1 -0
- package/dist/src/models/sampleDetails.js +3 -0
- package/dist/src/models/sampleDetails.js.map +1 -0
- package/dist/src/restLevelClient/generateClient.d.ts +1 -1
- package/dist/src/restLevelClient/generateClient.d.ts.map +1 -1
- package/dist/src/restLevelClient/generateClient.js +48 -164
- package/dist/src/restLevelClient/generateClient.js.map +1 -1
- package/dist/src/restLevelClient/generateClientDefinition.d.ts +6 -0
- package/dist/src/restLevelClient/generateClientDefinition.d.ts.map +1 -0
- package/dist/src/restLevelClient/generateClientDefinition.js +231 -0
- package/dist/src/restLevelClient/generateClientDefinition.js.map +1 -0
- package/dist/src/restLevelClient/generateMethodShortcuts.d.ts +8 -0
- package/dist/src/restLevelClient/generateMethodShortcuts.d.ts.map +1 -0
- package/dist/src/restLevelClient/generateMethodShortcuts.js +70 -0
- package/dist/src/restLevelClient/generateMethodShortcuts.js.map +1 -0
- package/dist/src/restLevelClient/generateObjectTypes.d.ts.map +1 -1
- package/dist/src/restLevelClient/generateObjectTypes.js.map +1 -1
- package/dist/src/restLevelClient/generatePagingHelper.d.ts.map +1 -1
- package/dist/src/restLevelClient/generatePagingHelper.js +2 -1
- package/dist/src/restLevelClient/generatePagingHelper.js.map +1 -1
- package/dist/src/restLevelClient/generateParameterTypes.d.ts.map +1 -1
- package/dist/src/restLevelClient/generateParameterTypes.js +104 -18
- package/dist/src/restLevelClient/generateParameterTypes.js.map +1 -1
- package/dist/src/restLevelClient/generatePollingHelper.d.ts.map +1 -1
- package/dist/src/restLevelClient/generatePollingHelper.js +3 -1
- package/dist/src/restLevelClient/generatePollingHelper.js.map +1 -1
- package/dist/src/restLevelClient/generateResponseTypes.d.ts.map +1 -1
- package/dist/src/restLevelClient/generateResponseTypes.js +4 -1
- package/dist/src/restLevelClient/generateResponseTypes.js.map +1 -1
- package/dist/src/restLevelClient/generateRestLevel.d.ts.map +1 -1
- package/dist/src/restLevelClient/generateRestLevel.js +19 -3
- package/dist/src/restLevelClient/generateRestLevel.js.map +1 -1
- package/dist/src/restLevelClient/generateSchemaTypes.d.ts.map +1 -1
- package/dist/src/restLevelClient/generateSchemaTypes.js +5 -2
- package/dist/src/restLevelClient/generateSchemaTypes.js.map +1 -1
- package/dist/src/restLevelClient/generateTopLevelIndexFile.d.ts +4 -0
- package/dist/src/restLevelClient/generateTopLevelIndexFile.d.ts.map +1 -0
- package/dist/src/restLevelClient/generateTopLevelIndexFile.js +41 -0
- package/dist/src/restLevelClient/generateTopLevelIndexFile.js.map +1 -0
- package/dist/src/restLevelClient/helpers/operationHelpers.d.ts +10 -0
- package/dist/src/restLevelClient/helpers/operationHelpers.d.ts.map +1 -0
- package/dist/src/restLevelClient/helpers/operationHelpers.js +64 -0
- package/dist/src/restLevelClient/helpers/operationHelpers.js.map +1 -0
- package/dist/src/restLevelClient/interfaces.d.ts +24 -0
- package/dist/src/restLevelClient/interfaces.d.ts.map +1 -0
- package/dist/src/restLevelClient/interfaces.js +3 -0
- package/dist/src/restLevelClient/interfaces.js.map +1 -0
- package/dist/src/restLevelClient/operationHelpers.d.ts.map +1 -1
- package/dist/src/restLevelClient/operationHelpers.js +4 -1
- package/dist/src/restLevelClient/operationHelpers.js.map +1 -1
- package/dist/src/restLevelClient/schemaHelpers.d.ts.map +1 -1
- package/dist/src/restLevelClient/schemaHelpers.js +4 -1
- package/dist/src/restLevelClient/schemaHelpers.js.map +1 -1
- package/dist/src/transforms/operationTransforms.d.ts.map +1 -1
- package/dist/src/transforms/operationTransforms.js +1 -0
- package/dist/src/transforms/operationTransforms.js.map +1 -1
- package/dist/src/transforms/samplesTransforms.d.ts +7 -0
- package/dist/src/transforms/samplesTransforms.d.ts.map +1 -0
- package/dist/src/transforms/samplesTransforms.js +283 -0
- package/dist/src/transforms/samplesTransforms.js.map +1 -0
- package/dist/src/transforms/transforms.d.ts +1 -2
- package/dist/src/transforms/transforms.d.ts.map +1 -1
- package/dist/src/transforms/transforms.js +4 -3
- package/dist/src/transforms/transforms.js.map +1 -1
- package/dist/src/typescriptGenerator.d.ts +2 -2
- package/dist/src/typescriptGenerator.d.ts.map +1 -1
- package/dist/src/typescriptGenerator.js +18 -7
- package/dist/src/typescriptGenerator.js.map +1 -1
- package/dist/src/utils/autorestOptions.d.ts +2 -2
- package/dist/src/utils/autorestOptions.d.ts.map +1 -1
- package/dist/src/utils/autorestOptions.js +70 -30
- package/dist/src/utils/autorestOptions.js.map +1 -1
- package/dist/src/utils/nameUtils.d.ts +6 -2
- package/dist/src/utils/nameUtils.d.ts.map +1 -1
- package/dist/src/utils/nameUtils.js +9 -5
- package/dist/src/utils/nameUtils.js.map +1 -1
- package/dist/src/utils/schemaHelpers.js +8 -3
- package/dist/src/utils/schemaHelpers.js.map +1 -1
- package/package.json +11 -5
- package/src/autorestSession.ts +16 -15
- package/src/conflictResolver.ts +0 -1
- package/src/generators/clientFileGenerator.ts +262 -33
- package/src/generators/indexGenerator.ts +78 -9
- package/src/generators/modelsGenerator.ts +21 -1
- package/src/generators/operationGenerator.ts +7 -7
- package/src/generators/samples/sampleEnv.hbs +4 -0
- package/src/generators/samples/sampleEnvGenerator.ts +14 -0
- package/src/generators/samples/sampleGenerator.ts +50 -0
- package/src/generators/static/README.md.hbs +19 -0
- package/src/generators/static/karma.conf.js.hbs +141 -0
- package/src/generators/static/karmaConfigFileGenerator.ts +20 -0
- package/src/generators/static/packageFileGenerator.ts +99 -14
- package/src/generators/static/rollupConfigFileGenerator.ts +7 -70
- package/src/generators/static/samples.ts.hbs +49 -0
- package/src/generators/static/tsConfigFileGenerator.ts +12 -12
- package/src/generators/test/envBrowserFileGenerator.ts +14 -0
- package/src/generators/test/envFileGenerator.ts +22 -0
- package/src/generators/test/recordedClientFileGenerator.ts +22 -0
- package/src/generators/test/rlcEnv.ts.hbs +3 -0
- package/src/generators/test/rlcRecordedClient.ts.hbs +35 -0
- package/src/generators/test/rlcSampleTest.spec.ts.hbs +19 -0
- package/src/generators/{static → test}/sampleTest.ts.hbs +0 -0
- package/src/generators/test/sampleTestGenerator.ts +23 -8
- package/src/generators/utils/pagingOperations.ts +1 -1
- package/src/main.ts +9 -5
- package/src/models/clientDetails.ts +3 -0
- package/src/models/modelDetails.ts +2 -2
- package/src/models/operationDetails.ts +1 -0
- package/src/models/sampleDetails.ts +22 -0
- package/src/restLevelClient/generateClient.ts +57 -253
- package/src/restLevelClient/generateClientDefinition.ts +343 -0
- package/src/restLevelClient/generateMethodShortcuts.ts +121 -0
- package/src/restLevelClient/generateObjectTypes.ts +1 -3
- package/src/restLevelClient/generatePagingHelper.ts +3 -2
- package/src/restLevelClient/generateParameterTypes.ts +155 -25
- package/src/restLevelClient/generatePollingHelper.ts +3 -3
- package/src/restLevelClient/generateResponseTypes.ts +4 -1
- package/src/restLevelClient/generateRestLevel.ts +24 -6
- package/src/restLevelClient/generateSchemaTypes.ts +5 -3
- package/src/restLevelClient/generateTopLevelIndexFile.ts +41 -0
- package/src/restLevelClient/helpers/operationHelpers.ts +93 -0
- package/src/restLevelClient/interfaces.ts +26 -0
- package/src/restLevelClient/operationHelpers.ts +8 -2
- package/src/restLevelClient/schemaHelpers.ts +4 -2
- package/src/transforms/operationTransforms.ts +1 -0
- package/src/transforms/samplesTransforms.ts +300 -0
- package/src/transforms/transforms.ts +6 -6
- package/src/typescriptGenerator.ts +19 -10
- package/src/utils/autorestOptions.ts +121 -58
- package/src/utils/nameUtils.ts +16 -8
- package/src/utils/schemaHelpers.ts +2 -2
- package/dist/src/generators/clientContextFileGenerator.d.ts +0 -5
- package/dist/src/generators/clientContextFileGenerator.d.ts.map +0 -1
- package/dist/src/generators/clientContextFileGenerator.js +0 -263
- package/dist/src/generators/clientContextFileGenerator.js.map +0 -1
- package/dist/src/restLevelClient/helpers/getOperationParameters.d.ts +0 -6
- package/dist/src/restLevelClient/helpers/getOperationParameters.d.ts.map +0 -1
- package/dist/src/restLevelClient/helpers/getOperationParameters.js +0 -29
- package/dist/src/restLevelClient/helpers/getOperationParameters.js.map +0 -1
- package/src/generators/clientContextFileGenerator.ts +0 -405
- package/src/restLevelClient/helpers/getOperationParameters.ts +0 -37
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
Project,
|
|
6
6
|
PropertyDeclarationStructure,
|
|
7
7
|
ClassDeclaration,
|
|
8
|
-
SourceFile
|
|
8
|
+
SourceFile,
|
|
9
|
+
CodeBlockWriter
|
|
9
10
|
} from "ts-morph";
|
|
10
11
|
import { ClientDetails } from "../models/clientDetails";
|
|
11
12
|
import {
|
|
@@ -25,6 +26,9 @@ import { getAllModelsNames } from "./utils/responseTypeUtils";
|
|
|
25
26
|
import { addTracingOperationImports } from "./utils/tracingUtils";
|
|
26
27
|
import { addPagingEsNextRef, addPagingImports } from "./utils/pagingOperations";
|
|
27
28
|
import { getAutorestOptions } from "../autorestSession";
|
|
29
|
+
import { ParameterDetails } from "../models/parameterDetails";
|
|
30
|
+
import { EndpointDetails } from "../transforms/urlTransforms";
|
|
31
|
+
import { PackageDetails } from "../models/packageDetails";
|
|
28
32
|
|
|
29
33
|
type OperationDeclarationDetails = { name: string; typeName: string };
|
|
30
34
|
|
|
@@ -33,9 +37,10 @@ export function generateClient(clientDetails: ClientDetails, project: Project) {
|
|
|
33
37
|
useCoreV2,
|
|
34
38
|
hideClients,
|
|
35
39
|
srcPath,
|
|
36
|
-
addCredentials
|
|
40
|
+
addCredentials,
|
|
41
|
+
packageDetails,
|
|
42
|
+
coreHttpCompatMode
|
|
37
43
|
} = getAutorestOptions();
|
|
38
|
-
const clientContextClassName = `${clientDetails.className}Context`;
|
|
39
44
|
const hasMappers = !!clientDetails.mappers.length;
|
|
40
45
|
|
|
41
46
|
// Check if there are any client level operations
|
|
@@ -72,37 +77,44 @@ export function generateClient(clientDetails: ClientDetails, project: Project) {
|
|
|
72
77
|
}
|
|
73
78
|
);
|
|
74
79
|
|
|
80
|
+
!useCoreV2 && writePackageInfo(clientFile, packageDetails);
|
|
81
|
+
|
|
75
82
|
const flattenedInlineOperations = inlineOperations.reduce<OperationDetails[]>(
|
|
76
83
|
(acc, curr) => (acc = [...acc, ...curr.operations]),
|
|
77
84
|
[]
|
|
78
85
|
);
|
|
79
86
|
|
|
87
|
+
if (!useCoreV2) {
|
|
88
|
+
clientFile.addImportDeclaration({
|
|
89
|
+
namespaceImport: "coreHttp",
|
|
90
|
+
moduleSpecifier: "@azure/core-http"
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
clientFile.addImportDeclaration({
|
|
94
|
+
namespaceImport: "coreClient",
|
|
95
|
+
moduleSpecifier: "@azure/core-client"
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
80
99
|
if (hasCredentials || hasInlineOperations || !hasClientOptionalParams) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
});
|
|
91
|
-
clientFile.addImportDeclaration({
|
|
92
|
-
namespaceImport: "coreRestPipeline",
|
|
93
|
-
moduleSpecifier: "@azure/core-rest-pipeline"
|
|
94
|
-
});
|
|
100
|
+
clientFile.addImportDeclaration({
|
|
101
|
+
namespaceImport: "coreRestPipeline",
|
|
102
|
+
moduleSpecifier: "@azure/core-rest-pipeline"
|
|
103
|
+
});
|
|
104
|
+
clientFile.addImportDeclaration({
|
|
105
|
+
namespaceImport: "coreTracing",
|
|
106
|
+
moduleSpecifier: "@azure/core-tracing"
|
|
107
|
+
});
|
|
108
|
+
if (hasCredentials) {
|
|
95
109
|
clientFile.addImportDeclaration({
|
|
96
|
-
namespaceImport: "
|
|
97
|
-
moduleSpecifier: "@azure/core-
|
|
110
|
+
namespaceImport: "coreAuth",
|
|
111
|
+
moduleSpecifier: "@azure/core-auth"
|
|
98
112
|
});
|
|
99
|
-
if (hasCredentials) {
|
|
100
|
-
clientFile.addImportDeclaration({
|
|
101
|
-
namespaceImport: "coreAuth",
|
|
102
|
-
moduleSpecifier: "@azure/core-auth"
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
113
|
}
|
|
114
|
+
clientFile.addImportDeclaration({
|
|
115
|
+
namespaceImport: "coreHttpCompat",
|
|
116
|
+
moduleSpecifier: "@azure/core-http-compat"
|
|
117
|
+
});
|
|
106
118
|
}
|
|
107
119
|
|
|
108
120
|
addPagingEsNextRef(flattenedInlineOperations, clientFile);
|
|
@@ -163,14 +175,13 @@ export function generateClient(clientDetails: ClientDetails, project: Project) {
|
|
|
163
175
|
});
|
|
164
176
|
}
|
|
165
177
|
|
|
166
|
-
clientFile.addImportDeclaration({
|
|
167
|
-
namedImports: [clientContextClassName],
|
|
168
|
-
moduleSpecifier: `./${clientDetails.sourceFileName}Context`
|
|
169
|
-
});
|
|
170
|
-
|
|
171
178
|
const clientClass = clientFile.addClass({
|
|
172
179
|
name: clientDetails.className,
|
|
173
|
-
extends:
|
|
180
|
+
extends: !useCoreV2
|
|
181
|
+
? "coreHttp.ServiceClient"
|
|
182
|
+
: coreHttpCompatMode
|
|
183
|
+
? "coreHttpCompat.ExtendedServiceClient"
|
|
184
|
+
: "coreClient.ServiceClient",
|
|
174
185
|
isExported: true
|
|
175
186
|
});
|
|
176
187
|
|
|
@@ -185,7 +196,10 @@ export function generateClient(clientDetails: ClientDetails, project: Project) {
|
|
|
185
196
|
}
|
|
186
197
|
|
|
187
198
|
const importedModels = new Set<string>();
|
|
188
|
-
|
|
199
|
+
const clientParams = clientDetails.parameters.filter(
|
|
200
|
+
param => param.implementationLocation === ImplementationLocation.Client
|
|
201
|
+
);
|
|
202
|
+
writeClassProperties(clientClass, clientParams, importedModels);
|
|
189
203
|
writeConstructor(clientDetails, clientClass, importedModels);
|
|
190
204
|
writeClientOperations(
|
|
191
205
|
clientFile,
|
|
@@ -206,6 +220,26 @@ export function generateClient(clientDetails: ClientDetails, project: Project) {
|
|
|
206
220
|
clientFile.fixUnusedIdentifiers();
|
|
207
221
|
}
|
|
208
222
|
|
|
223
|
+
function writeClassProperties(
|
|
224
|
+
clientClass: ClassDeclaration,
|
|
225
|
+
clientParams: ParameterDetails[],
|
|
226
|
+
importedModels: Set<string>
|
|
227
|
+
) {
|
|
228
|
+
const params = clientParams.filter(p => !p.isSynthetic);
|
|
229
|
+
params.forEach(({ typeDetails }) =>
|
|
230
|
+
typeDetails.usedModels.forEach(model => importedModels.add(model))
|
|
231
|
+
);
|
|
232
|
+
clientClass.addProperties(
|
|
233
|
+
params.map(param => {
|
|
234
|
+
return {
|
|
235
|
+
name: param.name,
|
|
236
|
+
type: param.typeDetails.typeName,
|
|
237
|
+
hasQuestionToken: !param.required
|
|
238
|
+
} as PropertyDeclarationStructure;
|
|
239
|
+
})
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
209
243
|
export function checkForNameCollisions(
|
|
210
244
|
importedOperations: OperationGroupDetails[],
|
|
211
245
|
inlineOperations: OperationGroupDetails[]
|
|
@@ -285,8 +319,57 @@ function writeConstructor(
|
|
|
285
319
|
]
|
|
286
320
|
});
|
|
287
321
|
|
|
322
|
+
const { useCoreV2 } = getAutorestOptions();
|
|
323
|
+
const hasLro = clientDetails.operationGroups.some(og =>
|
|
324
|
+
og.operations.some(o => o.isLro)
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
const clientParams = clientDetails.parameters.filter(
|
|
328
|
+
param => param.implementationLocation === ImplementationLocation.Client
|
|
329
|
+
);
|
|
330
|
+
const addBlankLine = true;
|
|
331
|
+
const requiredParameters = getRequiredParamAssignments(requiredParams);
|
|
332
|
+
const constantParameters = getConstantClientParamAssignments(clientParams);
|
|
333
|
+
|
|
334
|
+
const writeStatement = (content: string, shouldAddBlankLine = false) => (
|
|
335
|
+
writer: CodeBlockWriter
|
|
336
|
+
) => {
|
|
337
|
+
if (content) {
|
|
338
|
+
writer.writeLine(content);
|
|
339
|
+
shouldAddBlankLine && writer.blankLine();
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
const writeStatements = (lines: string[], shouldAddBlankLine = false) => (
|
|
344
|
+
writer: CodeBlockWriter
|
|
345
|
+
) => {
|
|
346
|
+
lines.forEach(line => writer.writeLine(line));
|
|
347
|
+
shouldAddBlankLine && writer.blankLine();
|
|
348
|
+
};
|
|
349
|
+
|
|
288
350
|
clientConstructor.addStatements([
|
|
289
|
-
|
|
351
|
+
writeStatements(getRequiredParamChecks(requiredParams), addBlankLine),
|
|
352
|
+
writeStatement(
|
|
353
|
+
writeDefaultOptions(
|
|
354
|
+
clientParams.some(p => p.name === "credentials"),
|
|
355
|
+
hasLro,
|
|
356
|
+
clientDetails
|
|
357
|
+
)
|
|
358
|
+
)
|
|
359
|
+
]);
|
|
360
|
+
|
|
361
|
+
!useCoreV2 &&
|
|
362
|
+
clientConstructor.addStatements([
|
|
363
|
+
writeStatement(getEndpointStatement(clientDetails.endpoint), addBlankLine)
|
|
364
|
+
]);
|
|
365
|
+
|
|
366
|
+
clientConstructor.addStatements([
|
|
367
|
+
requiredParameters.length ? "// Parameter assignments" : "",
|
|
368
|
+
writeStatements(getRequiredParamAssignments(requiredParams), addBlankLine),
|
|
369
|
+
constantParameters.length
|
|
370
|
+
? "// Assigning values to Constant parameters"
|
|
371
|
+
: "",
|
|
372
|
+
writeStatements(constantParameters, addBlankLine)
|
|
290
373
|
]);
|
|
291
374
|
|
|
292
375
|
const operationDeclarationDetails: OperationDeclarationDetails[] = getOperationGroupsDeclarationDetails(
|
|
@@ -362,3 +445,149 @@ function writeClientOperations(
|
|
|
362
445
|
})
|
|
363
446
|
);
|
|
364
447
|
}
|
|
448
|
+
|
|
449
|
+
function getRequiredParamChecks(requiredParameters: ParameterDetails[]) {
|
|
450
|
+
return requiredParameters.map(
|
|
451
|
+
({ name }) => `if(${name} === undefined) {
|
|
452
|
+
throw new Error("'${name}' cannot be null");
|
|
453
|
+
}`
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function getCredentialScopesValue(credentialScopes?: string | string[]) {
|
|
458
|
+
if (Array.isArray(credentialScopes)) {
|
|
459
|
+
return `[${credentialScopes.map(scope => `"${scope}"`).join()}]`;
|
|
460
|
+
} else if (typeof credentialScopes === "string") {
|
|
461
|
+
return `"${credentialScopes}"`;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
return credentialScopes;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function getTrack2DefaultContent(addScopes: string, hasCredentials: boolean) {
|
|
468
|
+
return `// Initializing default values for options
|
|
469
|
+
if (!options) {
|
|
470
|
+
options = {};
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const defaultUserAgent = \`azsdk-js-\${packageName.replace(/@.*\\//,"")}/\${packageVersion} \${coreHttp.getDefaultUserAgentValue()}\`;
|
|
474
|
+
|
|
475
|
+
${addScopes}
|
|
476
|
+
|
|
477
|
+
super(${hasCredentials ? "credentials" : `undefined`}, {
|
|
478
|
+
...options,
|
|
479
|
+
userAgent: options.userAgent
|
|
480
|
+
? \`\${options.userAgent} \${defaultUserAgent}\`
|
|
481
|
+
: \`\${defaultUserAgent}\`
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
this.requestContentType = "application/json; charset=utf-8";
|
|
485
|
+
|
|
486
|
+
`;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function getTrack1DefaultContent(
|
|
490
|
+
addScopes: string,
|
|
491
|
+
defaults: string,
|
|
492
|
+
packageDetails: PackageDetails,
|
|
493
|
+
clientDetails: ClientDetails
|
|
494
|
+
) {
|
|
495
|
+
return `// Initializing default values for options
|
|
496
|
+
if (!options) {
|
|
497
|
+
options = {};
|
|
498
|
+
}
|
|
499
|
+
${defaults}
|
|
500
|
+
|
|
501
|
+
const packageDetails = \`azsdk-js-${packageDetails.name.replace(
|
|
502
|
+
/@.*\//,
|
|
503
|
+
""
|
|
504
|
+
)}/${packageDetails.version}\`;
|
|
505
|
+
const userAgentPrefix =
|
|
506
|
+
options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
507
|
+
? \`\${options.userAgentOptions.userAgentPrefix} \${packageDetails}\`
|
|
508
|
+
: \`\${packageDetails}\`;
|
|
509
|
+
|
|
510
|
+
${addScopes}
|
|
511
|
+
const optionsWithDefaults = {
|
|
512
|
+
...defaults,
|
|
513
|
+
...options,
|
|
514
|
+
userAgentOptions: {
|
|
515
|
+
userAgentPrefix
|
|
516
|
+
},
|
|
517
|
+
baseUri: ${getEndpoint(clientDetails.endpoint)}
|
|
518
|
+
};
|
|
519
|
+
super(optionsWithDefaults);
|
|
520
|
+
`;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function writeDefaultOptions(
|
|
524
|
+
hasCredentials: boolean,
|
|
525
|
+
hasLro: boolean,
|
|
526
|
+
clientDetails: ClientDetails
|
|
527
|
+
) {
|
|
528
|
+
const { useCoreV2, credentialScopes, packageDetails } = getAutorestOptions();
|
|
529
|
+
|
|
530
|
+
const credentialScopesValues = getCredentialScopesValue(credentialScopes);
|
|
531
|
+
const addScopes = credentialScopes
|
|
532
|
+
? `if(!options.credentialScopes) {
|
|
533
|
+
options.credentialScopes = ${credentialScopesValues}
|
|
534
|
+
}`
|
|
535
|
+
: "";
|
|
536
|
+
|
|
537
|
+
const defaults = !hasCredentials
|
|
538
|
+
? `const defaults: ${clientDetails.className}OptionalParams = {
|
|
539
|
+
requestContentType: "application/json; charset=utf-8"
|
|
540
|
+
};`
|
|
541
|
+
: `const defaults: ${clientDetails.className}OptionalParams = {
|
|
542
|
+
requestContentType: "application/json; charset=utf-8",
|
|
543
|
+
credential: credentials
|
|
544
|
+
};`;
|
|
545
|
+
|
|
546
|
+
return !useCoreV2
|
|
547
|
+
? getTrack2DefaultContent(addScopes, hasCredentials)
|
|
548
|
+
: getTrack1DefaultContent(
|
|
549
|
+
addScopes,
|
|
550
|
+
defaults,
|
|
551
|
+
packageDetails,
|
|
552
|
+
clientDetails
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
function getEndpointStatement({ endpoint }: EndpointDetails) {
|
|
557
|
+
return `this.baseUri = options.endpoint ${
|
|
558
|
+
endpoint ? ` || "${endpoint}"` : ""
|
|
559
|
+
};`;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function getEndpoint({ endpoint }: EndpointDetails) {
|
|
563
|
+
return `options.endpoint ${endpoint ? ` || "${endpoint}"` : ""}`;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function getRequiredParamAssignments(requiredParameters: ParameterDetails[]) {
|
|
567
|
+
const disallowedClientParameters = ["credentials"];
|
|
568
|
+
return requiredParameters
|
|
569
|
+
.filter(({ name }) => !disallowedClientParameters.includes(name))
|
|
570
|
+
.map(({ name }) => `this.${name} = ${name};`);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function getConstantClientParamAssignments(
|
|
574
|
+
clientParameters: ParameterDetails[]
|
|
575
|
+
) {
|
|
576
|
+
return clientParameters
|
|
577
|
+
.filter(p => !!p.defaultValue || p.schemaType === SchemaType.Constant)
|
|
578
|
+
.map(
|
|
579
|
+
({ name, defaultValue }) =>
|
|
580
|
+
`this.${name} = options.${name} || ${defaultValue}`
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function writePackageInfo(
|
|
585
|
+
sourceFile: SourceFile,
|
|
586
|
+
packageDetails: PackageDetails
|
|
587
|
+
) {
|
|
588
|
+
sourceFile.addStatements([
|
|
589
|
+
`\n\n`,
|
|
590
|
+
`const packageName = "${packageDetails.name || ""}";`,
|
|
591
|
+
`const packageVersion = "${packageDetails.version || ""}";`
|
|
592
|
+
]);
|
|
593
|
+
}
|
|
@@ -12,7 +12,7 @@ export function generateIndexFile(
|
|
|
12
12
|
project: Project,
|
|
13
13
|
clientDetails?: ClientDetails
|
|
14
14
|
) {
|
|
15
|
-
const { restLevelClient, srcPath } = getAutorestOptions();
|
|
15
|
+
const { restLevelClient, srcPath, multiClient, batch } = getAutorestOptions();
|
|
16
16
|
const indexFile = project.createSourceFile(`${srcPath}/index.ts`, undefined, {
|
|
17
17
|
overwrite: true
|
|
18
18
|
});
|
|
@@ -24,30 +24,103 @@ export function generateIndexFile(
|
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
26
|
generateHLCIndex(clientDetails, indexFile);
|
|
27
|
-
} else {
|
|
27
|
+
} else if (!multiClient || !batch || batch?.length === 1) {
|
|
28
|
+
// if we are generate single client package for RLC
|
|
28
29
|
generateRLCIndex(indexFile);
|
|
30
|
+
} else {
|
|
31
|
+
generateRLCIndexForMultiClient(indexFile);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// to generate a index.ts for each single module inside the multi client RLC package
|
|
36
|
+
function generateRLCIndexForMultiClient(file: SourceFile) {
|
|
37
|
+
const { model } = getSession();
|
|
38
|
+
const clientName = model.language.default.name;
|
|
39
|
+
const createClientFuncName = `${clientName}`;
|
|
40
|
+
const moduleName = normalizeName(clientName, NameType.File);
|
|
41
|
+
|
|
42
|
+
file.addImportDeclaration({
|
|
43
|
+
namespaceImport: "Parameters",
|
|
44
|
+
moduleSpecifier: "./parameters"
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
file.addImportDeclaration({
|
|
48
|
+
namespaceImport: "Responses",
|
|
49
|
+
moduleSpecifier: "./responses"
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
file.addImportDeclaration({
|
|
53
|
+
namespaceImport: "Client",
|
|
54
|
+
moduleSpecifier: "./clientDefinitions"
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const exports = ['Parameters', 'Responses', 'Client'];
|
|
58
|
+
if (hasInputModels(model)) {
|
|
59
|
+
file.addImportDeclaration({
|
|
60
|
+
namespaceImport: "Models",
|
|
61
|
+
moduleSpecifier: "./models",
|
|
62
|
+
});
|
|
63
|
+
exports.push("Models");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (hasOutputModels(model)) {
|
|
67
|
+
file.addImportDeclaration({
|
|
68
|
+
namespaceImport: "OutputModels",
|
|
69
|
+
moduleSpecifier: "./outputModels",
|
|
70
|
+
});
|
|
71
|
+
exports.push("OutputModels");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (hasPagingOperations(model)) {
|
|
75
|
+
file.addImportDeclaration({
|
|
76
|
+
namespaceImport: "PaginateHelper",
|
|
77
|
+
moduleSpecifier: './paginateHelper',
|
|
78
|
+
});
|
|
79
|
+
exports.push("PaginateHelper");
|
|
29
80
|
}
|
|
81
|
+
|
|
82
|
+
if (hasPollingOperations(model)) {
|
|
83
|
+
file.addImportDeclaration({
|
|
84
|
+
namespaceImport: 'PollingHelper',
|
|
85
|
+
moduleSpecifier: './pollingHelper',
|
|
86
|
+
})
|
|
87
|
+
exports.push("PollingHelper");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
file.addExportDeclarations([
|
|
91
|
+
{
|
|
92
|
+
moduleSpecifier: `./${moduleName}`,
|
|
93
|
+
namedExports: [createClientFuncName],
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
namedExports: [...exports]
|
|
97
|
+
}
|
|
98
|
+
]);
|
|
30
99
|
}
|
|
31
100
|
|
|
32
101
|
function generateRLCIndex(file: SourceFile) {
|
|
33
102
|
const { model } = getSession();
|
|
34
103
|
const clientName = model.language.default.name;
|
|
104
|
+
const createClientFuncName = `${clientName}`;
|
|
35
105
|
const moduleName = normalizeName(clientName, NameType.File);
|
|
36
106
|
|
|
37
107
|
file.addImportDeclaration({
|
|
38
108
|
moduleSpecifier: `./${moduleName}`,
|
|
39
|
-
defaultImport:
|
|
109
|
+
defaultImport: createClientFuncName
|
|
40
110
|
});
|
|
41
111
|
|
|
42
112
|
file.addExportDeclarations([
|
|
43
113
|
{
|
|
44
|
-
moduleSpecifier: `./${moduleName}
|
|
114
|
+
moduleSpecifier: `./${moduleName}`,
|
|
45
115
|
},
|
|
46
116
|
{
|
|
47
117
|
moduleSpecifier: "./parameters"
|
|
48
118
|
},
|
|
49
119
|
{
|
|
50
120
|
moduleSpecifier: "./responses"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
moduleSpecifier: "./clientDefinitions"
|
|
51
124
|
}
|
|
52
125
|
]);
|
|
53
126
|
|
|
@@ -84,7 +157,7 @@ function generateRLCIndex(file: SourceFile) {
|
|
|
84
157
|
}
|
|
85
158
|
|
|
86
159
|
file.addExportAssignment({
|
|
87
|
-
expression:
|
|
160
|
+
expression: createClientFuncName,
|
|
88
161
|
isExportEquals: false
|
|
89
162
|
});
|
|
90
163
|
}
|
|
@@ -102,10 +175,6 @@ function generateHLCIndex(clientDetails: ClientDetails, file: SourceFile) {
|
|
|
102
175
|
{
|
|
103
176
|
moduleSpecifier: `./${clientDetails.sourceFileName}`,
|
|
104
177
|
namedExports: [clientDetails.className]
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
moduleSpecifier: `./${clientDetails.sourceFileName}Context`,
|
|
108
|
-
namedExports: [`${clientDetails.className}Context`]
|
|
109
178
|
}
|
|
110
179
|
]);
|
|
111
180
|
|
|
@@ -69,6 +69,10 @@ export function generateModels(clientDetails: ClientDetails, project: Project) {
|
|
|
69
69
|
namespaceImport: "coreRestPipeline",
|
|
70
70
|
moduleSpecifier: "@azure/core-rest-pipeline"
|
|
71
71
|
});
|
|
72
|
+
modelsIndexFile.addImportDeclaration({
|
|
73
|
+
namespaceImport: "coreHttpCompat",
|
|
74
|
+
moduleSpecifier: "@azure/core-http-compat"
|
|
75
|
+
});
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
writeUniontypes(clientDetails, modelsIndexFile);
|
|
@@ -77,13 +81,21 @@ export function generateModels(clientDetails: ClientDetails, project: Project) {
|
|
|
77
81
|
writeOperationModels(clientDetails, modelsIndexFile);
|
|
78
82
|
writeClientModels(clientDetails, modelsIndexFile);
|
|
79
83
|
modelsIndexFile.fixUnusedIdentifiers();
|
|
84
|
+
const allTypes = modelsIndexFile.getTypeAliases();
|
|
85
|
+
clientDetails.allTypes = allTypes
|
|
86
|
+
.filter(item => {
|
|
87
|
+
return item.isExported();
|
|
88
|
+
})
|
|
89
|
+
.map(item => {
|
|
90
|
+
return item.getName();
|
|
91
|
+
});
|
|
80
92
|
}
|
|
81
93
|
|
|
82
94
|
const writeClientModels = (
|
|
83
95
|
clientDetails: ClientDetails,
|
|
84
96
|
modelsIndexFile: SourceFile
|
|
85
97
|
) => {
|
|
86
|
-
const { useCoreV2 } = getAutorestOptions();
|
|
98
|
+
const { useCoreV2, coreHttpCompatMode } = getAutorestOptions();
|
|
87
99
|
let clientOptionalParams = clientDetails.parameters.filter(
|
|
88
100
|
p =>
|
|
89
101
|
(!p.required || p.defaultValue) &&
|
|
@@ -97,6 +109,8 @@ const writeClientModels = (
|
|
|
97
109
|
{
|
|
98
110
|
baseClass: !useCoreV2
|
|
99
111
|
? "coreHttp.ServiceClientOptions"
|
|
112
|
+
: coreHttpCompatMode
|
|
113
|
+
? "coreHttpCompat.ExtendedServiceClientOptions"
|
|
100
114
|
: "coreClient.ServiceClientOptions"
|
|
101
115
|
}
|
|
102
116
|
);
|
|
@@ -771,6 +785,12 @@ function getPropertyTypeName(
|
|
|
771
785
|
ignoreNullableOnOptional: boolean
|
|
772
786
|
) {
|
|
773
787
|
if (property.isConstant) {
|
|
788
|
+
if (
|
|
789
|
+
property.type === SchemaType.Number ||
|
|
790
|
+
property.type === SchemaType.Boolean
|
|
791
|
+
) {
|
|
792
|
+
return `${property.defaultValue}`;
|
|
793
|
+
}
|
|
774
794
|
return `"${getStringForValue(
|
|
775
795
|
property.defaultValue,
|
|
776
796
|
property.type,
|
|
@@ -475,7 +475,7 @@ function addClass(
|
|
|
475
475
|
name: "client",
|
|
476
476
|
isReadonly: true,
|
|
477
477
|
scope: Scope.Private,
|
|
478
|
-
type: `${clientDetails.className}
|
|
478
|
+
type: `${clientDetails.className}`
|
|
479
479
|
});
|
|
480
480
|
const constructorDefinition = operationGroupClass.addConstructor({
|
|
481
481
|
docs: [
|
|
@@ -487,7 +487,7 @@ function addClass(
|
|
|
487
487
|
{
|
|
488
488
|
name: "client",
|
|
489
489
|
hasQuestionToken: false,
|
|
490
|
-
type: `${clientDetails.className}
|
|
490
|
+
type: `${clientDetails.className}`
|
|
491
491
|
}
|
|
492
492
|
]
|
|
493
493
|
});
|
|
@@ -1319,16 +1319,16 @@ function addImports(
|
|
|
1319
1319
|
});
|
|
1320
1320
|
}
|
|
1321
1321
|
|
|
1322
|
-
const
|
|
1322
|
+
const clientClassName = `${className}`;
|
|
1323
1323
|
|
|
1324
|
-
const
|
|
1325
|
-
|
|
1324
|
+
const clientFileName = normalizeName(
|
|
1325
|
+
clientClassName,
|
|
1326
1326
|
NameType.File
|
|
1327
1327
|
);
|
|
1328
1328
|
|
|
1329
1329
|
operationGroupFile.addImportDeclaration({
|
|
1330
|
-
namedImports: [`${
|
|
1331
|
-
moduleSpecifier: `../${
|
|
1330
|
+
namedImports: [`${clientClassName}`],
|
|
1331
|
+
moduleSpecifier: `../${clientFileName}`
|
|
1332
1332
|
});
|
|
1333
1333
|
|
|
1334
1334
|
if (hasLroOperation(operationGroupDetails)) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as hbs from 'handlebars';
|
|
4
|
+
import { Project } from 'ts-morph';
|
|
5
|
+
|
|
6
|
+
export function generateSampleEnv(project: Project) {
|
|
7
|
+
const file = fs.readFileSync(path.join(__dirname, "sampleEnv.hbs"), {
|
|
8
|
+
encoding: "utf-8"
|
|
9
|
+
});
|
|
10
|
+
const readmeFileContents = hbs.compile(file, { noEscape: true });
|
|
11
|
+
project.createSourceFile("sample.env", readmeFileContents({}), {
|
|
12
|
+
overwrite: true
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Project,
|
|
6
|
+
SourceFile
|
|
7
|
+
} from "ts-morph";
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import * as hbs from "handlebars";
|
|
11
|
+
import { getAutorestOptions, getSession } from "../../autorestSession";
|
|
12
|
+
import { ClientDetails } from "../../models/clientDetails";
|
|
13
|
+
import { SampleGroup } from "../../models/sampleDetails";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Function that writes the code for all the operations.
|
|
17
|
+
* It will generate one file per operation group and each file contains:
|
|
18
|
+
* - A class definition for the operation group
|
|
19
|
+
* - Methods and overrides for each operation
|
|
20
|
+
* - OperationSpecs for each operation
|
|
21
|
+
* @param clientDetails client details
|
|
22
|
+
* @param project project for code generation
|
|
23
|
+
*/
|
|
24
|
+
export function generateSamples(
|
|
25
|
+
clientDetails: ClientDetails,
|
|
26
|
+
project: Project
|
|
27
|
+
): void {
|
|
28
|
+
// Toplevel operations are inlined in the client
|
|
29
|
+
const sampleGroups = clientDetails.samples;
|
|
30
|
+
const session = getSession();
|
|
31
|
+
if (!sampleGroups) {
|
|
32
|
+
session.error("No samples are found! ", []);
|
|
33
|
+
}
|
|
34
|
+
for (const sampleGroup of sampleGroups as SampleGroup[]) {
|
|
35
|
+
try {
|
|
36
|
+
const file = fs.readFileSync(path.join(__dirname, "../static/samples.ts.hbs"), {
|
|
37
|
+
encoding: "utf-8"
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const sampleGroupFileContents = hbs.compile(file, { noEscape: true });
|
|
41
|
+
project.createSourceFile(`samples-dev/${sampleGroup.sampleFileName}.ts`, sampleGroupFileContents(sampleGroup), {
|
|
42
|
+
overwrite: true
|
|
43
|
+
});
|
|
44
|
+
} catch (error) {
|
|
45
|
+
session.error("An error was encountered while handling sample generation", [sampleGroup.sampleFileName]);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|