Skip to content

Commit 3bbbb38

Browse files
Accounting for internal types autorest generation (#286)
1 parent 738844a commit 3bbbb38

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

src/generator/src/cmd/generate.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ executeSynchronous(async () => {
4646
const waitForDebugger = args['wait-for-debugger'];
4747
const singlePath = args['single-path'];
4848

49+
// Detect internal generation by checking if output directory contains 'internal'
50+
const isInternalGeneration = outputBaseDir.includes('internal');
51+
52+
// For internal generation, use 1.1.0-preview-internal version consistently
53+
const effectiveExtensionConfig = isInternalGeneration ? {
54+
"beta": {
55+
"name": extensionConfig["beta"].name,
56+
"version": "1.0.0",
57+
},
58+
"v1.0": {
59+
"name": extensionConfig["v1.0"].name,
60+
"version": "1.0.0",
61+
}
62+
} : extensionConfigForGeneration;
63+
4964
if (!existsSync(`${extensionDir}/dist`)) {
5065
throw `Unable to find ${extensionDir}/dist. Did you forget to run 'npm run build'?`;
5166
}
@@ -83,11 +98,11 @@ executeSynchronous(async () => {
8398

8499
for (const apiVersion of [ApiVersion.Beta, ApiVersion.V1_0]) {
85100
const tmpOutputApiVersionDir = path.join(tmpOutputDir, 'microsoft.graph', apiVersion);
86-
const outputApiVersionDir = path.join(outputBaseDir, apiVersion, extensionConfigForGeneration[apiVersion].version);
101+
const outputApiVersionDir = path.join(outputBaseDir, apiVersion, effectiveExtensionConfig[apiVersion].version);
87102

88103
try {
89104
// autorest readme.bicep.md files are not checked in, so we must generate them before invoking autorest
90-
await generateAutorestConfig(logger, readmePath, bicepReadmePath, apiVersion, extensionConfigForGeneration[apiVersion].version);
105+
await generateAutorestConfig(logger, readmePath, bicepReadmePath, apiVersion, effectiveExtensionConfig[apiVersion].version);
91106
await generateSchema(logger, bicepReadmePath, tmpOutputDir, logLevel, waitForDebugger);
92107

93108
// remove all previously-generated files and copy over results
@@ -118,8 +133,8 @@ ${err}
118133
}
119134

120135
// build the type index
121-
await buildTypeIndex(defaultLogger, outputBaseDir, ApiVersion.Beta);
122-
await buildTypeIndex(defaultLogger, outputBaseDir, ApiVersion.V1_0);
136+
await buildTypeIndex(defaultLogger, outputBaseDir, ApiVersion.Beta, effectiveExtensionConfig);
137+
await buildTypeIndex(defaultLogger, outputBaseDir, ApiVersion.V1_0, effectiveExtensionConfig);
123138
});
124139

125140
function normalizeJsonPath(jsonPath: string) {
@@ -259,7 +274,7 @@ async function findReadmePaths(specsPath: string) {
259274
});
260275
}
261276

262-
async function buildTypeIndex(logger: ILogger, baseDir: string, apiVersion: ApiVersion) {
277+
async function buildTypeIndex(logger: ILogger, baseDir: string, apiVersion: ApiVersion, extensionConfig: any) {
263278
// Add the MsGraphBicepExtensionConfig type to the last position in types.json file
264279
function isEnhancedRelationshipVersion(apiVersion: string, extensionVersion: string): boolean {
265280
return (apiVersion === 'beta' && extensionVersion === '1.1.0-preview') ||
@@ -335,9 +350,9 @@ async function buildTypeIndex(logger: ILogger, baseDir: string, apiVersion: ApiV
335350
return contentTypes;
336351
};
337352

338-
const extensionBaseDir = path.join(baseDir, apiVersion, extensionConfigForGeneration[apiVersion].version);
353+
const extensionBaseDir = path.join(baseDir, apiVersion, extensionConfig[apiVersion].version);
339354
const typesPaths = await findRecursive(extensionBaseDir, filePath => {
340-
return shouldIncludeFilePath(filePath) && path.basename(filePath) === 'types.json';
355+
return shouldIncludeFilePath(filePath, extensionConfig) && path.basename(filePath) === 'types.json';
341356
});
342357

343358
if (typesPaths.length === 0) {
@@ -346,15 +361,15 @@ async function buildTypeIndex(logger: ILogger, baseDir: string, apiVersion: ApiV
346361
}
347362

348363
const content = await readFile(typesPaths[0], { encoding: 'utf8' });
349-
const contentJson = addConfigToContent(content, apiVersion, extensionConfigForGeneration[apiVersion].version);
364+
const contentJson = addConfigToContent(content, apiVersion, extensionConfig[apiVersion].version);
350365
const typeFiles: TypeFile[] = [{
351366
relativePath: path.relative(extensionBaseDir, typesPaths[0]),
352367
types: readTypesJson(JSON.stringify(contentJson)),
353368
}];
354369

355370
const typeSettings: TypeSettings = {
356-
name: extensionConfigForGeneration[apiVersion].name,
357-
version: extensionConfigForGeneration[apiVersion].version,
371+
name: extensionConfig[apiVersion].name,
372+
version: extensionConfig[apiVersion].version,
358373
isSingleton: false,
359374
configurationType: new CrossFileTypeReference('types.json', contentJson.length - 1),
360375
};
@@ -365,9 +380,9 @@ async function buildTypeIndex(logger: ILogger, baseDir: string, apiVersion: ApiV
365380
await writeFile(`${extensionBaseDir}/index.md`, writeIndexMarkdown(indexContent));
366381
}
367382

368-
function shouldIncludeFilePath(filePath: string) {
369-
return filePath.includes(path.join(ApiVersion.Beta, extensionConfigForGeneration[ApiVersion.Beta].version)) ||
370-
filePath.includes(path.join(ApiVersion.V1_0, extensionConfigForGeneration[ApiVersion.V1_0].version));
383+
function shouldIncludeFilePath(filePath: string, extensionConfig: any) {
384+
return filePath.includes(path.join(ApiVersion.Beta, extensionConfig[ApiVersion.Beta].version)) ||
385+
filePath.includes(path.join(ApiVersion.V1_0, extensionConfig[ApiVersion.V1_0].version));
371386
}
372387

373388
function isVerboseLoggingLevel(logLevel: string) {

0 commit comments

Comments
 (0)