diff --git a/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts b/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts index e38770f94e..99b896ede6 100644 --- a/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts +++ b/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts @@ -27,19 +27,19 @@ export class GenerateClientCommand extends Command { private _openApiTreeProvider: OpenApiTreeProvider; private _context: vscode.ExtensionContext; private _dependenciesViewProvider: DependenciesViewProvider; - private _setWorkspaceGenerationContext: (params: Partial) => void; + private _setWorkspaceGenerationContext: (params: Partial) => void; constructor( openApiTreeProvider: OpenApiTreeProvider, context: vscode.ExtensionContext, dependenciesViewProvider: DependenciesViewProvider, - setWorkspaceGenerationContext: (params: Partial) => void + setWorkspaceGenerationContext: (params: Partial) => void ) { super(); this._openApiTreeProvider = openApiTreeProvider; this._context = context; this._dependenciesViewProvider = dependenciesViewProvider; - this._setWorkspaceGenerationContext = setWorkspaceGenerationContext; + this._setWorkspaceGenerationContext = setWorkspaceGenerationContext; } public getName(): string { @@ -80,9 +80,16 @@ export class GenerateClientCommand extends Command { ); setGenerationConfiguration(config); const generationType = parseGenerationType(config.generationType); - const outputPath = typeof config.outputPath === "string" - ? config.outputPath - : "./output"; + + let outputPath = "./output"; + if (typeof config.outputPath === "string") { + if (deepLinkParams.source?.toLowerCase() === 'ttk') { + outputPath = path.join(config.outputPath, "appPackage"); + } else { + outputPath = config.outputPath; + } + } + let manifestKey = null; switch (config.generationType) { case "client": diff --git a/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts b/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts index 36ebefece1..139425d8ff 100644 --- a/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts +++ b/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts @@ -1,4 +1,5 @@ import TelemetryReporter from "@vscode/extension-telemetry"; +import * as path from "path"; import * as vscode from "vscode"; import { ExtensionContext } from "vscode"; @@ -114,4 +115,32 @@ export class RegenerateService { }); this._openApiTreeProvider.resetInitialState(); } + + async regenerateTeamsApp(workspaceJson: vscode.TextDocument, clientOrPluginKey: string) { + const workspaceDirectory = path.dirname(workspaceJson.fileName); + const workspaceParentDirectory = path.dirname(workspaceDirectory); + const shouldMakeTTKFunctionCall = await this.followsTTKFolderStructure(workspaceParentDirectory); + + if (shouldMakeTTKFunctionCall) { + const workspaceJsonContent = workspaceJson.getText(); + const workspaceJsonData = JSON.parse(workspaceJsonContent); + + const outputPath = workspaceJsonData.plugins[clientOrPluginKey].outputPath; + const pathOfSpec = path.join(workspaceParentDirectory, outputPath, `${clientOrPluginKey.toLowerCase()}-openapi.yml`); + const pathPluginManifest = path.join(workspaceParentDirectory, outputPath, `${clientOrPluginKey.toLowerCase()}-apiplugin.json`); + + await vscode.commands.executeCommand( + 'fx-extension.kiotaregenerate', + [ + pathOfSpec, + pathPluginManifest + ] + ); + } + } + + private async followsTTKFolderStructure(workspaceParentDirectory: string): Promise { + const filesAndFolders = await vscode.workspace.fs.readDirectory(vscode.Uri.file(workspaceParentDirectory)); + return !!filesAndFolders.find(([name, type]) => type === vscode.FileType.File && name === 'teamsapp.yml'); + } } \ No newline at end of file diff --git a/vscode/microsoft-kiota/src/commands/regenerate/regenerateButtonCommand.ts b/vscode/microsoft-kiota/src/commands/regenerate/regenerateButtonCommand.ts index 25ad81022b..2830a072eb 100644 --- a/vscode/microsoft-kiota/src/commands/regenerate/regenerateButtonCommand.ts +++ b/vscode/microsoft-kiota/src/commands/regenerate/regenerateButtonCommand.ts @@ -1,7 +1,7 @@ import * as vscode from "vscode"; import { ExtensionContext } from "vscode"; -import { extensionId, treeViewId } from "../../constants"; +import { extensionId, KIOTA_WORKSPACE_FILE, treeViewId } from "../../constants"; import { getGenerationConfiguration, setGenerationConfiguration } from "../../handlers/configurationHandler"; import { OpenApiTreeProvider } from "../../providers/openApiTreeProvider"; import { getExtensionSettings } from "../../types/extensionSettings"; @@ -57,6 +57,11 @@ export class RegenerateButtonCommand extends Command { if (isClientType(generationType)) { await regenerateService.regenerateClient(settings, selectedPaths); + + const workspaceJson = vscode.workspace.textDocuments.find(doc => doc.fileName.endsWith(KIOTA_WORKSPACE_FILE)); + if (workspaceJson && !workspaceJson.isDirty) { + await regenerateService.regenerateTeamsApp(workspaceJson, clientOrPluginKey); + } } if (isPluginType(generationType)) { await regenerateService.regeneratePlugin(settings, selectedPaths); diff --git a/vscode/microsoft-kiota/src/commands/regenerate/regenerateCommand.ts b/vscode/microsoft-kiota/src/commands/regenerate/regenerateCommand.ts index a2688351d0..c28e1824d1 100644 --- a/vscode/microsoft-kiota/src/commands/regenerate/regenerateCommand.ts +++ b/vscode/microsoft-kiota/src/commands/regenerate/regenerateCommand.ts @@ -43,10 +43,12 @@ export class RegenerateCommand extends Command { const regenerateService = new RegenerateService(this._context, this._openApiTreeProvider, clientOrPluginKey, clientOrPluginObject); if (isClientType(generationType)) { await regenerateService.regenerateClient(settings); + if (workspaceJson) { + await regenerateService.regenerateTeamsApp(workspaceJson, clientOrPluginKey); + } } if (isPluginType(generationType)) { await regenerateService.regeneratePlugin(settings); } } - } \ No newline at end of file