Skip to content

Commit

Permalink
make function async
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome committed Nov 18, 2024
1 parent 920c55a commit fc0c01b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class GenerateClientCommand extends Command {
if (!deepLinkParams.name && this._openApiTreeProvider.apiTitle) {
deepLinkParams.name = getSanitizedString(this._openApiTreeProvider.apiTitle);
}
availableStateInfo = transformToGenerationConfig(deepLinkParams);
availableStateInfo = await transformToGenerationConfig(deepLinkParams);
} else {
const pluginName = getSanitizedString(this._openApiTreeProvider.apiTitle);
availableStateInfo = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ suite('GenerateClientCommand Test Suite', () => {
assert.strictEqual(!treeProvider.descriptionUrl, false);
vscodeWindowSpy.verify();
sinon.assert.calledOnceWithMatch(getlanguageInfoFn, context);
let stateInfo = transformToGenerationConfig(pluginParams);
let stateInfo = await transformToGenerationConfig(pluginParams);
sinon.assert.calledOnceWithMatch(generateStepsFn, stateInfo, undefined , pluginParams);
sinon.assert.calledOnce(showUpgradeWarningMessageStub);
sinon.assert.calledOnceWithMatch(getExtensionSettingsStub, "kiota");
Expand Down
16 changes: 8 additions & 8 deletions vscode/microsoft-kiota/src/utilities/deep-linking.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs';
import * as path from 'path';
import { promises as fs } from 'fs';

import { GenerateState } from "../modules/steps/generateSteps";
import { KiotaGenerationLanguage, KiotaPluginType } from "../types/enums";
Expand All @@ -11,8 +11,8 @@ export function isDeeplinkEnabled(deepLinkParams: Partial<IntegrationParams>): b
return Object.values(deepLinkParams).filter(property => property).length >= minimumNumberOfParams;
}

export function transformToGenerationConfig(deepLinkParams: Partial<IntegrationParams>)
: Partial<GenerateState> {
export async function transformToGenerationConfig(deepLinkParams: Partial<IntegrationParams>)
: Promise<Partial<GenerateState>> {
const generationConfig: Partial<GenerateState> = {};
if (deepLinkParams.kind === "client") {
generationConfig.generationType = "client";
Expand All @@ -37,7 +37,7 @@ export function transformToGenerationConfig(deepLinkParams: Partial<IntegrationP
}
generationConfig.outputPath =
(deepLinkParams.source && deepLinkParams.source?.toLowerCase() === 'ttk')
? determineOutputPath(deepLinkParams)
? await determineOutputPath(deepLinkParams)
: undefined;
}
return generationConfig;
Expand Down Expand Up @@ -113,7 +113,6 @@ export function validateDeepLinkQueryParams(queryParameters: Partial<Integration
projectPath = undefined;
errormsg.push(`A relative paths is not supported for the projectPath parameter`);
}

validQueryParams = {
descriptionurl,
name,
Expand All @@ -127,12 +126,13 @@ export function validateDeepLinkQueryParams(queryParameters: Partial<Integration
return [validQueryParams, errormsg];
}

function determineOutputPath(deepLinkParams: Partial<IntegrationParams>): string | undefined {
async function determineOutputPath(deepLinkParams: Partial<IntegrationParams>): Promise<string | undefined> {
if (deepLinkParams.projectPath) {
try {
if (!fs.existsSync(deepLinkParams.projectPath)) {
const exists = await fs.access(deepLinkParams.projectPath).then(() => true).catch(() => false);
if (!exists) {
try {
fs.mkdirSync(deepLinkParams.projectPath);
await fs.mkdir(deepLinkParams.projectPath);
} catch (err: unknown) {
throw new Error(`Error creating directory: ${(err as Error).message}`);
}
Expand Down

0 comments on commit fc0c01b

Please sign in to comment.