Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task: support .kiota folder in ttk integration #5612

Merged
merged 9 commits into from
Nov 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ export class GenerateClientCommand extends Command {
private _openApiTreeProvider: OpenApiTreeProvider;
private _context: vscode.ExtensionContext;
private _dependenciesViewProvider: DependenciesViewProvider;
private _setWorkspaceGenerationContext: (params: Partial<WorkspaceGenerationContext>) => void;
private _setWorkspaceGenerationContext: (params: Partial<WorkspaceGenerationContext>) => void;

constructor(
openApiTreeProvider: OpenApiTreeProvider,
context: vscode.ExtensionContext,
dependenciesViewProvider: DependenciesViewProvider,
setWorkspaceGenerationContext: (params: Partial<WorkspaceGenerationContext>) => void
setWorkspaceGenerationContext: (params: Partial<WorkspaceGenerationContext>) => void
) {
super();
this._openApiTreeProvider = openApiTreeProvider;
this._context = context;
this._dependenciesViewProvider = dependenciesViewProvider;
this._setWorkspaceGenerationContext = setWorkspaceGenerationContext;
this._setWorkspaceGenerationContext = setWorkspaceGenerationContext;
}

public getName(): string {
Expand Down Expand Up @@ -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") {
thewahome marked this conversation as resolved.
Show resolved Hide resolved
if (deepLinkParams.source?.toLowerCase() === 'ttk') {
outputPath = path.join(config.outputPath, "appPackage");
} else {
outputPath = config.outputPath;
}
}

let manifestKey = null;
switch (config.generationType) {
case "client":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import TelemetryReporter from "@vscode/extension-telemetry";
import * as path from "path";
import * as vscode from "vscode";
import { ExtensionContext } from "vscode";

Expand Down Expand Up @@ -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<boolean> {
const filesAndFolders = await vscode.workspace.fs.readDirectory(vscode.Uri.file(workspaceParentDirectory));
return !!filesAndFolders.find(([name, type]) => type === vscode.FileType.File && name === 'teamsapp.yml');
}
}
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

}
Loading